1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-24 02:17:39 +00:00

Limit turtle's reach distance in Item.use

When a turtle attempts to place a block, it does so by searching for
nearby blocks and attempting to place the item against that block.

This has slightly strange behaviour when working with "placable"
non-block items though (such as buckets or boats). In this case, we call
Item.use, which doesn't take in the position of the block we're placing
against. Instead these items do their own ray trace, using the default
reach distance.

If the block we're trying to place against is non-solid, the ray trace
will go straight through it and continue (up to the maximum of 5
blocks), allowing placing the item much further away.

Our fix here is to override the default reach distance of our fake
players, limiting it to 2. This is easy on Forge (it has built-in
support), and requires a mixin on Fabric.

Closes #1497.
This commit is contained in:
Jonathan Coates
2023-06-24 17:09:34 +01:00
parent c3bdb0440e
commit 672c2cf029
7 changed files with 245 additions and 2 deletions

View File

@@ -16,6 +16,8 @@ import net.minecraftforge.common.util.FakePlayer;
import javax.annotation.Nullable;
import java.util.OptionalInt;
import static dan200.computercraft.shared.platform.FakePlayerConstants.MAX_REACH;
class FakePlayerExt extends FakePlayer {
FakePlayerExt(ServerLevel serverLevel, GameProfile profile) {
super(serverLevel, profile);
@@ -45,4 +47,14 @@ class FakePlayerExt extends FakePlayer {
public float getStandingEyeHeight(Pose pose, EntityDimensions dimensions) {
return 0;
}
@Override
public double getBlockReach() {
return MAX_REACH;
}
@Override
public double getEntityReach() {
return MAX_REACH;
}
}