| |
| package net.minecraft.tileentity; |
| |
| import com.google.common.collect.Maps; |
| import java.util.Map; |
| import java.util.concurrent.Callable; |
| import net.minecraft.block.Block; |
| import net.minecraft.block.BlockJukebox; |
| import net.minecraft.block.state.IBlockState; |
| import net.minecraft.crash.CrashReportCategory; |
| import net.minecraft.init.Blocks; |
| import net.minecraft.nbt.NBTTagCompound; |
| import net.minecraft.network.Packet; |
| import net.minecraft.util.BlockPos; |
| import net.minecraft.world.World; |
| import net.minecraftforge.fml.relauncher.Side; |
| import net.minecraftforge.fml.relauncher.SideOnly; |
| import org.apache.logging.log4j.LogManager; |
| import org.apache.logging.log4j.Logger; |
| |
| public abstract class TileEntity |
| { |
| private static final Logger logger = LogManager.getLogger(); |
| |
| private static Map nameToClassMap = Maps.newHashMap(); |
| |
| private static Map classToNameMap = Maps.newHashMap(); |
| |
| protected World worldObj; |
| protected BlockPos pos; |
| protected boolean tileEntityInvalid; |
| private int blockMetadata; |
| |
| protected Block blockType; |
| private static final String __OBFID = "CL_00000340"; |
| |
| public TileEntity() |
| { |
| this.pos = BlockPos.ORIGIN; |
| this.blockMetadata = -1; |
| } |
| |
| |
| |
| |
| public static void addMapping(Class cl, String id) |
| { |
| if (nameToClassMap.containsKey(id)) |
| { |
| throw new IllegalArgumentException("Duplicate id: " + id); |
| } |
| else |
| { |
| nameToClassMap.put(id, cl); |
| classToNameMap.put(cl, id); |
| } |
| } |
| |
| |
| |
| |
| public World getWorld() |
| { |
| return this.worldObj; |
| } |
| |
| |
| |
| |
| public void setWorldObj(World worldIn) |
| { |
| this.worldObj = worldIn; |
| } |
| |
| |
| |
| |
| public boolean hasWorldObj() |
| { |
| return this.worldObj != null; |
| } |
| |
| public void readFromNBT(NBTTagCompound compound) |
| { |
| this.pos = new BlockPos(compound.getInteger("x"), compound.getInteger("y"), compound.getInteger("z")); |
| } |
| |
| public void writeToNBT(NBTTagCompound compound) |
| { |
| String s = (String)classToNameMap.get(this.getClass()); |
| |
| if (s == null) |
| { |
| throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!"); |
| } |
| else |
| { |
| compound.setString("id", s); |
| compound.setInteger("x", this.pos.getX()); |
| compound.setInteger("y", this.pos.getY()); |
| compound.setInteger("z", this.pos.getZ()); |
| } |
| } |
| |
| |
| |
| |
| public static TileEntity createAndLoadEntity(NBTTagCompound nbt) |
| { |
| TileEntity tileentity = null; |
| |
| Class oclass = null; |
| try |
| { |
| oclass = (Class)nameToClassMap.get(nbt.getString("id")); |
| |
| if (oclass != null) |
| { |
| tileentity = (TileEntity)oclass.newInstance(); |
| } |
| } |
| catch (Exception exception) |
| { |
| exception.printStackTrace(); |
| } |
| |
| if (tileentity != null) |
| { |
| tileentity.readFromNBT(nbt); |
| } |
| else |
| { |
| try |
| { |
| logger.warn("Skipping BlockEntity with id " + nbt.getString("id")); |
| } |
| catch (Exception ex) |
| { |
| net.minecraftforge.fml.common.FMLLog.log(org.apache.logging.log4j.Level.ERROR, ex, |
| "A TileEntity %s(%s) has thrown an exception during loading, its state cannot be restored. Report this to the mod author", |
| nbt.getString("id"), oclass.getName()); |
| tileentity = null; |
| } |
| } |
| |
| return tileentity; |
| } |
| |
| public int getBlockMetadata() |
| { |
| if (this.blockMetadata == -1) |
| { |
| IBlockState iblockstate = this.worldObj.getBlockState(this.pos); |
| this.blockMetadata = iblockstate.getBlock().getMetaFromState(iblockstate); |
| } |
| |
| return this.blockMetadata; |
| } |
| |
| |
| |
| |
| |
| public void markDirty() |
| { |
| if (this.worldObj != null) |
| { |
| IBlockState iblockstate = this.worldObj.getBlockState(this.pos); |
| this.blockMetadata = iblockstate.getBlock().getMetaFromState(iblockstate); |
| this.worldObj.markChunkDirty(this.pos, this); |
| |
| if (this.getBlockType() != Blocks.air) |
| { |
| this.worldObj.updateComparatorOutputLevel(this.pos, this.getBlockType()); |
| } |
| } |
| } |
| |
| |
| |
| |
| public double getDistanceSq(double x, double y, double z) |
| { |
| double d3 = (double)this.pos.getX() + 0.5D - x; |
| double d4 = (double)this.pos.getY() + 0.5D - y; |
| double d5 = (double)this.pos.getZ() + 0.5D - z; |
| return d3 * d3 + d4 * d4 + d5 * d5; |
| } |
| |
| @SideOnly(Side.CLIENT) |
| public double getMaxRenderDistanceSquared() |
| { |
| return 4096.0D; |
| } |
| |
| public BlockPos getPos() |
| { |
| return this.pos; |
| } |
| |
| |
| |
| |
| public Block getBlockType() |
| { |
| if (this.blockType == null) |
| { |
| this.blockType = this.worldObj.getBlockState(this.pos).getBlock(); |
| } |
| |
| return this.blockType; |
| } |
| |
| |
| |
| |
| |
| public Packet getDescriptionPacket() |
| { |
| return null; |
| } |
| |
| public boolean isInvalid() |
| { |
| return this.tileEntityInvalid; |
| } |
| |
| |
| |
| |
| public void invalidate() |
| { |
| this.tileEntityInvalid = true; |
| } |
| |
| |
| |
| |
| public void validate() |
| { |
| this.tileEntityInvalid = false; |
| } |
| |
| public boolean receiveClientEvent(int id, int type) |
| { |
| return false; |
| } |
| |
| public void updateContainingBlockInfo() |
| { |
| this.blockType = null; |
| this.blockMetadata = -1; |
| } |
| |
| public void addInfoToCrashReport(CrashReportCategory reportCategory) |
| { |
| reportCategory.addCrashSectionCallable("Name", new Callable() |
| { |
| private static final String __OBFID = "CL_00000341"; |
| public String call() |
| { |
| return (String)TileEntity.classToNameMap.get(TileEntity.this.getClass()) + " // " + TileEntity.this.getClass().getCanonicalName(); |
| } |
| }); |
| |
| if (this.worldObj != null) |
| { |
| CrashReportCategory.addBlockInfo(reportCategory, this.pos, this.getBlockType(), this.getBlockMetadata()); |
| reportCategory.addCrashSectionCallable("Actual block type", new Callable() |
| { |
| private static final String __OBFID = "CL_00000343"; |
| public String call() |
| { |
| int i = Block.getIdFromBlock(TileEntity.this.worldObj.getBlockState(TileEntity.this.pos).getBlock()); |
| |
| try |
| { |
| return String.format("ID #%d (%s // %s)", new Object[] {Integer.valueOf(i), Block.getBlockById(i).getUnlocalizedName(), Block.getBlockById(i).getClass().getCanonicalName()}); |
| } |
| catch (Throwable throwable) |
| { |
| return "ID #" + i; |
| } |
| } |
| }); |
| reportCategory.addCrashSectionCallable("Actual block data value", new Callable() |
| { |
| private static final String __OBFID = "CL_00000344"; |
| public String call() |
| { |
| IBlockState iblockstate = TileEntity.this.worldObj.getBlockState(TileEntity.this.pos); |
| int i = iblockstate.getBlock().getMetaFromState(iblockstate); |
| |
| if (i < 0) |
| { |
| return "Unknown? (Got " + i + ")"; |
| } |
| else |
| { |
| String s = String.format("%4s", new Object[] {Integer.toBinaryString(i)}).replace(" ", "0"); |
| return String.format("%1$d / 0x%1$X / 0b%2$s", new Object[] {Integer.valueOf(i), s}); |
| } |
| } |
| }); |
| } |
| } |
| |
| public void setPos(BlockPos posIn) |
| { |
| this.pos = posIn; |
| } |
| |
| static |
| { |
| addMapping(TileEntityFurnace.class, "Furnace"); |
| addMapping(TileEntityChest.class, "Chest"); |
| addMapping(TileEntityEnderChest.class, "EnderChest"); |
| addMapping(BlockJukebox.TileEntityJukebox.class, "RecordPlayer"); |
| addMapping(TileEntityDispenser.class, "Trap"); |
| addMapping(TileEntityDropper.class, "Dropper"); |
| addMapping(TileEntitySign.class, "Sign"); |
| addMapping(TileEntityMobSpawner.class, "MobSpawner"); |
| addMapping(TileEntityNote.class, "Music"); |
| addMapping(TileEntityPiston.class, "Piston"); |
| addMapping(TileEntityBrewingStand.class, "Cauldron"); |
| addMapping(TileEntityEnchantmentTable.class, "EnchantTable"); |
| addMapping(TileEntityEndPortal.class, "Airportal"); |
| addMapping(TileEntityCommandBlock.class, "Control"); |
| addMapping(TileEntityBeacon.class, "Beacon"); |
| addMapping(TileEntitySkull.class, "Skull"); |
| addMapping(TileEntityDaylightDetector.class, "DLDetector"); |
| addMapping(TileEntityHopper.class, "Hopper"); |
| addMapping(TileEntityComparator.class, "Comparator"); |
| addMapping(TileEntityFlowerPot.class, "FlowerPot"); |
| addMapping(TileEntityBanner.class, "Banner"); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public void onDataPacket(net.minecraft.network.NetworkManager net, net.minecraft.network.play.server.S35PacketUpdateTileEntity pkt) |
| { |
| } |
| |
| |
| |
| |
| public void onChunkUnload() |
| { |
| } |
| |
| private boolean isVanilla = getClass().getName().startsWith("net.minecraft."); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) |
| { |
| return !isVanilla || (oldState.getBlock() != newSate.getBlock()); |
| } |
| |
| public boolean shouldRenderInPass(int pass) |
| { |
| return pass == 0; |
| } |
| |
| |
| |
| |
| public static final net.minecraft.util.AxisAlignedBB INFINITE_EXTENT_AABB = new net.minecraft.util.AxisAlignedBB(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); |
| |
| |
| |
| |
| |
| |
| |
| @SideOnly(Side.CLIENT) |
| public net.minecraft.util.AxisAlignedBB getRenderBoundingBox() |
| { |
| net.minecraft.util.AxisAlignedBB bb = INFINITE_EXTENT_AABB; |
| Block type = getBlockType(); |
| if (type == Blocks.enchanting_table) |
| { |
| bb = new net.minecraft.util.AxisAlignedBB(getPos(), getPos().add(1, 1, 1)); |
| } |
| else if (type == Blocks.chest || type == Blocks.trapped_chest) |
| { |
| bb = new net.minecraft.util.AxisAlignedBB(getPos().add(-1, 0, -1), getPos().add(2, 2, 2)); |
| } |
| else if (type != null && type != Blocks.beacon) |
| { |
| net.minecraft.util.AxisAlignedBB cbb = null; |
| try |
| { |
| cbb = type.getCollisionBoundingBox(worldObj, getPos(), worldObj.getBlockState(getPos())); |
| } |
| catch (Exception e) |
| { |
| |
| |
| |
| |
| |
| |
| cbb = new net.minecraft.util.AxisAlignedBB(getPos().add(-1, 0, -1), getPos().add(1, 1, 1)); |
| } |
| if (cbb != null) bb = cbb; |
| } |
| return bb; |
| } |
| |
| |
| |
| |
| |
| |
| public boolean canRenderBreaking() |
| { |
| Block block = this.getBlockType(); |
| return (block instanceof net.minecraft.block.BlockChest || |
| block instanceof net.minecraft.block.BlockEnderChest || |
| block instanceof net.minecraft.block.BlockSign || |
| block instanceof net.minecraft.block.BlockSkull); |
| } |
| } |