Skip to content

Commit

Permalink
fix: patch out line of sight checks
Browse files Browse the repository at this point in the history
Fixes #1072
  • Loading branch information
klikli-dev committed Mar 14, 2024
1 parent 8729a3b commit ec4952f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ public void tick() {

public boolean canSeeTarget() {

ClipContext context = new ClipContext(this.entity.position(),
Math3DUtil.center(this.targetBlock), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE,
this.entity);
BlockHitResult result = this.entity.level().clip(context);

if (result.getType() != BlockHitResult.Type.MISS) {
BlockPos sidePos = result.getBlockPos();
BlockPos pos = BlockPos.containing(result.getLocation());
return this.entity.level().isEmptyBlock(sidePos) || this.entity.level().isEmptyBlock(pos) ||
this.entity.level().getBlockEntity(pos) == this.entity.level().getBlockEntity(this.targetBlock);
}
// ClipContext context = new ClipContext(this.entity.position(),
// Math3DUtil.center(this.targetBlock), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE,
// this.entity);
// BlockHitResult result = this.entity.level().clip(context);
//
// if (result.getType() != BlockHitResult.Type.MISS) {
// BlockPos sidePos = result.getBlockPos();
// BlockPos pos = BlockPos.containing(result.getLocation());
// return this.entity.level().isEmptyBlock(sidePos) || this.entity.level().isEmptyBlock(pos) ||
// this.entity.level().getBlockEntity(pos) == this.entity.level().getBlockEntity(this.targetBlock);
// }

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ public void tick() {
}

public boolean canSeeTarget() {
BlockState targetBlockState = this.entity.level().getBlockState(this.targetBlock);
ClipContext context = new ClipContext(this.entity.getEyePosition(0),
Math3DUtil.center(this.targetBlock), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE,
this.entity);
BlockHitResult rayTrace = this.entity.level().clip(context);

if (rayTrace.getType() != BlockHitResult.Type.MISS) {
BlockPos sidePos = rayTrace.getBlockPos();
BlockPos pos = BlockPos.containing(rayTrace.getLocation());
return this.entity.level().isEmptyBlock(sidePos) || this.entity.level().isEmptyBlock(pos) ||
this.entity.level().getBlockEntity(pos) == this.entity.level().getBlockEntity(this.targetBlock);
}
// BlockState targetBlockState = this.entity.level().getBlockState(this.targetBlock);
// ClipContext context = new ClipContext(this.entity.getEyePosition(0),
// Math3DUtil.center(this.targetBlock), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE,
// this.entity);
// BlockHitResult rayTrace = this.entity.level().clip(context);
//
// if (rayTrace.getType() != BlockHitResult.Type.MISS) {
// BlockPos sidePos = rayTrace.getBlockPos();
// BlockPos pos = BlockPos.containing(rayTrace.getLocation());
// return this.entity.level().isEmptyBlock(sidePos) || this.entity.level().isEmptyBlock(pos) ||
// this.entity.level().getBlockEntity(pos) == this.entity.level().getBlockEntity(this.targetBlock);
// }

return true;
}
Expand Down

0 comments on commit ec4952f

Please sign in to comment.