Skip to content

Commit

Permalink
Update for HitboxData and CollisionData
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Nov 14, 2024
1 parent 5a6f87f commit 9035180
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 292 deletions.
254 changes: 89 additions & 165 deletions src/main/java/ac/grim/grimac/utils/collisions/CollisionData.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,22 @@ public enum CollisionData {

// Overwrite previous SKULL enum for legacy, where head and wall skull isn't separate
WALL_SKULL((player, version, data, x, y, z) -> {
switch (data.getFacing()) {
default:
case NORTH:
return new SimpleCollisionBox(0.25F, 0.25F, 0.5F, 0.75F, 0.75F, 1.0F, false);
case SOUTH:
return new SimpleCollisionBox(0.25F, 0.25F, 0.0F, 0.75F, 0.75F, 0.5F, false);
case WEST:
return new SimpleCollisionBox(0.5F, 0.25F, 0.25F, 1.0F, 0.75F, 0.75F, false);
case EAST:
return new SimpleCollisionBox(0.0F, 0.25F, 0.25F, 0.5F, 0.75F, 0.75F, false);
}
return switch (data.getFacing()) {
case SOUTH -> new SimpleCollisionBox(0.25F, 0.25F, 0.0F, 0.75F, 0.75F, 0.5F, false);
case WEST -> new SimpleCollisionBox(0.5F, 0.25F, 0.25F, 1.0F, 0.75F, 0.75F, false);
case EAST -> new SimpleCollisionBox(0.0F, 0.25F, 0.25F, 0.5F, 0.75F, 0.75F, false);
default -> new SimpleCollisionBox(0.25F, 0.25F, 0.5F, 0.75F, 0.75F, 1.0F, false);
};
}, StateTypes.CREEPER_WALL_HEAD, StateTypes.DRAGON_WALL_HEAD, StateTypes.PLAYER_WALL_HEAD, StateTypes.ZOMBIE_WALL_HEAD,
StateTypes.SKELETON_WALL_SKULL, StateTypes.WITHER_SKELETON_WALL_SKULL),

PIGLIN_WALL_HEAD((player, version, data, x, y, z) -> {
switch (data.getFacing()) {
default:
case NORTH:
return new HexCollisionBox(3.0D, 4.0D, 8.0D, 13.0D, 12.0D, 16.0D);
case SOUTH:
return new HexCollisionBox(3.0D, 4.0D, 0.0D, 13.0D, 12.0D, 8.0D);
case EAST:
return new HexCollisionBox(0.0D, 4.0D, 3.0D, 8.0D, 12.0D, 13.0D);
case WEST:
return new HexCollisionBox(8.0D, 4.0D, 3.0D, 16.0D, 12.0D, 13.0D);
}
return switch (data.getFacing()) {
case SOUTH -> new HexCollisionBox(3.0D, 4.0D, 0.0D, 13.0D, 12.0D, 8.0D);
case EAST -> new HexCollisionBox(0.0D, 4.0D, 3.0D, 8.0D, 12.0D, 13.0D);
case WEST -> new HexCollisionBox(8.0D, 4.0D, 3.0D, 16.0D, 12.0D, 13.0D);
default -> new HexCollisionBox(3.0D, 4.0D, 8.0D, 13.0D, 12.0D, 16.0D);
};
}, StateTypes.PIGLIN_WALL_HEAD),

DOOR(new DoorHandler(), BlockTags.DOORS.getStates().toArray(new StateType[0])),
Expand Down Expand Up @@ -351,17 +341,12 @@ public enum CollisionData {
if (version.isOlderThanOrEquals(ClientVersion.V_1_8))
width = 2;

switch (data.getFacing()) {
case NORTH:
return new HexCollisionBox(0.0D, 0.0D, 16.0D - width, 16.0D, 16.0D, 16.0D);
case SOUTH:
return new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, width);
case WEST:
return new HexCollisionBox(16.0D - width, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D);
default:
case EAST:
return new HexCollisionBox(0.0D, 0.0D, 0.0D, width, 16.0D, 16.0D);
}
return switch (data.getFacing()) {
case NORTH -> new HexCollisionBox(0.0D, 0.0D, 16.0D - width, 16.0D, 16.0D, 16.0D);
case SOUTH -> new HexCollisionBox(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, width);
case WEST -> new HexCollisionBox(16.0D - width, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D);
default -> new HexCollisionBox(0.0D, 0.0D, 0.0D, width, 16.0D, 16.0D);
};
}, StateTypes.LADDER),

