public static EntityBlock create( EntityPlayer player, World world, int x, int y, int z, Class<? extends EntityBlock> klazz) { Block block = world.getBlock(x, y, z); if (block.isAir(world, x, y, z)) return null; int meta = world.getBlockMetadata(x, y, z); final EntityBlock entity; try { entity = klazz.getConstructor(World.class).newInstance(world); } catch (Throwable t) { Log.warn(t, "Failed to create EntityBlock(%s) at %d,%d,%d", klazz, x, y, z); return null; } entity.setBlockNameAndMeta(BlockProperties.getBlockName(block), meta); final TileEntity te = world.getTileEntity(x, y, z); if (te != null) { entity.tileEntity = new NBTTagCompound(); te.writeToNBT(entity.tileEntity); } final boolean blockRemoved = new BlockManipulator(world, player, x, y, z).setSilentTeRemove(true).remove(); if (!blockRemoved) return null; entity.setPositionAndRotation(x + 0.5, y + 0.5, z + 0.5, 0, 0); return entity; }
@Override protected void readEntityFromNBT(NBTTagCompound tag) { String blockName = tag.getString(TAG_BLOCK_NAME); Block block = BlockProperties.getBlockByName(blockName); if (block == null) { setDead(); return; } int blockMeta = tag.getInteger(TAG_BLOCK_META); setBlockNameAndMeta(blockName, blockMeta); if (tag.hasKey(TAG_TILE_ENTITY, Constants.NBT.TAG_COMPOUND)) this.tileEntity = tag.getCompoundTag(TAG_TILE_ENTITY); else this.tileEntity = null; }
public Block getBlock() { return BlockProperties.getBlockByName(getBlockName()); }
@Override protected void entityInit() { dataWatcher.addObject(OBJECT_BLOCK_NAME, BlockProperties.getBlockName(Blocks.bedrock)); dataWatcher.addObject(OBJECT_BLOCK_META, 0); }