protected void setBlockMode(World world, int x, int y, int z) { if (world.isRemote) return; TileEntity ent = world.getTileEntity(x, y, z); int habCount = 0; if (ent instanceof TileEntityFlickerHabitat) { TileEntityFlickerHabitat hab = (TileEntityFlickerHabitat) ent; for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { Block block = world.getBlock(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ); TileEntity te = world.getTileEntity( x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ); if (block == BlocksCommonProxy.elementalAttuner && te != null && te instanceof TileEntityFlickerHabitat) { TileEntityFlickerHabitat foundHab = (TileEntityFlickerHabitat) te; if (foundHab.isUpgrade() == false) { habCount++; if (habCount == 1) { hab.setUpgrade(true, direction); } else { world.func_147480_a(x, y, z, true); } } else { world.func_147480_a(x, y, z, true); } } } } }
@Override public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlockID) { if (world.isRemote) return; TileEntity te = world.getTileEntity(x, y, z); if (te instanceof TileEntityFlickerHabitat) { TileEntityFlickerHabitat hab = (TileEntityFlickerHabitat) te; if (hab.isUpgrade()) { int habCount = 0; for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { te = world.getTileEntity( x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ); if (te != null && te instanceof TileEntityFlickerHabitat) { TileEntityFlickerHabitat foundHab = (TileEntityFlickerHabitat) te; if (foundHab.isUpgrade() == false) { habCount++; if (habCount == 1) { } else { world.func_147480_a(x, y, z, true); } } else { world.func_147480_a(x, y, z, true); } } } if (habCount == 0) { world.func_147480_a(x, y, z, true); } } else { hab.scanForNearbyUpgrades(); if (!hab.isUpgrade()) { hab.scanForNearbyUpgrades(); } } } }
@Override public void breakBlock(World world, int x, int y, int z, Block oldBlockID, int oldMetadata) { TileEntityFlickerHabitat habitat = (TileEntityFlickerHabitat) world.getTileEntity(x, y, z); // if there is no habitat at the location break out if (habitat == null) return; // if the habitat has a flicker throw it on the ground if (habitat.hasFlicker()) { Random rand = new Random(); ItemStack stack = habitat.getStackInSlot(0); float offsetX = rand.nextFloat() * 0.8F + 0.1F; float offsetY = rand.nextFloat() * 0.8F + 0.1F; float offsetZ = rand.nextFloat() * 0.8F + 0.1F; float force = 0.05F; EntityItem entityItem = new EntityItem(world, x + offsetX, y + offsetY, z + offsetZ, stack); entityItem.motionX = (float) rand.nextGaussian() * force; entityItem.motionY = (float) rand.nextGaussian() * force + 0.2F; entityItem.motionZ = (float) rand.nextGaussian() * force; world.spawnEntityInWorld(entityItem); } if (!habitat.isUpgrade()) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { TileEntity te = world.getTileEntity( x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ); if (te != null && te instanceof TileEntityFlickerHabitat) { TileEntityFlickerHabitat upgHab = (TileEntityFlickerHabitat) te; if (upgHab.isUpgrade()) { world.func_147480_a( x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ, true); world.setTileEntity( x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ, null); } } } } super.breakBlock(world, x, y, z, oldBlockID, oldMetadata); return; }