diff --git a/gradle.properties b/gradle.properties index 62cae8e..c1e5cf3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,4 +11,4 @@ mcp_mappings=20200514-1.15.1 botania=r1.15-387.455 version_major=2 -version_minor=1 \ No newline at end of file +version_minor=4 \ No newline at end of file diff --git a/src/main/java/thetadev/constructionwand/basics/WandUtil.java b/src/main/java/thetadev/constructionwand/basics/WandUtil.java index 6ae07a6..78ab4d4 100644 --- a/src/main/java/thetadev/constructionwand/basics/WandUtil.java +++ b/src/main/java/thetadev/constructionwand/basics/WandUtil.java @@ -9,6 +9,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.stats.Stats; import net.minecraft.util.Direction; import net.minecraft.util.EntityPredicates; @@ -16,6 +17,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.World; @@ -26,6 +28,7 @@ import thetadev.constructionwand.ConstructionWand; import thetadev.constructionwand.basics.option.WandOptions; import thetadev.constructionwand.containers.ContainerManager; import thetadev.constructionwand.items.wand.ItemWand; +import thetadev.constructionwand.wand.WandItemUseContext; import javax.annotation.Nullable; import java.util.ArrayList; @@ -200,13 +203,19 @@ public class WandUtil /** * Tests if a wand can place a block at a certain position. - * This check is independent from the used block. + * This check is independent of the used block. */ public static boolean isPositionPlaceable(World world, PlayerEntity player, BlockPos pos, boolean replace) { if(!isPositionModifiable(world, player, pos)) return false; // If replace mode is off, target has to be air - return replace || world.isAirBlock(pos); + if(world.isAirBlock(pos)) return true; + + // Otherwise, check if the block can be replaced by a generic block + return replace && world.getBlockState(pos).isReplaceable( + new WandItemUseContext(world, player, + new BlockRayTraceResult(new Vec3d(0, 0, 0), Direction.DOWN, pos, false), + pos, (BlockItem) Items.STONE)); } public static boolean isBlockRemovable(World world, PlayerEntity player, BlockPos pos) { @@ -218,6 +227,10 @@ public class WandUtil return true; } + public static boolean isBlockPermeable(World world, BlockPos pos) { + return world.isAirBlock(pos) || world.getBlockState(pos).getCollisionShape(world, pos).isEmpty(); + } + public static boolean entitiesCollidingWithBlock(World world, BlockState blockState, BlockPos pos) { VoxelShape shape = blockState.getCollisionShape(world, pos); if(!shape.isEmpty()) { diff --git a/src/main/java/thetadev/constructionwand/wand/action/ActionDestruction.java b/src/main/java/thetadev/constructionwand/wand/action/ActionDestruction.java index 72340fd..5364101 100644 --- a/src/main/java/thetadev/constructionwand/wand/action/ActionDestruction.java +++ b/src/main/java/thetadev/constructionwand/wand/action/ActionDestruction.java @@ -39,14 +39,14 @@ public class ActionDestruction implements IWandAction HashSet allCandidates = new HashSet<>(); // Block face the wand was pointed at - Direction breakDirection = rayTraceResult.getFace(); + Direction breakFace = rayTraceResult.getFace(); // Block the wand was pointed at BlockPos startingPoint = rayTraceResult.getPos(); BlockState targetBlock = world.getBlockState(rayTraceResult.getPos()); // Is break direction allowed by lock? // Tried to break blocks from top/bottom face, so the wand should allow breaking in NS/EW direction - if(breakDirection == Direction.UP || breakDirection == Direction.DOWN) { + if(breakFace == Direction.UP || breakFace == Direction.DOWN) { if(options.testLock(WandOptions.LOCK.NORTHSOUTH) || options.testLock(WandOptions.LOCK.EASTWEST)) candidates.add(startingPoint); } @@ -57,6 +57,10 @@ public class ActionDestruction implements IWandAction // Process current candidates, stop when none are avaiable or block limit is reached while(!candidates.isEmpty() && destroySnapshots.size() < limit) { BlockPos currentCandidate = candidates.removeFirst(); + + // Only break blocks facing the player, with no collidable blocks in between + if(!WandUtil.isBlockPermeable(world, currentCandidate.offset(breakFace))) continue; + try { BlockState candidateBlock = world.getBlockState(currentCandidate); @@ -67,7 +71,7 @@ public class ActionDestruction implements IWandAction if(snapshot == null) continue; destroySnapshots.add(snapshot); - switch(breakDirection) { + switch(breakFace) { case DOWN: case UP: if(options.testLock(WandOptions.LOCK.NORTHSOUTH)) { diff --git a/src/main/java/thetadev/constructionwand/wand/supplier/SupplierInventory.java b/src/main/java/thetadev/constructionwand/wand/supplier/SupplierInventory.java index 19105de..2480d9b 100644 --- a/src/main/java/thetadev/constructionwand/wand/supplier/SupplierInventory.java +++ b/src/main/java/thetadev/constructionwand/wand/supplier/SupplierInventory.java @@ -5,6 +5,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; @@ -51,7 +52,7 @@ public class SupplierInventory implements IWandSupplier addBlockItem((BlockItem) offhandStack.getItem()); } // Otherwise use target block - else { + else if(target != null && target != Items.AIR) { addBlockItem(target); // Add replacement items