Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,19 +12,21 @@ private Hitbox() {

public static boolean setCustomHitbox(Entity entity, float width, float height, boolean fixed) {
EntityDimensions entityDimensions = new EntityDimensions(width, height, height, null, fixed);
AABB boundingBox = entityDimensions.makeBoundingBox(entity.position());

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;
} catch (IllegalAccessException e) {
e.printStackTrace();
return false;
}
entity.setBoundingBox(entityDimensions.makeBoundingBox(entity.position()));
entity.setBoundingBox(boundingBox);
return true;
}
}