From 2419989e218328fa2d3c297e7dfcbba4aa56bce4 Mon Sep 17 00:00:00 2001 From: Mitchell Gertrude Date: Thu, 11 Jul 2024 12:58:57 +1000 Subject: [PATCH 1/2] Update v1_21_R1 Hitbox Fixed vR1_21_R1 hitbox to set entity's hitbox field to class AABB instead of EntityDimensions --- .../v1_21_R1/hitbox/Hitbox.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/EasyMinecraftGoals/v1_21_R1/src/main/java/com/magmaguy/easyminecraftgoals/v1_21_R1/hitbox/Hitbox.java b/EasyMinecraftGoals/v1_21_R1/src/main/java/com/magmaguy/easyminecraftgoals/v1_21_R1/hitbox/Hitbox.java index fa1ef93..20976f8 100644 --- a/EasyMinecraftGoals/v1_21_R1/src/main/java/com/magmaguy/easyminecraftgoals/v1_21_R1/hitbox/Hitbox.java +++ b/EasyMinecraftGoals/v1_21_R1/src/main/java/com/magmaguy/easyminecraftgoals/v1_21_R1/hitbox/Hitbox.java @@ -2,6 +2,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.phys.AABB; import java.lang.reflect.Field; @@ -11,11 +12,25 @@ private Hitbox() { public static boolean setCustomHitbox(Entity entity, float width, float height, boolean fixed) { EntityDimensions entityDimensions = new EntityDimensions(width, height, height, null, fixed); + + double x = entity.getX(); + double y = entity.getY(); + double z = entity.getZ(); + + // Calculate the half dimensions + double halfWidth = entityDimensions.width() / 2.0; + double dHeight = entityDimensions.height(); + + AABB boundingBox = new AABB( + x - halfWidth, y, z - halfWidth, // min corner + x + halfWidth, y + dHeight, z + halfWidth // max corner + ); + Class entityClass = Entity.class; try { Field field = entityClass.getDeclaredField("aF"); field.setAccessible(true); - field.set(entity, entityDimensions); + field.set(entity, boundingBox); } catch (NoSuchFieldException e) { e.printStackTrace(); return false; From fbc2d93b379b248cd2bc15c7d1f7eadf16b29905 Mon Sep 17 00:00:00 2001 From: Mitchell Gertrude Date: Thu, 11 Jul 2024 13:03:02 +1000 Subject: [PATCH 2/2] Update v1_21_R1 Hitbox Fixed vR1_21_R1 hitbox to set entity's hitbox field to class AABB instead of EntityDimensions --- .../v1_21_R1/hitbox/Hitbox.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/EasyMinecraftGoals/v1_21_R1/src/main/java/com/magmaguy/easyminecraftgoals/v1_21_R1/hitbox/Hitbox.java b/EasyMinecraftGoals/v1_21_R1/src/main/java/com/magmaguy/easyminecraftgoals/v1_21_R1/hitbox/Hitbox.java index 20976f8..ee32edb 100644 --- a/EasyMinecraftGoals/v1_21_R1/src/main/java/com/magmaguy/easyminecraftgoals/v1_21_R1/hitbox/Hitbox.java +++ b/EasyMinecraftGoals/v1_21_R1/src/main/java/com/magmaguy/easyminecraftgoals/v1_21_R1/hitbox/Hitbox.java @@ -12,19 +12,7 @@ private Hitbox() { public static boolean setCustomHitbox(Entity entity, float width, float height, boolean fixed) { EntityDimensions entityDimensions = new EntityDimensions(width, height, height, null, fixed); - - double x = entity.getX(); - double y = entity.getY(); - double z = entity.getZ(); - - // Calculate the half dimensions - double halfWidth = entityDimensions.width() / 2.0; - double dHeight = entityDimensions.height(); - - AABB boundingBox = new AABB( - x - halfWidth, y, z - halfWidth, // min corner - x + halfWidth, y + dHeight, z + halfWidth // max corner - ); + AABB boundingBox = entityDimensions.makeBoundingBox(entity.position()); Class entityClass = Entity.class; try { @@ -38,7 +26,7 @@ public static boolean setCustomHitbox(Entity entity, float width, float height, e.printStackTrace(); return false; } - entity.setBoundingBox(entityDimensions.makeBoundingBox(entity.position())); + entity.setBoundingBox(boundingBox); return true; } }