Skip to content

Commit

Permalink
Fix destruction behind permeable blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Theta-Dev committed Oct 22, 2021
1 parent c60260e commit bb48292
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/thetadev/constructionwand/basics/WandUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ public static boolean isBlockRemovable(Level world, Player player, BlockPos pos)
return true;
}

public static boolean isBlockPermeable(Level world, BlockPos pos) {
return world.isEmptyBlock(pos) || world.getBlockState(pos).getCollisionShape(world, pos).isEmpty();
}

public static boolean entitiesCollidingWithBlock(Level world, BlockState blockState, BlockPos pos) {
VoxelShape shape = blockState.getCollisionShape(world, pos);
if(!shape.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import thetadev.constructionwand.api.IWandAction;
import thetadev.constructionwand.api.IWandSupplier;
import thetadev.constructionwand.basics.ConfigServer;
import thetadev.constructionwand.basics.WandUtil;
import thetadev.constructionwand.basics.option.WandOptions;
import thetadev.constructionwand.wand.undo.DestroySnapshot;
import thetadev.constructionwand.wand.undo.ISnapshot;
Expand Down Expand Up @@ -57,8 +58,8 @@ else if(options.testLock(WandOptions.LOCK.HORIZONTAL) || options.testLock(WandOp
while(!candidates.isEmpty() && destroySnapshots.size() < limit) {
BlockPos currentCandidate = candidates.removeFirst();

// Only break blocks facing the player, with no blocks in between
if(!world.isEmptyBlock(currentCandidate.offset(breakFace.getNormal()))) continue;
// Only break blocks facing the player, with no collidable blocks in between
if(!WandUtil.isBlockPermeable(world, currentCandidate.offset(breakFace.getNormal()))) continue;

try {
BlockState candidateBlock = world.getBlockState(currentCandidate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void getSupply(@Nullable BlockItem target) {
addBlockItem((BlockItem) offhandStack.getItem());
}
// Otherwise use target block
else {
else if(target != null && target != Items.AIR) {
addBlockItem(target);

// Add replacement items
Expand Down

0 comments on commit bb48292

Please sign in to comment.