Skip to content

Commit

Permalink
Fix hidebehind suffocating in logs/trees (Fixes #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeow committed Apr 4, 2021
1 parent b05bae0 commit c60efc4
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.itsmeow.whisperwoods.init.ModEntities;
import dev.itsmeow.whisperwoods.init.ModSounds;
import dev.itsmeow.whisperwoods.util.IOverrideCollisions;
import net.minecraft.block.BlockState;
import net.minecraft.block.TorchBlock;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.*;
Expand Down Expand Up @@ -295,6 +296,29 @@ public boolean attackEntityAsMob(Entity entity) {
return flag;
}

@Override
public boolean isEntityInsideOpaqueBlock() {
if (this.noClip) {
return false;
} else {
try (BlockPos.PooledMutable blockpos$pooledmutable = BlockPos.PooledMutable.retain()) {
for(int i = 0; i < 8; ++i) {
int j = MathHelper.floor(this.getPosY() + (double)(((float)((i >> 0) % 2) - 0.5F) * 0.1F) + (double)this.getEyeHeight());
int k = MathHelper.floor(this.getPosX() + (double)(((float)((i >> 1) % 2) - 0.5F) * this.getWidth() * 0.8F));
int l = MathHelper.floor(this.getPosZ() + (double)(((float)((i >> 2) % 2) - 0.5F) * this.getWidth() * 0.8F));
if (blockpos$pooledmutable.getX() != k || blockpos$pooledmutable.getY() != j || blockpos$pooledmutable.getZ() != l) {
blockpos$pooledmutable.setPos(k, j, l);
BlockState state = this.world.getBlockState(blockpos$pooledmutable);
if (state.isSuffocating(this.world, blockpos$pooledmutable) && !state.getBlock().isIn(BlockTags.LOGS)) {
return true;
}
}
}
return false;
}
}
}

@Override
public Vec3d getAllowedMovement(Vec3d vec) {
return allowedMove(vec);
Expand Down

0 comments on commit c60efc4

Please sign in to comment.