CAMPFIRE((player, version, data, x, y, z) -> {
Expand Down Expand Up @@ -528,18 +513,12 @@ public enum CollisionData {
if (data.isOpen())
return NoCollisionBox.INSTANCE;

switch (data.getFacing()) {
case NORTH:
case SOUTH:
return new SimpleCollisionBox(0.0F, 0.0F, 0.375F, 1.0F, 1.5F, 0.625F, false);
case WEST:
case EAST:
return new SimpleCollisionBox(0.375F, 0.0F, 0.0F, 0.625F, 1.5F, 1.0F, false);
}

// This code is unreachable but the compiler does not know this
return NoCollisionBox.INSTANCE;

return switch (data.getFacing()) {
case NORTH, SOUTH -> new SimpleCollisionBox(0.0F, 0.0F, 0.375F, 1.0F, 1.5F, 0.625F, false);
case WEST, EAST -> new SimpleCollisionBox(0.375F, 0.0F, 0.0F, 0.625F, 1.5F, 1.0F, false);
default -> // This code is unreachable but the compiler does not know this
NoCollisionBox.INSTANCE;
};
}, BlockTags.FENCE_GATES.getStates().toArray(new StateType[0])),

FENCE(new DynamicCollisionFence(), BlockTags.FENCES.getStates().toArray(new StateType[0])),
Expand Down Expand Up @@ -754,32 +733,22 @@ public enum CollisionData {
BlockTags.FLOWER_POTS.getStates().toArray(new StateType[0])),

WALL_SIGN((player, version, data, x, y, z) -> {
switch (data.getFacing()) {
case NORTH:
return new HexCollisionBox(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D);
case SOUTH:
return new HexCollisionBox(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D);
case WEST:
return new HexCollisionBox(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D);
case EAST:
return new HexCollisionBox(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D);
default:
return NoCollisionBox.INSTANCE;
}
return switch (data.getFacing()) {
case NORTH -> new HexCollisionBox(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D);
case SOUTH -> new HexCollisionBox(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D);
case WEST -> new HexCollisionBox(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D);
case EAST -> new HexCollisionBox(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D);
default -> NoCollisionBox.INSTANCE;
};
}, BlockTags.WALL_SIGNS.getStates().toArray(new StateType[0])),

WALL_FAN((player, version, data, x, y, z) -> {
switch (data.getFacing()) {
case NORTH:
return new HexCollisionBox(0.0D, 4.0D, 5.0D, 16.0D, 12.0D, 16.0D);
case SOUTH:
return new HexCollisionBox(0.0D, 4.0D, 0.0D, 16.0D, 12.0D, 11.0D);
case WEST:
return new HexCollisionBox(5.0D, 4.0D, 0.0D, 16.0D, 12.0D, 16.0D);
case EAST:
default:
return new HexCollisionBox(0.0D, 4.0D, 0.0D, 11.0D, 12.0D, 16.0D);
}
return switch (data.getFacing()) {
case NORTH -> new HexCollisionBox(0.0D, 4.0D, 5.0D, 16.0D, 12.0D, 16.0D);
case SOUTH -> new HexCollisionBox(0.0D, 4.0D, 0.0D, 16.0D, 12.0D, 11.0D);
case WEST -> new HexCollisionBox(5.0D, 4.0D, 0.0D, 16.0D, 12.0D, 16.0D);
default -> new HexCollisionBox(0.0D, 4.0D, 0.0D, 11.0D, 12.0D, 16.0D);
};
}, BlockTags.WALL_CORALS.getStates().toArray(new StateType[0])),

CORAL_PLANT((player, version, data, x, y, z) -> {
Expand Down Expand Up @@ -828,53 +797,37 @@ public enum CollisionData {
}, StateTypes.TRIPWIRE),

TRIPWIRE_HOOK((player, version, data, x, y, z) -> {
switch (data.getFacing()) {
case NORTH:
return new HexCollisionBox(5.0D, 0.0D, 10.0D, 11.0D, 10.0D, 16.0D);
case SOUTH:
return new HexCollisionBox(5.0D, 0.0D, 0.0D, 11.0D, 10.0D, 6.0D);
case WEST:
return new HexCollisionBox(10.0D, 0.0D, 5.0D, 16.0D, 10.0D, 11.0D);
case EAST:
default:
return new HexCollisionBox(0.0D, 0.0D, 5.0D, 6.0D, 10.0D, 11.0D);
}
return switch (data.getFacing()) {
case NORTH -> new HexCollisionBox(5.0D, 0.0D, 10.0D, 11.0D, 10.0D, 16.0D);
case SOUTH -> new HexCollisionBox(5.0D, 0.0D, 0.0D, 11.0D, 10.0D, 6.0D);
case WEST -> new HexCollisionBox(10.0D, 0.0D, 5.0D, 16.0D, 10.0D, 11.0D);
default -> new HexCollisionBox(0.0D, 0.0D, 5.0D, 6.0D, 10.0D, 11.0D);
};
}, StateTypes.TRIPWIRE_HOOK),

TORCH(new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D),
StateTypes.TORCH, StateTypes.REDSTONE_TORCH),

WALL_TORCH((player, version, data, x, y, z) -> {
switch (data.getFacing()) {
case NORTH:
return new HexCollisionBox(5.5D, 3.0D, 11.0D, 10.5D, 13.0D, 16.0D);
case SOUTH:
return new HexCollisionBox(5.5D, 3.0D, 0.0D, 10.5D, 13.0D, 5.0D);
case WEST:
return new HexCollisionBox(11.0D, 3.0D, 5.5D, 16.0D, 13.0D, 10.5D);
case EAST:
return new HexCollisionBox(0.0D, 3.0D, 5.5D, 5.0D, 13.0D, 10.5D);
default: // 1.13 separates wall and normal torches, 1.12 does not
case UP:
return new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D);
}

return switch (data.getFacing()) {
case NORTH -> new HexCollisionBox(5.5D, 3.0D, 11.0D, 10.5D, 13.0D, 16.0D);
case SOUTH -> new HexCollisionBox(5.5D, 3.0D, 0.0D, 10.5D, 13.0D, 5.0D);
case WEST -> new HexCollisionBox(11.0D, 3.0D, 5.5D, 16.0D, 13.0D, 10.5D);
case EAST -> new HexCollisionBox(0.0D, 3.0D, 5.5D, 5.0D, 13.0D, 10.5D);
// 1.13 separates wall and normal torches, 1.12 does not
default -> new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D);
};
}, StateTypes.WALL_TORCH, StateTypes.REDSTONE_WALL_TORCH),

