public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (this.blockMaterial == Material.lava) { if (worldIn.getGameRules().getGameRuleBooleanValue("doFireTick")) { int var5 = rand.nextInt(3); if (var5 > 0) { BlockPos var6 = pos; for (int var7 = 0; var7 < var5; ++var7) { var6 = var6.add(rand.nextInt(3) - 1, 1, rand.nextInt(3) - 1); Block var8 = worldIn.getBlockState(var6).getBlock(); if (var8.blockMaterial == Material.air) { if (this.isSurroundingBlockFlammable(worldIn, var6)) { worldIn.setBlockState(var6, Blocks.fire.getDefaultState()); return; } } else if (var8.blockMaterial.blocksMovement()) { return; } } } else { for (int var9 = 0; var9 < 3; ++var9) { BlockPos var10 = pos.add(rand.nextInt(3) - 1, 0, rand.nextInt(3) - 1); if (worldIn.isAirBlock(var10.offsetUp()) && this.getCanBlockBurn(worldIn, var10)) { worldIn.setBlockState(var10.offsetUp(), Blocks.fire.getDefaultState()); } } } } } }
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (rand.nextInt(25) == 0) { int var5 = 5; boolean var6 = true; Iterator var7 = BlockPos.getAllInBoxMutable(pos.add(-4, -1, -4), pos.add(4, 1, 4)).iterator(); while (var7.hasNext()) { BlockPos var8 = (BlockPos) var7.next(); if (worldIn.getBlockState(var8).getBlock() == this) { --var5; if (var5 <= 0) { return; } } } BlockPos var9 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1); for (int var10 = 0; var10 < 4; ++var10) { if (worldIn.isAirBlock(var9) && this.canBlockStay(worldIn, var9, this.getDefaultState())) { pos = var9; } var9 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1); } if (worldIn.isAirBlock(var9) && this.canBlockStay(worldIn, var9, this.getDefaultState())) { worldIn.setBlockState(var9, this.getDefaultState(), 2); } } }
void clearAreaWater(World world, BlockPos center, int wdt, int hgt) { for (int x = -wdt / 2; x < wdt; x++) { for (int z = -wdt / 2; z < wdt; z++) { for (int y = -hgt / 2; y < hgt; y++) { if (world.getBlockState(center.add(x, y, z)).getBlock().getMaterial() == Material.water) { world.setBlockState(center.add(x, y, z), Blocks.air.getDefaultState()); } } } } }
void clearAreaRock(World world, BlockPos center, int wdt, int hgt) { for (int x = -wdt / 2; x < wdt; x++) { for (int z = -wdt / 2; z < wdt; z++) { for (int y = 0; y < 240; y++) { if (world.getBlockState(center.add(x, y, z)).getBlock() instanceof BlockRock) { world.setBlockState(center.add(x, y, z), Blocks.air.getDefaultState()); } } } } }
public boolean generate(World worldIn, Random rand, BlockPos position) { for (int i = 0; i < 20; ++i) { BlockPos blockpos = position.add(rand.nextInt(4) - rand.nextInt(4), 0, rand.nextInt(4) - rand.nextInt(4)); if (worldIn.isAirBlock(blockpos)) { BlockPos blockpos1 = blockpos.down(); if (worldIn.getBlockState(blockpos1.west()).getBlock().getMaterial() == Material.water || worldIn.getBlockState(blockpos1.east()).getBlock().getMaterial() == Material.water || worldIn.getBlockState(blockpos1.north()).getBlock().getMaterial() == Material.water || worldIn.getBlockState(blockpos1.south()).getBlock().getMaterial() == Material.water) { int j = 2 + rand.nextInt(rand.nextInt(3) + 1); for (int k = 0; k < j; ++k) { if (Blocks.reeds.canBlockStay(worldIn, blockpos)) { worldIn.setBlockState(blockpos.up(k), Blocks.reeds.getDefaultState(), 2); } } } } } return true; }
@Override public void populate(Chunk chunk, Random random) { Vector3i min = chunk.getBlockMin(); World world = (World) chunk.getWorld(); BlockPos position = new BlockPos(min.getX(), min.getY(), min.getZ()); ShrubType stype = ShrubTypes.TALL_GRASS; List<ShrubType> result; // The vanilla populator places down grass in batches of 128, which is a // decent enough amount in order to get nice 'patches' of grass so we // divide the total count into batches of 128. int n = (int) Math.ceil(this.count.getFlooredAmount(random) / 128f); for (int i = 0; i < n; i++) { BlockPos pos = position.add(random.nextInt(16) + 8, 0, random.nextInt(16) + 8); pos = world.getTopSolidOrLiquidBlock(pos).add(0, 1, 0); if (this.override != null) { Location<Chunk> pos2 = new Location<>(chunk, VecHelper.toVector(pos)); stype = this.override.apply(pos2); } else { result = this.types.get(random); if (result.isEmpty()) { continue; } stype = result.get(0); } BlockTallGrass.EnumType type = (BlockTallGrass.EnumType) (Object) stype; this.tallGrassState = Blocks.tallgrass.getDefaultState().withProperty(BlockTallGrass.TYPE, type); generate(world, random, pos); } }
void createPlane(World world, BlockPos center, int wdt, IBlockState state) { for (int x = -wdt / 2; x < wdt; x++) { for (int z = -wdt / 2; z < wdt; z++) { world.setBlockState(center.add(x, -1, z), state); } } }
void clearArea(World world, BlockPos center, int wdt, int hgt) { for (int x = -wdt / 2; x < wdt; x++) { for (int z = -wdt / 2; z < wdt; z++) { for (int y = 0; y < hgt; y++) { world.setBlockState(center.add(x, y, z), Blocks.air.getDefaultState()); } } } }
@SubscribeEvent public void chopChop(TickEvent.WorldTickEvent event) { if (event.side.isClient()) { finish(); return; } // setup int left = blocksPerTick; // continue running BlockPos pos; while (left > 0) { // completely done or can't do our job anymore?! if (blocks.isEmpty() || ToolHelper.isBroken(tool)) { finish(); return; } pos = blocks.remove(); if (!visited.add(pos)) { continue; } // can we harvest the block and is effective? if (!isLog(world, pos) || !ToolHelper.isToolEffective2(tool, world.getBlockState(pos))) { continue; } // save its neighbours for (EnumFacing facing : new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST }) { BlockPos pos2 = pos.offset(facing); if (!visited.contains(pos2)) { blocks.add(pos2); } } // also add the layer above.. stupid acacia trees for (int x = 0; x < 3; x++) { for (int z = 0; z < 3; z++) { BlockPos pos2 = pos.add(-1 + x, 1, -1 + z); if (!visited.contains(pos2)) { blocks.add(pos2); } } } // break it, wooo! ToolHelper.breakExtraBlock(tool, world, player, pos, pos); left--; } }
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { BlockPos bottomBlock = pos.add(0, -1, 0); if (worldIn.getBlockState(bottomBlock).getBlock() != JCBlockRegistry.cultivate_bottom) { worldIn.setBlockState( bottomBlock, JCBlockRegistry.cultivate_bottom .getDefaultState() .withProperty(COLOR, state.getValue(COLOR))); } }
void replaceBlocks(BlockPos center, ICommandSender sender, int wdt, int hgt, boolean ignoremeta) { ItemStack searchstack = ((EntityPlayer) sender.getCommandSenderEntity()).inventory.mainInventory[0]; ItemStack replacestack = ((EntityPlayer) sender.getCommandSenderEntity()).inventory.mainInventory[1]; if (!(searchstack.getItem() instanceof ItemBlock)) { sender.addChatMessage(new ChatComponentText("Search item is not a block")); return; } if (!(replacestack.getItem() instanceof ItemBlock)) { sender.addChatMessage(new ChatComponentText("Replace item is not a block")); return; } Block searchblock = ((ItemBlock) searchstack.getItem()).block; Block replaceblock = ((ItemBlock) replacestack.getItem()).block; IBlockState replaceblockstate = replaceblock.getStateFromMeta(replacestack.getItemDamage()); int replaced = 0; for (int x = -wdt / 2; x < wdt; x++) { for (int z = -wdt / 2; z < wdt; z++) { for (int y = 0; y < hgt; y++) { IBlockState blockstate = sender.getEntityWorld().getBlockState(center.add(x, y, z)); if (blockstate.getBlock() == searchblock && (ignoremeta || blockstate.getBlock().getMetaFromState(blockstate) == searchstack.getItemDamage())) { sender.getEntityWorld().setBlockState(center.add(x, y, z), replaceblockstate); replaced++; } } } } sender.addChatMessage(new ChatComponentText("Replaced " + replaced + " blocks")); }
protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos) { float f = 1.0F; BlockPos blockpos = pos.down(); for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { float f1 = 0.0F; IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j)); if (iblockstate.getBlock() == Blocks.farmland) { f1 = 1.0F; if (((Integer) iblockstate.getValue(BlockFarmland.MOISTURE)).intValue() > 0) { f1 = 3.0F; } } if (i != 0 || j != 0) { f1 /= 4.0F; } f += f1; } } BlockPos blockpos1 = pos.north(); BlockPos blockpos2 = pos.south(); BlockPos blockpos3 = pos.west(); BlockPos blockpos4 = pos.east(); boolean flag = blockIn == worldIn.getBlockState(blockpos3).getBlock() || blockIn == worldIn.getBlockState(blockpos4).getBlock(); boolean flag1 = blockIn == worldIn.getBlockState(blockpos1).getBlock() || blockIn == worldIn.getBlockState(blockpos2).getBlock(); if (flag && flag1) { f /= 2.0F; } else { boolean flag2 = blockIn == worldIn.getBlockState(blockpos3.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos3.south()).getBlock(); if (flag2) { f /= 2.0F; } } return f; }
private Set<EnumFacing> getVisibleSides(final BlockPos pos) { final VisGraph visgraph = new VisGraph(); final BlockPos posChunk = new BlockPos(pos.getX() & ~0xF, pos.getY() & ~0xF, pos.getZ() & ~0xF); for (final BlockPos.MutableBlockPos mutableBlockPos : (Iterable<BlockPos.MutableBlockPos>) BlockPos.getAllInBoxMutable(posChunk, posChunk.add(15, 15, 15))) { if (this.world.getBlockState(mutableBlockPos).getBlock().isOpaqueCube()) { visgraph.func_178606_a(mutableBlockPos); } } return visgraph.func_178609_b(pos); }
@Override public void onBlockPlacedBy( World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { final int angle = MathHelper.floor_double(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; int change = EnumFacing.getHorizontal(angle).getOpposite().getHorizontalIndex(); if (stack.getItemDamage() >= METADATA_CARGO_UNLOADER) { change += METADATA_CARGO_UNLOADER; } else if (stack.getItemDamage() >= METADATA_CARGO_LOADER) { change += METADATA_CARGO_LOADER; } worldIn.setBlockState(pos, getStateFromMeta(change), 3); for (int dX = -2; dX < 3; dX++) { for (int dZ = -2; dZ < 3; dZ++) { final Block block = worldIn.getBlockState(pos.add(dX, 0, dZ)).getBlock(); if (block == GCBlocks.landingPadFull) { worldIn.markBlockForUpdate(pos.add(dX, 0, dZ)); } } } }
public static boolean detectTree(World world, BlockPos origin) { BlockPos pos = null; Stack<BlockPos> candidates = new Stack<BlockPos>(); candidates.add(origin); while (!candidates.isEmpty()) { BlockPos candidate = candidates.pop(); if ((pos == null || candidate.getY() > pos.getY()) && isLog(world, candidate)) { pos = candidate.up(); // go up while (isLog(world, pos)) { pos = pos.up(); } // check if we still have a way diagonally up candidates.add(pos.north()); candidates.add(pos.east()); candidates.add(pos.south()); candidates.add(pos.west()); } } // not even one match, so there were no logs. if (pos == null) { return false; } // check if there were enough leaves around the last position // pos now contains the block above the topmost log // we want at least 5 leaves in the surrounding 26 blocks int d = 3; int o = -1; // -(d-1)/2 int leaves = 0; for (int x = 0; x < d; x++) { for (int y = 0; y < d; y++) { for (int z = 0; z < d; z++) { BlockPos leaf = pos.add(o + x, o + y, o + z); if (world.getBlockState(leaf).getBlock().isLeaves(world, leaf)) { if (++leaves >= 5) { return true; } } } } } // not enough leaves. sorreh return false; }
@Override public boolean onBlockActivated( World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { BlockPos add = pos.add(0, -1, 0); IBlockState blockState = world.getBlockState(add); return blockState .getBlock() .onBlockActivated(world, add, blockState, player, side, hitX, hitY, hitZ); }
private BlockPos find() { NukerMod nuker = (NukerMod) WurstClient.INSTANCE.modManager.getModByClass(NukerMod.class); LinkedList<BlockPos> queue = new LinkedList<BlockPos>(); HashSet<BlockPos> alreadyProcessed = new HashSet<BlockPos>(); queue.add(new BlockPos(Minecraft.getMinecraft().thePlayer)); while (!queue.isEmpty()) { BlockPos currentPos = queue.poll(); if (alreadyProcessed.contains(currentPos)) continue; alreadyProcessed.add(currentPos); if (BlockUtils.getPlayerBlockDistance(currentPos) > nuker.yesCheatRange) continue; int currentID = Block.getIdFromBlock( Minecraft.getMinecraft().theWorld.getBlockState(currentPos).getBlock()); if (currentID != 0) switch (WurstClient.INSTANCE.options.nukerMode) { case 1: if (currentID == NukerMod.id) return currentPos; break; case 2: if (currentPos.getY() >= Minecraft.getMinecraft().thePlayer.posY) return currentPos; break; case 3: if (Minecraft.getMinecraft() .theWorld .getBlockState(currentPos) .getBlock() .getPlayerRelativeBlockHardness( Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().theWorld, currentPos) >= 1) return currentPos; break; default: return currentPos; } if (!Minecraft.getMinecraft() .theWorld .getBlockState(currentPos) .getBlock() .getMaterial() .blocksMovement()) { queue.add(currentPos.add(0, 0, -1)); // north queue.add(currentPos.add(0, 0, 1)); // south queue.add(currentPos.add(-1, 0, 0)); // west queue.add(currentPos.add(1, 0, 0)); // east queue.add(currentPos.add(0, -1, 0)); // down queue.add(currentPos.add(0, 1, 0)); // up } } return null; }
@Override public boolean generate(World world, Random rand, BlockPos blockPos) { int h = blockPos.getY(); int h1 = world.getHorizon(blockPos.add(1, 0, 1)).getY(); int h2 = world.getHorizon(blockPos.add(0, 0, 1)).getY(); int h3 = world.getHorizon(blockPos.add(1, 0, 0)).getY(); Block b = world.getBlockState(blockPos.down()).getBlock(); if (!b.isNormalCube()) return false; if (Math.abs(-h1) < 2 && Math.abs(h - h2) < 2 && Math.abs(h - h3) < 2) { if (!checkGround(world, blockPos.add(0, -1, 0))) return false; if (!checkGround(world, blockPos.add(1, -1, 0))) return false; if (!checkGround(world, blockPos.add(0, -1, 1))) return false; if (!checkGround(world, blockPos.add(1, -1, 1))) return false; int dir = rand.nextInt(4); blockPos.add(rotX[dir], 0, rotZ[dir]); ItemTent.placeAt(world, blockPos, dir, true, true); for (int[] pos : entrance[dir]) { world.setBlockToAir(blockPos.add(pos[0], 0, pos[1])); world.setBlockToAir(blockPos.add(pos[0], 1, pos[1])); } if (rand.nextInt(3) == 0) { int r = rand.nextInt(2); BlockPos craftPos = world.getHorizon(blockPos.add(entrance[dir][r][0] * 2, 0, entrance[dir][r][1] * 2)); world.setBlockState(craftPos, Blocks.crafting_table.getDefaultState()); } if (rand.nextInt(3) == 0) { int r = rand.nextInt(2); BlockPos craftPos = world.getHorizon(blockPos.add(entrance[dir][r][0] * 2, 0, entrance[dir][r][1] * 2)); world.setBlockState(craftPos, Blocks.torch.getDefaultState()); } return true; } return false; }
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { if (!world.isRemote) { if (world.getLightFromNeighbors(pos.offsetUp()) < 4 && world.getBlockState(pos.offsetUp()).getBlock().getLightOpacity() > 2) { world.setBlockState( pos, Blocks.dirt .getDefaultState() .withProperty(BlockDirt.VARIANT, BlockDirt.EnumDirtType.DIRT)); } else if (world.getLightFromNeighbors(pos.offsetUp()) >= 9) { for (int i = 0; i < 4; i++) { BlockPos target = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1); if (pos.blockIs(world, Blocks.dirt) && target.getBlockProperty(world, BlockDirt.VARIANT) == BlockDirt.EnumDirtType.DIRT && world.getLightFromNeighbors(target.offsetUp()) >= 4 && pos.offsetUp().getBlock(world).getLightOpacity() <= 2) { world.setBlockState(target, this.getDefaultState()); } } } } }
@Override public void onCreate(World world, BlockPos placedPosition) { int buildHeight = world.getHeight() - 1; for (int y = 0; y < 3; y += 2) { if (placedPosition.getY() + y > buildHeight) return; for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { final BlockPos vecToAdd = placedPosition.add(x, y, z); if (!vecToAdd.equals(placedPosition)) { ((BlockTelepadFake) AsteroidBlocks.fakeTelepad) .makeFakeBlock( world, vecToAdd, placedPosition, AsteroidBlocks.fakeTelepad .getDefaultState() .withProperty(BlockTelepadFake.TOP, y == 2)); } } } } }
public boolean generate(World worldIn, Random p_180709_2_, BlockPos p_180709_3_) { Block block; do { block = worldIn.getBlockState(p_180709_3_).getBlock(); if (!block.isLeaves(worldIn, p_180709_3_) && !block.isLeaves(worldIn, p_180709_3_)) break; p_180709_3_ = p_180709_3_.down(); } while (p_180709_3_.getY() > 0); for (int i = 0; i < 4; ++i) { BlockPos blockpos1 = p_180709_3_.add( p_180709_2_.nextInt(8) - p_180709_2_.nextInt(8), p_180709_2_.nextInt(4) - p_180709_2_.nextInt(4), p_180709_2_.nextInt(8) - p_180709_2_.nextInt(8)); if (worldIn.isAirBlock(blockpos1) && Blocks.deadbush.canBlockStay(worldIn, blockpos1, Blocks.deadbush.getDefaultState())) { worldIn.setBlockState(blockpos1, Blocks.deadbush.getDefaultState(), 2); } } return true; }
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getBlock().getLightOpacity(worldIn, pos.up()) > 2) { worldIn.setBlockState(pos, MBlocks.dirt_permafrost.getDefaultState()); } else { if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { for (int i = 0; i < 4; ++i) { BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1); Block block = worldIn.getBlockState(blockpos1.up()).getBlock(); IBlockState iblockstate1 = worldIn.getBlockState(blockpos1); if (iblockstate1.getBlock() == MBlocks.dirt_permafrost && worldIn.getLightFromNeighbors(blockpos1.up()) >= 4 && block.getLightOpacity(worldIn, blockpos1.up()) <= 2) { worldIn.setBlockState(blockpos1, MBlocks.lichen_permafrost.getDefaultState()); } } } } } }
@Override public void rebuildChunk( final float x, final float y, final float z, final ChunkCompileTaskGenerator generator) { final CompiledOverlay compiledOverlay = new CompiledOverlay(); final BlockPos from = getPosition(); final BlockPos to = from.add(15, 15, 15); generator.getLock().lock(); RegionRenderCache regionRenderCache; final SchematicWorld schematic = (SchematicWorld) this.world; try { if (generator.getStatus() != ChunkCompileTaskGenerator.Status.COMPILING) { return; } if (from.getX() < 0 || from.getZ() < 0 || from.getX() >= schematic.getWidth() || from.getZ() >= schematic.getLength()) { generator.setCompiledChunk(CompiledChunk.DUMMY); return; } regionRenderCache = new RegionRenderCache(this.world, from.add(-1, -1, -1), to.add(1, 1, 1), 1); generator.setCompiledChunk(compiledOverlay); } finally { generator.getLock().unlock(); } final VisGraph visgraph = new VisGraph(); if (!regionRenderCache.extendedLevelsInChunkCache()) { ++renderChunksUpdated; final World mcWorld = Minecraft.getMinecraft().theWorld; final EnumWorldBlockLayer layer = EnumWorldBlockLayer.TRANSLUCENT; final WorldRenderer worldRenderer = generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(layer); GeometryTessellator.setStaticDelta(ConfigurationHandler.blockDelta); for (final BlockPos pos : BlockPos.getAllInBox(from, to)) { if (schematic.isRenderingLayer && schematic.renderingLayer != pos.getY() || !schematic.isInside(pos)) { continue; } boolean render = false; int sides = 0; int color = 0; final IBlockState schBlockState = schematic.getBlockState(pos); final Block schBlock = schBlockState.getBlock(); if (schBlock.isOpaqueCube()) { visgraph.func_178606_a(pos); } final BlockPos mcPos = pos.add(schematic.position); final IBlockState mcBlockState = mcWorld.getBlockState(mcPos); final Block mcBlock = mcBlockState.getBlock(); final boolean isSchAirBlock = schematic.isAirBlock(pos); final boolean isMcAirBlock = mcWorld.isAirBlock(mcPos) || ConfigurationHandler.isExtraAirBlock(mcBlock); if (!isMcAirBlock) { if (isSchAirBlock && ConfigurationHandler.highlightAir) { render = true; sides = GeometryMasks.Quad.ALL; color = 0xBF00BF; } } if (!render) { if (ConfigurationHandler.highlight) { if (!isMcAirBlock) { if (schBlock != mcBlock) { render = true; color = 0xFF0000; } else if (schBlock.getMetaFromState(schBlockState) != mcBlock.getMetaFromState(mcBlockState)) { render = true; color = 0xBF5F00; } } else if (!isSchAirBlock) { render = true; color = 0x00BFFF; } } if (render) { if (schBlock.shouldSideBeRendered( schematic, pos.offset(EnumFacing.DOWN), EnumFacing.DOWN)) { sides |= GeometryMasks.Quad.DOWN; } if (schBlock.shouldSideBeRendered( schematic, pos.offset(EnumFacing.UP), EnumFacing.UP)) { sides |= GeometryMasks.Quad.UP; } if (schBlock.shouldSideBeRendered( schematic, pos.offset(EnumFacing.NORTH), EnumFacing.NORTH)) { sides |= GeometryMasks.Quad.NORTH; } if (schBlock.shouldSideBeRendered( schematic, pos.offset(EnumFacing.SOUTH), EnumFacing.SOUTH)) { sides |= GeometryMasks.Quad.SOUTH; } if (schBlock.shouldSideBeRendered( schematic, pos.offset(EnumFacing.WEST), EnumFacing.WEST)) { sides |= GeometryMasks.Quad.WEST; } if (schBlock.shouldSideBeRendered( schematic, pos.offset(EnumFacing.EAST), EnumFacing.EAST)) { sides |= GeometryMasks.Quad.EAST; } } } if (render && sides != 0) { if (!compiledOverlay.isLayerStarted(layer)) { compiledOverlay.setLayerStarted(layer); preRenderBlocks(worldRenderer, from); } GeometryTessellator.drawCuboid(worldRenderer, pos, sides, 0x3F000000 | color); compiledOverlay.setLayerUsed(layer); } } if (compiledOverlay.isLayerStarted(layer)) { postRenderBlocks(layer, x, y, z, worldRenderer, compiledOverlay); } } compiledOverlay.setVisibility(visgraph.computeVisibility()); }
private int spread(World world, BlockPos from, int times) { if (times == 0) return 0; if (OreDictionary.itemMatches( new ItemStack(Blocks.log), new ItemStack(world.getBlockState(from.add(0, -1, 0)).getBlock()), false)) { world.destroyBlock(from.add(0, -1, 0), false); world.setBlockState(from.add(0, -1, 0), Parachronology.petrifiedWood.getDefaultState()); world.markBlockForUpdate(from); times--; times = spread(world, from.add(0, -1, 0), times); } if (times == 0) return 0; if (OreDictionary.itemMatches( new ItemStack(Blocks.log), new ItemStack(world.getBlockState(from.add(0, 1, 0)).getBlock()), false)) { world.destroyBlock(from.add(0, 1, 0), false); world.setBlockState(from.add(0, 1, 0), Parachronology.petrifiedWood.getDefaultState()); world.markBlockForUpdate(from); times--; times = spread(world, from.add(0, 1, 0), times); } if (times == 0) return 0; if (OreDictionary.itemMatches( new ItemStack(Blocks.log), new ItemStack(world.getBlockState(from.add(-1, 0, 0)).getBlock()), false)) { world.destroyBlock(from.add(-1, 0, 0), false); world.setBlockState(from.add(-1, 0, 0), Parachronology.petrifiedWood.getDefaultState()); world.markBlockForUpdate(from); times--; times = spread(world, from.add(-1, 0, 0), times); } if (times == 0) return 0; if (OreDictionary.itemMatches( new ItemStack(Blocks.log), new ItemStack(world.getBlockState(from.add(1, 0, 0)).getBlock()), false)) { world.destroyBlock(from.add(1, 0, 0), false); world.setBlockState(from.add(1, 0, 0), Parachronology.petrifiedWood.getDefaultState()); world.markBlockForUpdate(from); times--; times = spread(world, from.add(1, 0, 0), times); } if (times == 0) return 0; if (OreDictionary.itemMatches( new ItemStack(Blocks.log), new ItemStack(world.getBlockState(from.add(0, 0, -1)).getBlock()), false)) { world.destroyBlock(from.add(0, 0, -1), false); world.setBlockState(from.add(0, 0, -1), Parachronology.petrifiedWood.getDefaultState()); world.markBlockForUpdate(from); times--; times = spread(world, from.add(0, 0, -1), times); } if (times == 0) return 0; if (OreDictionary.itemMatches( new ItemStack(Blocks.log), new ItemStack(world.getBlockState(from.add(0, 0, 1)).getBlock()), false)) { world.destroyBlock(from.add(0, 0, 1), false); world.setBlockState(from.add(0, 0, 1), Parachronology.petrifiedWood.getDefaultState()); world.markBlockForUpdate(from); times--; times = spread(world, from.add(0, 0, 1), times); } return times; }
/** Called on both Client and Server when World#addBlockEvent is called */ public boolean onBlockEventReceived( World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) { EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); if (!worldIn.isRemote) { boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing); if (flag && eventID == 1) { worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2); return false; } if (!flag && eventID == 0) { return false; } } if (eventID == 0) { if (!this.doMove(worldIn, pos, enumfacing, true)) { return false; } worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2); worldIn.playSoundEffect( (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, "tile.piston.out", 0.5F, worldIn.rand.nextFloat() * 0.25F + 0.6F); } else if (eventID == 1) { TileEntity tileentity1 = worldIn.getTileEntity(pos.offset(enumfacing)); if (tileentity1 instanceof TileEntityPiston) { ((TileEntityPiston) tileentity1).clearPistonTileEntity(); } worldIn.setBlockState( pos, Blocks.piston_extension .getDefaultState() .withProperty(BlockPistonMoving.FACING, enumfacing) .withProperty( BlockPistonMoving.TYPE, this.isSticky ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT), 3); worldIn.setTileEntity( pos, BlockPistonMoving.newTileEntity( this.getStateFromMeta(eventParam), enumfacing, false, true)); if (this.isSticky) { BlockPos blockpos = pos.add( enumfacing.getFrontOffsetX() * 2, enumfacing.getFrontOffsetY() * 2, enumfacing.getFrontOffsetZ() * 2); Block block = worldIn.getBlockState(blockpos).getBlock(); boolean flag1 = false; if (block == Blocks.piston_extension) { TileEntity tileentity = worldIn.getTileEntity(blockpos); if (tileentity instanceof TileEntityPiston) { TileEntityPiston tileentitypiston = (TileEntityPiston) tileentity; if (tileentitypiston.getFacing() == enumfacing && tileentitypiston.isExtending()) { tileentitypiston.clearPistonTileEntity(); flag1 = true; } } } if (!flag1 && block.getMaterial() != Material.air && canPush(block, worldIn, blockpos, enumfacing.getOpposite(), false) && (block.getMobilityFlag() == 0 || block == Blocks.piston || block == Blocks.sticky_piston)) { this.doMove(worldIn, pos, enumfacing, false); } } else { worldIn.setBlockToAir(pos.offset(enumfacing)); } worldIn.playSoundEffect( (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, "tile.piston.in", 0.5F, worldIn.rand.nextFloat() * 0.15F + 0.6F); } return true; }
/** Callback when the command is invoked */ public void processCommand(ICommandSender sender, String[] args) throws CommandException { if (args.length < 9) { throw new WrongUsageException("commands.compare.usage", new Object[0]); } else { sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0); BlockPos blockpos = parseBlockPos(sender, args, 0, false); BlockPos blockpos1 = parseBlockPos(sender, args, 3, false); BlockPos blockpos2 = parseBlockPos(sender, args, 6, false); StructureBoundingBox structureboundingbox = new StructureBoundingBox(blockpos, blockpos1); StructureBoundingBox structureboundingbox1 = new StructureBoundingBox(blockpos2, blockpos2.add(structureboundingbox.func_175896_b())); int i = structureboundingbox.getXSize() * structureboundingbox.getYSize() * structureboundingbox.getZSize(); if (i > 524288) { throw new CommandException( "commands.compare.tooManyBlocks", new Object[] {Integer.valueOf(i), Integer.valueOf(524288)}); } else if (structureboundingbox.minY >= 0 && structureboundingbox.maxY < 256 && structureboundingbox1.minY >= 0 && structureboundingbox1.maxY < 256) { World world = sender.getEntityWorld(); if (world.isAreaLoaded(structureboundingbox) && world.isAreaLoaded(structureboundingbox1)) { boolean flag = false; if (args.length > 9 && args[9].equals("masked")) { flag = true; } i = 0; BlockPos blockpos3 = new BlockPos( structureboundingbox1.minX - structureboundingbox.minX, structureboundingbox1.minY - structureboundingbox.minY, structureboundingbox1.minZ - structureboundingbox.minZ); BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos(); for (int j = structureboundingbox.minZ; j <= structureboundingbox.maxZ; ++j) { for (int k = structureboundingbox.minY; k <= structureboundingbox.maxY; ++k) { for (int l = structureboundingbox.minX; l <= structureboundingbox.maxX; ++l) { blockpos$mutableblockpos.func_181079_c(l, k, j); blockpos$mutableblockpos1.func_181079_c( l + blockpos3.getX(), k + blockpos3.getY(), j + blockpos3.getZ()); boolean flag1 = false; IBlockState iblockstate = world.getBlockState(blockpos$mutableblockpos); if (!flag || iblockstate.getBlock() != Blocks.air) { if (iblockstate == world.getBlockState(blockpos$mutableblockpos1)) { TileEntity tileentity = world.getTileEntity(blockpos$mutableblockpos); TileEntity tileentity1 = world.getTileEntity(blockpos$mutableblockpos1); if (tileentity != null && tileentity1 != null) { NBTTagCompound nbttagcompound = new NBTTagCompound(); tileentity.writeToNBT(nbttagcompound); nbttagcompound.removeTag("x"); nbttagcompound.removeTag("y"); nbttagcompound.removeTag("z"); NBTTagCompound nbttagcompound1 = new NBTTagCompound(); tileentity1.writeToNBT(nbttagcompound1); nbttagcompound1.removeTag("x"); nbttagcompound1.removeTag("y"); nbttagcompound1.removeTag("z"); if (!nbttagcompound.equals(nbttagcompound1)) { flag1 = true; } } else if (tileentity != null) { flag1 = true; } } else { flag1 = true; } ++i; if (flag1) { throw new CommandException("commands.compare.failed", new Object[0]); } } } } } sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, i); notifyOperators( sender, this, "commands.compare.success", new Object[] {Integer.valueOf(i)}); } else { throw new CommandException("commands.compare.outOfWorld", new Object[0]); } } else { throw new CommandException("commands.compare.outOfWorld", new Object[0]); } } }
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { worldIn.setBlockState(pos.add(0, -1, 0), Blocks.air.getDefaultState()); dropItems(worldIn, pos); super.breakBlock(worldIn, pos, state); }