Skip to content

Commit 474784c

Browse files
committed
refactor: clear unnecessary hitbox code
1 parent e94efdd commit 474784c

File tree

24 files changed

+59
-217
lines changed

24 files changed

+59
-217
lines changed

api/src/main/java/kr/toxicity/model/api/bone/RenderedBone.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public boolean createHitBox(@NotNull BaseEntity entity, @NotNull Predicate<Rende
203203
synchronized (this) {
204204
if (previous != hitBox) return false;
205205
var h = group.getHitBox();
206-
if (h == null) h = ModelBoundingBox.MIN.named(name());
206+
if (h == null) h = ModelBoundingBox.MIN;
207207
var l = eventDispatcher.onCreateHitBox(this, (listener != null ? listener : HitBoxListener.EMPTY).toBuilder()).build();
208208
if (hitBox != null) hitBox.removeHitBox();
209209
hitBox = BetterModel.nms().createHitBox(entity, this, h, group.getMountController(), l);

api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintElement.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public float scale() {
221221
* @return the named bounding box, or null if no cubes are present
222222
* @since 1.15.2
223223
*/
224-
public @Nullable NamedBoundingBox hitBox() {
224+
public @Nullable ModelBoundingBox hitBox() {
225225
return filterIsInstance(children, Cube.class).map(element -> {
226226
var from = element.from()
227227
.minus(origin)
@@ -238,7 +238,6 @@ public float scale() {
238238
to.z()
239239
).invert();
240240
}).max(Comparator.comparingDouble(ModelBoundingBox::length))
241-
.map(max -> new NamedBoundingBox(name, max))
242241
.orElse(null);
243242
}
244243
}

api/src/main/java/kr/toxicity/model/api/data/blueprint/ModelBoundingBox.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
*/
77
package kr.toxicity.model.api.data.blueprint;
88

9-
import kr.toxicity.model.api.bone.BoneName;
109
import org.jetbrains.annotations.NotNull;
1110
import org.joml.Quaterniond;
1211
import org.joml.Vector3d;
12+
import org.joml.Vector3f;
1313

1414
/**
1515
* Represents an axis-aligned bounding box (AABB) for a model part.
@@ -111,17 +111,6 @@ public record ModelBoundingBox(
111111
);
112112
}
113113

114-
/**
115-
* Associates this bounding box with a bone name.
116-
*
117-
* @param name the bone name
118-
* @return a {@link NamedBoundingBox} wrapping this box
119-
* @since 1.15.2
120-
*/
121-
public @NotNull NamedBoundingBox named(@NotNull BoneName name) {
122-
return new NamedBoundingBox(name, this);
123-
}
124-
125114
/**
126115
* Returns the width of the bounding box (X-axis extent).
127116
*
@@ -168,12 +157,12 @@ public double z() {
168157
* @return the center vector
169158
* @since 1.15.2
170159
*/
171-
public @NotNull Vector3d centerPoint() {
172-
return new Vector3d(
173-
minX + maxX,
174-
minY + maxY,
175-
minZ + maxZ
176-
).div(2D);
160+
public @NotNull Vector3f centerPoint() {
161+
return new Vector3f(
162+
(float) (minX + maxX),
163+
(float) (minY + maxY),
164+
(float) (minZ + maxZ)
165+
).div(2F);
177166
}
178167

179168
/**

api/src/main/java/kr/toxicity/model/api/data/blueprint/NamedBoundingBox.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

api/src/main/java/kr/toxicity/model/api/data/renderer/RendererGroup.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import kr.toxicity.model.api.BetterModel;
1010
import kr.toxicity.model.api.bone.*;
1111
import kr.toxicity.model.api.data.blueprint.BlueprintElement;
12-
import kr.toxicity.model.api.data.blueprint.NamedBoundingBox;
12+
import kr.toxicity.model.api.data.blueprint.ModelBoundingBox;
1313
import kr.toxicity.model.api.mount.MountController;
1414
import kr.toxicity.model.api.mount.MountControllers;
1515
import kr.toxicity.model.api.util.MathUtil;
@@ -46,7 +46,7 @@ public final class RendererGroup {
4646
@Unmodifiable
4747
private final Map<BoneName, RendererGroup> children;
4848
@Getter
49-
private final @Nullable NamedBoundingBox hitBox;
49+
private final @Nullable ModelBoundingBox hitBox;
5050

5151
@Getter
5252
private final @NotNull BoneItemMapper itemMapper;
@@ -67,7 +67,7 @@ public RendererGroup(
6767
@Nullable ItemStack itemStack,
6868
@NotNull BlueprintElement.Bone group,
6969
@NotNull Map<BoneName, RendererGroup> children,
70-
@Nullable NamedBoundingBox box
70+
@Nullable ModelBoundingBox box
7171
) {
7272
this.parent = group;
7373
this.children = children;

api/src/main/java/kr/toxicity/model/api/nms/HitBox.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public interface HitBox extends Identifiable {
7777
* @return the group name
7878
* @since 1.15.2
7979
*/
80-
@NotNull BoneName groupName();
80+
default @NotNull BoneName groupName() {
81+
return positionSource().name();
82+
}
8183

8284
/**
8385
* Returns the mount controller for this hitbox.

api/src/main/java/kr/toxicity/model/api/nms/NMS.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import kr.toxicity.model.api.BetterModel;
1010
import kr.toxicity.model.api.bone.RenderedBone;
11-
import kr.toxicity.model.api.data.blueprint.NamedBoundingBox;
11+
import kr.toxicity.model.api.data.blueprint.ModelBoundingBox;
1212
import kr.toxicity.model.api.entity.BaseBukkitEntity;
1313
import kr.toxicity.model.api.entity.BaseBukkitPlayer;
1414
import kr.toxicity.model.api.entity.BaseEntity;
@@ -184,13 +184,13 @@ default void hide(@NotNull PlayerChannelHandler channel, @NotNull EntityTrackerR
184184
*
185185
* @param entity the target entity
186186
* @param bone the bone associated with the hitbox
187-
* @param namedBoundingBox the bounding box definition
187+
* @param boundingBox the bounding box definition
188188
* @param controller the mount controller
189189
* @param listener the hitbox listener
190190
* @return the created hitbox, or null if creation failed
191191
* @since 1.15.2
192192
*/
193-
@Nullable HitBox createHitBox(@NotNull BaseEntity entity, @NotNull RenderedBone bone, @NotNull NamedBoundingBox namedBoundingBox, @NotNull MountController controller, @NotNull HitBoxListener listener);
193+
@Nullable HitBox createHitBox(@NotNull BaseEntity entity, @NotNull RenderedBone bone, @NotNull ModelBoundingBox boundingBox, @NotNull MountController controller, @NotNull HitBoxListener listener);
194194

195195
/**
196196
* Returns the NMS version of the server.

api/src/main/java/kr/toxicity/model/api/tracker/EntityTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public EntityTracker(@NotNull EntityTrackerRegistry registry, @NotNull RenderPip
9696
var shadow = BetterModel.nms().create(entity.location(), d -> {
9797
if (entity instanceof BasePlayer) d.moveDuration(1);
9898
});
99-
var baseScale = (float) (box.box().x() + box.box().z()) / 4F;
99+
var baseScale = (float) (box.x() + box.z()) / 4F;
100100
tick(((t, s) -> {
101101
var wPos = bone.hitBoxPosition();
102102
shadow.shadowRadius(scale.getAsFloat() * baseScale);

nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/HitBoxImpl.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package kr.toxicity.model.nms.v1_20_R4
88

99
import io.papermc.paper.event.entity.EntityKnockbackEvent
1010
import kr.toxicity.model.api.BetterModel
11-
import kr.toxicity.model.api.bone.BoneName
1211
import kr.toxicity.model.api.bone.RenderedBone
1312
import kr.toxicity.model.api.config.DebugConfig
1413
import kr.toxicity.model.api.data.blueprint.ModelBoundingBox
@@ -19,7 +18,6 @@ import kr.toxicity.model.api.mount.MountController
1918
import kr.toxicity.model.api.nms.HitBox
2019
import kr.toxicity.model.api.nms.HitBoxListener
2120
import kr.toxicity.model.api.nms.ModelInteractionHand
22-
import kr.toxicity.model.api.util.FunctionUtil
2321
import net.minecraft.core.BlockPos
2422
import net.minecraft.network.protocol.game.ServerboundInteractPacket
2523
import net.minecraft.server.level.ServerPlayer
@@ -47,13 +45,10 @@ import org.bukkit.craftbukkit.entity.CraftPlayer
4745
import org.bukkit.event.entity.CreatureSpawnEvent
4846
import org.bukkit.event.entity.EntityPotionEffectEvent
4947
import org.bukkit.util.Vector
50-
import org.joml.Quaterniond
5148
import org.joml.Vector3f
5249
import java.util.*
53-
import java.util.function.Supplier
5450

5551
internal class HitBoxImpl(
56-
private val name: BoneName,
5752
private val source: ModelBoundingBox,
5853
private val bone: RenderedBone,
5954
private val listener: HitBoxListener,
@@ -71,11 +66,7 @@ internal class HitBoxImpl(
7166
val craftEntity: HitBox by lazy {
7267
object : CraftArmorStand(Bukkit.getServer() as CraftServer, this), HitBox by this {}
7368
}
74-
private val _rotatedSource = FunctionUtil.throttleTick(Supplier {
75-
source.rotate(Quaterniond(bone.hitBoxViewRotation()))
76-
})
77-
private val rotatedSource get() = _rotatedSource.get()
78-
val dimensions: EntityDimensions get() = rotatedSource.run {
69+
val dimensions: EntityDimensions get() = source.run {
7970
EntityDimensions(
8071
(x() + z()).toFloat() / 2,
8172
y().toFloat(),
@@ -110,7 +101,6 @@ internal class HitBoxImpl(
110101
}
111102
}
112103

113-
override fun groupName(): BoneName = name
114104
override fun id(): Int = id
115105
override fun uuid(): UUID = uuid
116106
override fun source(): org.bukkit.entity.Entity = delegate.bukkitEntity
@@ -290,7 +280,7 @@ internal class HitBoxImpl(
290280
yHeadRot = yRot
291281
yBodyRot = yRot
292282
val pos = relativePosition()
293-
val minusHeight = rotatedSource.minY * bone.hitBoxScale()
283+
val minusHeight = source.minY * bone.hitBoxScale()
294284
setPos(
295285
pos.x.toDouble(),
296286
pos.y.toDouble() + minusHeight,
@@ -420,7 +410,6 @@ internal class HitBoxImpl(
420410
} else {
421411
val vec3 = position()
422412
val scale = bone.hitBoxScale()
423-
val source = rotatedSource
424413
AABB(
425414
vec3.x + source.minX * scale,
426415
vec3.y,

nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/NMSImpl.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import io.netty.channel.ChannelPromise
1414
import io.papermc.paper.chunk.system.entity.EntityLookup
1515
import kr.toxicity.model.api.BetterModel
1616
import kr.toxicity.model.api.bone.RenderedBone
17-
import kr.toxicity.model.api.data.blueprint.NamedBoundingBox
17+
import kr.toxicity.model.api.data.blueprint.ModelBoundingBox
1818
import kr.toxicity.model.api.entity.BaseBukkitEntity
1919
import kr.toxicity.model.api.entity.BaseBukkitPlayer
2020
import kr.toxicity.model.api.entity.BaseEntity
@@ -334,12 +334,10 @@ class NMSImpl : NMS {
334334
}
335335
}
336336

337-
override fun createHitBox(entity: BaseEntity, bone: RenderedBone, namedBoundingBox: NamedBoundingBox, mountController: MountController, listener: HitBoxListener): HitBox? {
337+
override fun createHitBox(entity: BaseEntity, bone: RenderedBone, boundingBox: ModelBoundingBox, mountController: MountController, listener: HitBoxListener): HitBox? {
338338
val handle = entity.handle() as? Entity ?: return null
339-
val newBox = namedBoundingBox.center()
340339
return HitBoxImpl(
341-
namedBoundingBox.name,
342-
newBox,
340+
boundingBox.center(),
343341
bone,
344342
listener,
345343
handle,

0 commit comments

Comments
 (0)