From 464f516a40667d627d6ee620526f20032e3e6377 Mon Sep 17 00:00:00 2001 From: Runemoro Date: Tue, 2 Jan 2018 05:01:01 -0500 Subject: [PATCH] Make non-solid blocks decay to air in limbo --- .../shared/items/ItemDimensionalDoor.java | 3 +- .../shared/items/ItemDimensionalTrapdoor.java | 3 +- .../world/limbodimension/LimboDecay.java | 50 +++++++++++-------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/dimdev/dimdoors/shared/items/ItemDimensionalDoor.java b/src/main/java/org/dimdev/dimdoors/shared/items/ItemDimensionalDoor.java index 75a66c0c..a46b8a6b 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/items/ItemDimensionalDoor.java +++ b/src/main/java/org/dimdev/dimdoors/shared/items/ItemDimensionalDoor.java @@ -20,9 +20,10 @@ public abstract class ItemDimensionalDoor extends ItemDoor { // TODO: endermen/block placers should set up blocks too, but this method doesn't get called when they place the block @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + boolean replaceable = world.getBlockState(pos).getBlock().isReplaceable(world, pos); // Check this before calling super, since that changes the block EnumActionResult result = super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ); if (result == EnumActionResult.SUCCESS) { - if (!world.getBlockState(pos).getBlock().isReplaceable(world, pos)) pos = pos.offset(facing); + if (!replaceable) pos = pos.offset(facing); IBlockState state = world.getBlockState(pos); if (state.getBlock() instanceof IRiftProvider) { // In case the door is placed on glass/leaves ((IRiftProvider) state.getBlock()).handleRiftSetup(world, pos, state); diff --git a/src/main/java/org/dimdev/dimdoors/shared/items/ItemDimensionalTrapdoor.java b/src/main/java/org/dimdev/dimdoors/shared/items/ItemDimensionalTrapdoor.java index 0568c0fa..74ebfb89 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/items/ItemDimensionalTrapdoor.java +++ b/src/main/java/org/dimdev/dimdoors/shared/items/ItemDimensionalTrapdoor.java @@ -21,9 +21,10 @@ public abstract class ItemDimensionalTrapdoor extends ItemBlock { // TODO: endermen/block placers should set up blocks too, but this method doesn't get called when they place the block @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + boolean replaceable = world.getBlockState(pos).getBlock().isReplaceable(world, pos); // Check this before calling super, since that changes the block EnumActionResult result = super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ); if (result == EnumActionResult.SUCCESS) { - if (!world.getBlockState(pos).getBlock().isReplaceable(world, pos)) pos = pos.offset(facing); + if (!replaceable) pos = pos.offset(facing); IBlockState state = world.getBlockState(pos); ((IRiftProvider) state.getBlock()).handleRiftSetup(world, pos, state); } diff --git a/src/main/java/org/dimdev/dimdoors/shared/world/limbodimension/LimboDecay.java b/src/main/java/org/dimdev/dimdoors/shared/world/limbodimension/LimboDecay.java index 74ac6d9d..2d5c64d3 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/world/limbodimension/LimboDecay.java +++ b/src/main/java/org/dimdev/dimdoors/shared/world/limbodimension/LimboDecay.java @@ -33,7 +33,7 @@ public final class LimboDecay { public static IBlockState[] getDecaySequence() { if (decaySequence == null) { - decaySequence = new IBlockState[] { + decaySequence = new IBlockState[]{ ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.UNRAVELED), Blocks.GRAVEL.getDefaultState(), Blocks.COBBLESTONE.getDefaultState(), @@ -46,7 +46,7 @@ public final class LimboDecay { public static IBlockState[] getBlocksImmuneToDecay() { if (blocksImmuneToDecay == null) { - blocksImmuneToDecay = new IBlockState[] { + blocksImmuneToDecay = new IBlockState[]{ ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.UNRAVELED), ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.ETERNAL), ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.ANCIENT), @@ -88,15 +88,14 @@ public final class LimboDecay { * Picks random blocks from each active chunk in Limbo and, if decay is applicable, converts them directly to Unraveled Fabric. * This decay method is designed to stop players from avoiding Limbo decay by building floating structures. */ - public static void applyRandomFastDecay() - { + public static void applyRandomFastDecay() { int x, y, z; int sectionY; int limboHeight; int[] limbo = DimensionManager.getDimensions(ModDimensions.LIMBO); - for (Integer i : limbo){ + for (Integer i : limbo) { World world = DimensionManager.getWorld(i); limboHeight = world.getHeight(); @@ -107,9 +106,10 @@ public final class LimboDecay { //Loop through each chunk section and fast-decay a random block //Apply the changes using the world object instead of directly to the chunk so that clients are always notified. for (sectionY = 0; sectionY < limboHeight; sectionY += SECTION_HEIGHT) { - BlockPos pos = new BlockPos(chunkPos.x * CHUNK_SIZE + random.nextInt(CHUNK_SIZE), - chunkPos.z * CHUNK_SIZE + random.nextInt(CHUNK_SIZE), - sectionY + random.nextInt(SECTION_HEIGHT)); + BlockPos pos = new BlockPos( + chunkPos.x * CHUNK_SIZE + random.nextInt(CHUNK_SIZE), + chunkPos.z * CHUNK_SIZE + random.nextInt(CHUNK_SIZE), + sectionY + random.nextInt(SECTION_HEIGHT)); decayBlockFast(world, pos); } } @@ -122,7 +122,11 @@ public final class LimboDecay { private static boolean decayBlockFast(World world, BlockPos pos) { IBlockState block = world.getBlockState(pos); if (canDecayBlock(block, world, pos)) { - world.setBlockState(pos, ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.UNRAVELED)); + if (block.isNormalCube()) { + world.setBlockState(pos, ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.UNRAVELED)); + } else { + world.setBlockState(pos, Blocks.AIR.getDefaultState()); + } return true; } return false; @@ -137,19 +141,23 @@ public final class LimboDecay { if (canDecayBlock(block, world, pos)) { //Loop over the block IDs that decay can go through. //Find an index matching the current blockID, if any. - for (index = 0; index < getDecaySequence().length; index++) { - if (getDecaySequence()[index].equals(block)) { - break; + if (block.isNormalCube()) { + for (index = 0; index < getDecaySequence().length; index++) { + if (getDecaySequence()[index].equals(block)) { + break; + } } + + //Since the decay sequence is a reversed list, the block ID in the index before our match + //is the block ID we should change this block into. A trick in this approach is that if + //we loop over the array without finding a match, then (index - 1) will contain the + //last ID in the array, which is the first one that all blocks decay into. + //We assume that Unraveled Fabric is NOT decayable. Otherwise, this will go out of bounds! + + world.setBlockState(pos, getDecaySequence()[index - 1]); + } else { + world.setBlockState(pos, Blocks.AIR.getDefaultState()); } - - //Since the decay sequence is a reversed list, the block ID in the index before our match - //is the block ID we should change this block into. A trick in this approach is that if - //we loop over the array without finding a match, then (index - 1) will contain the - //last ID in the array, which is the first one that all blocks decay into. - //We assume that Unraveled Fabric is NOT decayable. Otherwise, this will go out of bounds! - - world.setBlockState(pos, getDecaySequence()[index - 1]); return true; } return false; @@ -159,7 +167,7 @@ public final class LimboDecay { * Checks if a block can decay. We will not decay air, certain DD blocks, or containers. */ private static boolean canDecayBlock(IBlockState block, World world, BlockPos pos) { - if (world.isAirBlock(pos )) { + if (world.isAirBlock(pos)) { return false; }