Files
CustomNPC-Plus/src/main/java/noppes/npcs/scripted/ScriptBlock.java
T

229 lines
6.6 KiB
Java
Raw Normal View History

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package noppes.npcs.scripted;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
2022-07-07 21:17:44 -05:00
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2022-11-15 15:25:53 -05:00
import noppes.npcs.api.*;
import noppes.npcs.util.LRUHashMap;
2023-01-12 21:33:06 -05:00
import java.util.Map;
public class ScriptBlock implements IBlock {
private static final Map<String, IBlock> blockCache = new LRUHashMap(400);
2022-11-06 15:08:58 -06:00
protected IWorld world;
protected Block block;
protected BlockPos pos;
protected IPos bPos;
2022-09-07 23:06:15 -05:00
protected ITileEntity tile;
public ScriptBlock(World world, Block block, BlockPos pos) {
2022-09-07 23:06:15 -05:00
this.world = NpcAPI.Instance().getIWorld(world);
this.block = block;
this.pos = pos;
this.bPos = NpcAPI.Instance().getIPos(pos);
this.tile = NpcAPI.Instance().getITileEntity(world.getTileEntity(pos.getX(),pos.getY(), pos.getZ()));
}
2022-11-06 15:08:58 -06:00
public IPos getPosition() {
return this.bPos;
}
public IPos getPos() {
return this.bPos;
}
2022-11-06 15:08:58 -06:00
public boolean setPosition(IPos pos, IWorld world) {
if (pos == null || world == null || !world.setBlock(pos, this))
return false;
this.world.removeBlock(this.getPos());
this.world = world;
this.block = world.getBlock(pos).getMCBlock();
this.pos = pos.getMCPos();
this.bPos = pos;
this.tile = NpcAPI.Instance().getITileEntity(world.getMCWorld().getTileEntity(pos.getX(),pos.getY(),pos.getZ()));
return true;
}
public boolean setPosition(IPos pos) {
return this.setPosition(pos,world);
}
public boolean setPos(IPos pos, IWorld world) {
return this.setPosition(pos,world);
}
public boolean setPos(IPos pos) {
return this.setPosition(pos);
}
public boolean setPosition(int x, int y, int z, IWorld world) {
return this.setPos(NpcAPI.Instance().getIPos(x,y,z),world);
}
public boolean setPosition(int x, int y, int z) {
return this.setPos(NpcAPI.Instance().getIPos(x,y,z));
}
public boolean setPos(int x, int y, int z, IWorld world) {
return this.setPosition(x,y,z, world);
}
public boolean setPos(int x, int y, int z) {
return this.setPosition(x,y,z);
}
public int getX() {
return this.pos.getX();
}
public int getY() {
return this.pos.getY();
}
public int getZ() {
return this.pos.getZ();
}
public void remove() {
this.world.getMCWorld().setBlockToAir(getX(), getY(), getZ());
}
public boolean isAir() {
return this.block.isAir(this.world.getMCWorld(), getX(), getY(), getZ());
}
public IBlock setBlock(String blockName) {
Block block = (Block)Block.blockRegistry.getObject(new ResourceLocation(blockName));
if(block == null) {
return this;
} else {
this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block);
return NpcAPI.Instance().getIBlock(world, getX(),getY(),getZ());
}
}
public IBlock setBlock(IBlock block) {
this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block.getMCBlock());
return NpcAPI.Instance().getIBlock(world, getX(),getY(),getZ());
}
public boolean isContainer() {
2022-09-07 23:06:15 -05:00
return this.tile != null && this.tile.getMCTileEntity() != null && this.tile.getMCTileEntity() instanceof IInventory && ((IInventory) this.tile.getMCTileEntity()).getSizeInventory() > 0;
}
public IContainer getContainer() {
if(!this.isContainer()) {
throw new CustomNPCsException("This block is not a container", new Object[0]);
} else {
2022-09-07 23:06:15 -05:00
return NpcAPI.Instance().getIContainer((IInventory)this.tile.getMCTileEntity());
}
}
public String getName() {
return Block.blockRegistry.getNameForObject(this.block) + "";
}
public String getDisplayName() {
2022-09-07 23:06:15 -05:00
return this.tile == null || this.tile.getMCTileEntity() == null ? this.getName():this.tile.getMCTileEntity().blockType.getItemIconName();
}
public IWorld getWorld() {
return this.world;
}
public Block getMCBlock() {
return this.block;
}
public static void clearCache() {
blockCache.clear();
}
public boolean hasTileEntity() {
return this.tile != null;
}
public ITileEntity getTileEntity() {
2022-09-07 23:06:15 -05:00
return this.tile;
2022-05-03 23:09:21 -05:00
}
public void setTileEntity(ITileEntity tileEntity){
2022-05-03 23:09:21 -05:00
world.setTileEntity(pos.getX(),pos.getY(), pos.getZ(),tileEntity);
2022-09-07 23:06:15 -05:00
this.tile = tileEntity;
2022-05-03 23:09:21 -05:00
}
public TileEntity getMCTileEntity() {
2022-11-06 01:36:01 -06:00
if (this.tile == null)
return null;
2022-09-07 23:06:15 -05:00
return this.tile.getMCTileEntity();
}
public INbt getTileEntityNBT() {
2022-11-06 01:36:01 -06:00
if (this.tile == null || this.tile.getMCTileEntity() == null)
return null;
NBTTagCompound compound = new NBTTagCompound();
2022-09-07 23:06:15 -05:00
this.tile.getMCTileEntity().writeToNBT(compound);
return NpcAPI.Instance().getINbt(compound);
}
2022-07-07 20:49:03 -05:00
2022-07-07 21:17:44 -05:00
public boolean canCollide(double maxVolume) {
AxisAlignedBB alignedBB = block.getCollisionBoundingBoxFromPool(world.getMCWorld(),getX(),getY(),getZ());
if (alignedBB == null) {
return false;
}
double xEdge = alignedBB.maxX - alignedBB.minX;
double yEdge = alignedBB.maxY - alignedBB.minY;
double zEdge = alignedBB.maxZ - alignedBB.minZ;
return Math.abs(xEdge * yEdge * zEdge) > maxVolume;
}
2022-07-07 20:49:03 -05:00
2022-07-07 21:17:44 -05:00
public boolean canCollide() {
return canCollide(0);
2022-07-07 20:49:03 -05:00
}
2022-11-06 15:08:58 -06:00
2022-11-11 00:42:56 -06:00
public void setBounds(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
this.block.setBlockBounds(minX,minY,minZ,maxX,maxY,maxZ);
}
public double getBlockBoundsMinX() {
return this.block.getBlockBoundsMinX();
}
public double getBlockBoundsMinY() {
return this.block.getBlockBoundsMinY();
}
public double getBlockBoundsMinZ() {
return this.block.getBlockBoundsMinZ();
}
public double getBlockBoundsMaxX() {
return this.block.getBlockBoundsMaxX();
}
public double getBlockBoundsMaxY() {
return this.block.getBlockBoundsMaxY();
}
public double getBlockBoundsMaxZ() {
return this.block.getBlockBoundsMaxZ();
}
2022-11-06 15:08:58 -06:00
public String toString() {
return this.getName() + " @" + this.getPos() + (world == null ? "" : " in DIM" + world.getDimensionID());
}
}