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

151 lines
4.5 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 java.util.Map;
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;
import net.minecraft.world.WorldServer;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.util.LRUHashMap;
public class ScriptBlock implements IBlock {
private static final Map<String, IBlock> blockCache = new LRUHashMap(400);
protected final IWorld world;
protected final Block block;
protected final BlockPos pos;
2022-09-07 23:06:57 -05:00
protected final 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()));
}
public IPos getPos() {
return this.bPos;
}
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
}
}