Skip to content

Commit

Permalink
Refactor HitboxData.getBlockHitbox() to include isTargetBlock as para…
Browse files Browse the repository at this point in the history
…meter

Also fixes a rare NPE
  • Loading branch information
Axionize committed Jan 20, 2025
1 parent 75bcac7 commit ee36c25
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected boolean shouldCancel() {
protected SimpleCollisionBox getCombinedBox(final BlockPlace place) {
// Alright, instead of skidding AACAdditionsPro, let's just use bounding boxes
Vector3i clicked = place.getPlacedAgainstBlockLocation();
CollisionBox placedOn = HitboxData.getBlockHitbox(player, place.getMaterial(), player.getClientVersion(), player.compensatedWorld.getWrappedBlockStateAt(clicked), clicked.getX(), clicked.getY(), clicked.getZ());
CollisionBox placedOn = HitboxData.getBlockHitbox(player, place.getMaterial(), player.getClientVersion(), player.compensatedWorld.getWrappedBlockStateAt(clicked), true, clicked.getX(), clicked.getY(), clicked.getZ());

int size = placedOn.downCast(boxes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ private static HitData getNearestHitResult(GrimPlayer player, StateType heldItem
return null;
}

CollisionBox data = HitboxData.getBlockHitbox(player, heldItem, player.getClientVersion(), block, vector3i.getX(), vector3i.getY(), vector3i.getZ());
CollisionBox data = HitboxData.getBlockHitbox(player, heldItem, player.getClientVersion(), block, false, vector3i.getX(), vector3i.getY(), vector3i.getZ());
List<SimpleCollisionBox> boxes = new ArrayList<>();
data.downCast(boxes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void cancel() {
}

public SimpleCollisionBox getCombinedBox() {
CollisionBox placedOn = HitboxData.getBlockHitbox(player, player.getInventory().getHeldItem().getType().getPlacedType(), player.getClientVersion(), block, position.x, position.y, position.z);
CollisionBox placedOn = HitboxData.getBlockHitbox(player, player.getInventory().getHeldItem().getType().getPlacedType(), player.getClientVersion(), block, true, position.x, position.y, position.z);

List<SimpleCollisionBox> boxes = new ArrayList<>();
placedOn.downCast(boxes);
Expand Down
95 changes: 51 additions & 44 deletions src/main/java/ac/grim/grimac/utils/collisions/HitboxData.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DynamicHitboxFence extends DynamicConnecting implements HitBoxFacto
}

@Override
public CollisionBox fetch(GrimPlayer player, StateType heldItem, ClientVersion version, WrappedBlockState block, int x, int y, int z) {
public CollisionBox fetch(GrimPlayer player, StateType heldItem, ClientVersion version, WrappedBlockState block, boolean isTargetBlock, int x, int y, int z) {
boolean east;
boolean north;
boolean south;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DynamicHitboxPane extends DynamicConnecting implements HitBoxFactor
private static final CollisionBox[] COLLISION_BOXES = makeShapes(1.0F, 1.0F, 16.0F, 0.0F, 16.0F, true, 1);

@Override
public CollisionBox fetch(GrimPlayer player, StateType item, ClientVersion version, WrappedBlockState block, int x, int y, int z) {
public CollisionBox fetch(GrimPlayer player, StateType item, ClientVersion version, WrappedBlockState block, boolean isTargetBlock, int x, int y, int z) {
boolean east, north, south, west;

// 1.13+ servers on 1.13+ clients send the full fence data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DynamicHitboxWall extends DynamicConnecting implements HitBoxFactory {
@Override
public CollisionBox fetch(GrimPlayer player, StateType heldItem, ClientVersion version, WrappedBlockState state, int x, int y, int z) {
public CollisionBox fetch(GrimPlayer player, StateType heldItem, ClientVersion version, WrappedBlockState state, boolean isTargetBlock, int x, int y, int z) {
int[] connections = getConnections(player, version, state, x, y, z);
int north = connections[0], south = connections[1], west = connections[2], east = connections[3], up = connections[4];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;

public interface HitBoxFactory {
CollisionBox fetch(GrimPlayer player, StateType heldItem, ClientVersion version, WrappedBlockState block, int x, int y, int z);
CollisionBox fetch(GrimPlayer player, StateType heldItem, ClientVersion version, WrappedBlockState block, boolean isTargetBlock, int x, int y, int z);
}

0 comments on commit ee36c25

Please sign in to comment.