Пример #1
0
  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;
  }
Пример #2
0
 @Override
 protected void entityInit() {
   dataWatcher.addObject(OBJECT_BLOCK_NAME, BlockProperties.getBlockName(Blocks.bedrock));
   dataWatcher.addObject(OBJECT_BLOCK_META, 0);
 }