// 1.17 blocks
CANDLE((player, version, data, x, y, z) -> {
if (version.isNewerThanOrEquals(ClientVersion.V_1_17)) {
switch (data.getCandles()) {
case 1:
return new HexCollisionBox(7.0, 0.0, 7.0, 9.0, 6.0, 9.0);
case 2:
return new HexCollisionBox(5.0, 0.0, 6.0, 11.0, 6.0, 9.0);
case 3:
return new HexCollisionBox(5.0, 0.0, 6.0, 10.0, 6.0, 11.0);
default:
case 4:
return new HexCollisionBox(5.0, 0.0, 5.0, 11.0, 6.0, 10.0);
}
return switch (data.getCandles()) {
case 1 -> new HexCollisionBox(7.0, 0.0, 7.0, 9.0, 6.0, 9.0);
case 2 -> new HexCollisionBox(5.0, 0.0, 6.0, 11.0, 6.0, 9.0);
case 3 -> new HexCollisionBox(5.0, 0.0, 6.0, 10.0, 6.0, 11.0);
default -> new HexCollisionBox(5.0, 0.0, 5.0, 11.0, 6.0, 10.0);
};
}

return getPicklesBox(version, data.getCandles());
Expand Down Expand Up @@ -992,19 +945,13 @@ public enum CollisionData {
if (!data.isHanging()) {
return new HexCollisionBox(7.0D, 0.0D, 7.0D, 9.0D, 16.0D, 9.0D);
}
switch (data.getAge()) {
case 0:
return new HexCollisionBox(7.0D, 13.0D, 7.0D, 9.0D, 16.0D, 9.0D);
case 1:
return new HexCollisionBox(7.0D, 10.0D, 7.0D, 9.0D, 16.0D, 9.0D);
case 2:
return new HexCollisionBox(7.0D, 7.0D, 7.0D, 9.0D, 16.0D, 9.0D);
case 3:
return new HexCollisionBox(7.0D, 3.0D, 7.0D, 9.0D, 16.0D, 9.0D);
case 4:
default:
return new HexCollisionBox(7.0D, 0.0D, 7.0D, 9.0D, 16.0D, 9.0D);
}
return switch (data.getAge()) {
case 0 -> new HexCollisionBox(7.0D, 13.0D, 7.0D, 9.0D, 16.0D, 9.0D);
case 1 -> new HexCollisionBox(7.0D, 10.0D, 7.0D, 9.0D, 16.0D, 9.0D);
case 2 -> new HexCollisionBox(7.0D, 7.0D, 7.0D, 9.0D, 16.0D, 9.0D);
case 3 -> new HexCollisionBox(7.0D, 3.0D, 7.0D, 9.0D, 16.0D, 9.0D);
default -> new HexCollisionBox(7.0D, 0.0D, 7.0D, 9.0D, 16.0D, 9.0D);
};
}, StateTypes.MANGROVE_PROPAGULE),

SCULK_SHRIKER((player, version, data, x, y, z) -> {
Expand Down Expand Up @@ -1039,16 +986,11 @@ public enum CollisionData {
}, StateTypes.PITCHER_CROP),

WALL_HANGING_SIGNS((player, version, data, x, y, z) -> {
switch (data.getFacing()) {
case NORTH:
case SOUTH:
return new HexCollisionBox(0.0, 14.0, 6.0, 16.0, 16.0, 10.0);
case WEST:
case EAST:
return new HexCollisionBox(6.0, 14.0, 0.0, 10.0, 16.0, 16.0);
default:
return NoCollisionBox.INSTANCE;
}
return switch (data.getFacing()) {
case NORTH, SOUTH -> new HexCollisionBox(0.0, 14.0, 6.0, 16.0, 16.0, 10.0);
case WEST, EAST -> new HexCollisionBox(6.0, 14.0, 0.0, 10.0, 16.0, 16.0);
default -> NoCollisionBox.INSTANCE;
};
}, BlockTags.WALL_HANGING_SIGNS.getStates().toArray(new StateType[0])),

DEFAULT(new SimpleCollisionBox(0, 0, 0, 1, 1, 1, true), StateTypes.STONE);
Expand Down Expand Up @@ -1086,21 +1028,14 @@ private static CollisionBox getAmethystBox(ClientVersion version, com.github.ret
if (version.isOlderThanOrEquals(ClientVersion.V_1_16_4))
return NoCollisionBox.INSTANCE;

switch (facing) {
default:
case UP:
return new HexCollisionBox(param_1, 0.0, param_1, 16 - param_1, param_0, 16 - param_1);
case DOWN:
return new HexCollisionBox(param_1, 16 - param_0, param_1, 16 - param_1, 16.0, 16 - param_1);
case NORTH:
return new HexCollisionBox(param_1, param_1, 16 - param_0, 16 - param_1, 16 - param_1, 16.0);
case SOUTH:
return new HexCollisionBox(param_1, param_1, 0.0, 16 - param_1, 16 - param_1, param_0);
case EAST:
return new HexCollisionBox(0.0, param_1, param_1, param_0, 16 - param_1, 16 - param_1);
case WEST:
return new HexCollisionBox(16 - param_0, param_1, param_1, 16.0, 16 - param_1, 16 - param_1);
}
return switch (facing) {
case DOWN -> new HexCollisionBox(param_1, 16 - param_0, param_1, 16 - param_1, 16.0, 16 - param_1);
case NORTH -> new HexCollisionBox(param_1, param_1, 16 - param_0, 16 - param_1, 16 - param_1, 16.0);
case SOUTH -> new HexCollisionBox(param_1, param_1, 0.0, 16 - param_1, 16 - param_1, param_0);
case EAST -> new HexCollisionBox(0.0, param_1, param_1, param_0, 16 - param_1, 16 - param_1);
case WEST -> new HexCollisionBox(16 - param_0, param_1, param_1, 16.0, 16 - param_1, 16 - param_1);
default -> new HexCollisionBox(param_1, 0.0, param_1, 16 - param_1, param_0, 16 - param_1);
};
}

private static CollisionBox getPicklesBox(ClientVersion version, int pickles) {
Expand All @@ -1109,17 +1044,13 @@ private static CollisionBox getPicklesBox(ClientVersion version, int pickles) {
return getCocoa(version, pickles, BlockFace.WEST);
}

switch (pickles) {
case 1:
return new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 6.0D, 10.0D);
case 2:
return new HexCollisionBox(3.0D, 0.0D, 3.0D, 13.0D, 6.0D, 13.0D);
case 3:
return new HexCollisionBox(2.0D, 0.0D, 2.0D, 14.0D, 6.0D, 14.0D);
case 4:
return new HexCollisionBox(2.0D, 0.0D, 2.0D, 14.0D, 7.0D, 14.0D);
}
return NoCollisionBox.INSTANCE;
return switch (pickles) {
case 1 -> new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 6.0D, 10.0D);
case 2 -> new HexCollisionBox(3.0D, 0.0D, 3.0D, 13.0D, 6.0D, 13.0D);
case 3 -> new HexCollisionBox(2.0D, 0.0D, 2.0D, 14.0D, 6.0D, 14.0D);
case 4 -> new HexCollisionBox(2.0D, 0.0D, 2.0D, 14.0D, 7.0D, 14.0D);
default -> NoCollisionBox.INSTANCE;
};
}

public static CollisionBox getCocoa(ClientVersion version, int age, BlockFace direction) {
Expand Down Expand Up @@ -1174,18 +1105,11 @@ private static CollisionBox getEndRod(ClientVersion version, BlockFace face) {
if (version.isOlderThan(ClientVersion.V_1_9))
return NoCollisionBox.INSTANCE;

switch (face) {
case UP:
case DOWN:
default:
return new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 16.0D, 10.0);
case NORTH:
case SOUTH:
return new HexCollisionBox(6.0D, 6.0D, 0.0D, 10.0D, 10.0D, 16.0D);
case EAST:
case WEST:
return new HexCollisionBox(0.0D, 6.0D, 6.0D, 16.0D, 10.0D, 10.0D);
}
return switch (face) {
case NORTH, SOUTH -> new HexCollisionBox(6.0D, 6.0D, 0.0D, 10.0D, 10.0D, 16.0D);
case EAST, WEST -> new HexCollisionBox(0.0D, 6.0D, 6.0D, 16.0D, 10.0D, 10.0D);
default -> new HexCollisionBox(6.0D, 0.0D, 6.0D, 10.0D, 16.0D, 10.0);
};
}

// Would pre-computing all states be worth the memory cost? I doubt it
Expand Down
Loading

0 comments on commit 9035180

Please sign in to comment.