From 71941c71a3d9399c9b03e42f6c881c0251b9ba2e Mon Sep 17 00:00:00 2001 From: iam4722202468 Date: Sat, 2 Mar 2024 17:35:25 -0500 Subject: [PATCH] implement shape on generic model --- .../net/worldseed/multipart/GenericModel.java | 3 +- .../worldseed/multipart/GenericModelImpl.java | 72 +++++++++++++++++++ .../model_bones/misc/ModelBoneHitbox.java | 2 +- .../demo_models/bulbasaur/BulbasaurMob.java | 3 +- .../gem_golem/GemGolemAttackGoal.java | 5 +- .../demo_models/gem_golem/GemGolemMob.java | 3 +- .../demo_models/tuff_golem/TuffGolemMob.java | 3 +- 7 files changed, 80 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/worldseed/multipart/GenericModel.java b/src/main/java/net/worldseed/multipart/GenericModel.java index 88ad47a..497f925 100644 --- a/src/main/java/net/worldseed/multipart/GenericModel.java +++ b/src/main/java/net/worldseed/multipart/GenericModel.java @@ -1,6 +1,7 @@ package net.worldseed.multipart; import net.minestom.server.Viewable; +import net.minestom.server.collision.Shape; import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Pos; import net.minestom.server.entity.Entity; @@ -15,7 +16,7 @@ import java.util.List; import java.util.Set; -public interface GenericModel extends Viewable, EventHandler { +public interface GenericModel extends Viewable, EventHandler, Shape { /** * Get the ID of the model * @return the model ID diff --git a/src/main/java/net/worldseed/multipart/GenericModelImpl.java b/src/main/java/net/worldseed/multipart/GenericModelImpl.java index aa5adc6..0d08825 100644 --- a/src/main/java/net/worldseed/multipart/GenericModelImpl.java +++ b/src/main/java/net/worldseed/multipart/GenericModelImpl.java @@ -6,6 +6,9 @@ import net.kyori.adventure.audience.Audience; import net.minestom.server.MinecraftServer; import net.minestom.server.ServerProcess; +import net.minestom.server.collision.BoundingBox; +import net.minestom.server.collision.Shape; +import net.minestom.server.collision.SweepResult; import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Pos; import net.minestom.server.coordinate.Vec; @@ -14,6 +17,7 @@ import net.minestom.server.event.EventFilter; import net.minestom.server.event.EventNode; import net.minestom.server.instance.Instance; +import net.minestom.server.instance.block.BlockFace; import net.minestom.server.network.packet.server.SendablePacket; import net.worldseed.gestures.EmoteModel; import net.worldseed.multipart.animations.AnimationHandlerImpl; @@ -27,6 +31,7 @@ import net.worldseed.multipart.model_bones.misc.ModelBoneNametag; import net.worldseed.multipart.model_bones.misc.ModelBoneSeat; import net.worldseed.multipart.model_bones.misc.ModelBoneVFX; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -372,4 +377,71 @@ public boolean removeViewer(@NotNull Player player) { public @NotNull Set<@NotNull Player> getViewers() { return Set.copyOf(this.viewers); } + + // SHAPE IMPL + @Override + public boolean isFaceFull(@NotNull BlockFace face) { + return true; + } + + @Override + public boolean isOccluded(@NotNull Shape shape, @NotNull BlockFace blockFace) { + return false; + } + + @Override + public @NotNull Point relativeStart() { + Pos currentPosition = getPosition(); + Point p = currentPosition; + + for (var bone : this.hittableBones) { + for (var part : bone.getParts()) { + var entity = part.getEntity(); + var absoluteStart = entity.relativeStart().add(entity.getPosition()); + + if (p.x() > absoluteStart.x()) p = p.withX(absoluteStart.x()); + if (p.y() > absoluteStart.y()) p = p.withY(absoluteStart.y()); + if (p.z() > absoluteStart.z()) p = p.withZ(absoluteStart.z()); + } + } + + return p.sub(currentPosition); + } + + @Override + public @NotNull Point relativeEnd() { + Pos currentPosition = getPosition(); + Point p = currentPosition; + + for (var bone : this.hittableBones) { + for (var part : bone.getParts()) { + var entity = part.getEntity(); + var absoluteStart = entity.relativeEnd().add(entity.getPosition()); + + if (p.x() < absoluteStart.x()) p = p.withX(absoluteStart.x()); + if (p.y() < absoluteStart.y()) p = p.withY(absoluteStart.y()); + if (p.z() < absoluteStart.z()) p = p.withZ(absoluteStart.z()); + } + } + + return p.sub(currentPosition); + } + + @Override + public boolean intersectBox(@NotNull Point point, @NotNull BoundingBox boundingBox) { + var pos = getPosition(); + + for (var bone : this.hittableBones) { + for (var part : bone.getParts()) { + if (boundingBox.intersectEntity(point.add(pos), part.getEntity())) return true; + } + } + return false; + } + + @Override + @ApiStatus.Experimental + public boolean intersectBoxSwept(@NotNull Point rayStart, @NotNull Point rayDirection, @NotNull Point shapePos, @NotNull BoundingBox moving, @NotNull SweepResult finalResult) { + throw new UnsupportedOperationException("Not implemented"); + } } \ No newline at end of file diff --git a/src/main/java/net/worldseed/multipart/model_bones/misc/ModelBoneHitbox.java b/src/main/java/net/worldseed/multipart/model_bones/misc/ModelBoneHitbox.java index 4cfb6a8..f98798b 100644 --- a/src/main/java/net/worldseed/multipart/model_bones/misc/ModelBoneHitbox.java +++ b/src/main/java/net/worldseed/multipart/model_bones/misc/ModelBoneHitbox.java @@ -142,7 +142,7 @@ public void setParent(ModelBone parent) { @Override public Point getPosition() { - return this.actualPosition; + return this.actualPosition.add(this.model.getPosition()); } public Collection getParts() { diff --git a/src/test/java/demo_models/bulbasaur/BulbasaurMob.java b/src/test/java/demo_models/bulbasaur/BulbasaurMob.java index 70bea51..d8592b2 100644 --- a/src/test/java/demo_models/bulbasaur/BulbasaurMob.java +++ b/src/test/java/demo_models/bulbasaur/BulbasaurMob.java @@ -13,7 +13,6 @@ import net.minestom.server.instance.Instance; import net.minestom.server.network.packet.server.play.ParticlePacket; import net.minestom.server.particle.Particle; -import net.minestom.server.particle.ParticleCreator; import net.minestom.server.timer.Task; import net.minestom.server.utils.position.PositionUtils; import net.minestom.server.utils.time.TimeUnit; @@ -116,7 +115,7 @@ public void remove() { this.animationHandler.playOnce("animation.bulbasaur.faint", (cb) -> { this.model.destroy(); this.animationHandler.destroy(); - ParticlePacket packet = ParticleCreator.createParticlePacket(Particle.POOF, position.x(), position.y() + 1, position.z(), 1, 1, 1, 50); + ParticlePacket packet = new ParticlePacket(Particle.POOF, position.x(), position.y() + 1, position.z(), 1, 1, 1, 0, 50); viewers.forEach(v -> v.sendPacket(packet)); super.remove(); diff --git a/src/test/java/demo_models/gem_golem/GemGolemAttackGoal.java b/src/test/java/demo_models/gem_golem/GemGolemAttackGoal.java index 8003099..7effbde 100644 --- a/src/test/java/demo_models/gem_golem/GemGolemAttackGoal.java +++ b/src/test/java/demo_models/gem_golem/GemGolemAttackGoal.java @@ -7,7 +7,6 @@ import net.minestom.server.entity.ai.GoalSelector; import net.minestom.server.network.packet.server.play.ParticlePacket; import net.minestom.server.particle.Particle; -import net.minestom.server.particle.ParticleCreator; import net.minestom.server.timer.ExecutionType; import net.minestom.server.timer.TaskSchedule; import net.worldseed.multipart.GenericModel; @@ -76,13 +75,13 @@ private void attackNear() { Point p = model.getVFX("hit_vfx"); if (p != null) { - ParticlePacket packet = ParticleCreator.createParticlePacket(Particle.FLAME, p.x(), p.y(), p.z(), 0, 0, 0, 1); + ParticlePacket packet = new ParticlePacket(Particle.FLAME, p.x(), p.y(), p.z(), 0, 0, 0, 0, 1); entityCreature.sendPacketToViewers(packet); } if (counter.addAndGet(1) > sections) { if (p != null) { - ParticlePacket packet = ParticleCreator.createParticlePacket(Particle.EXPLOSION, p.x(), p.y(), p.z(), 0, 0, 0, 1); + ParticlePacket packet = new ParticlePacket(Particle.EXPLOSION, p.x(), p.y(), p.z(), 0, 0, 0, 0, 1); entityCreature.sendPacketToViewers(packet); } diff --git a/src/test/java/demo_models/gem_golem/GemGolemMob.java b/src/test/java/demo_models/gem_golem/GemGolemMob.java index 688334f..76f6a2d 100644 --- a/src/test/java/demo_models/gem_golem/GemGolemMob.java +++ b/src/test/java/demo_models/gem_golem/GemGolemMob.java @@ -13,7 +13,6 @@ import net.minestom.server.instance.Instance; import net.minestom.server.network.packet.server.play.ParticlePacket; import net.minestom.server.particle.Particle; -import net.minestom.server.particle.ParticleCreator; import net.minestom.server.timer.Task; import net.minestom.server.utils.position.PositionUtils; import net.minestom.server.utils.time.TimeUnit; @@ -143,7 +142,7 @@ public void remove() { this.animationHandler.playOnce("death", (cb) -> { this.model.destroy(); this.animationHandler.destroy(); - ParticlePacket packet = ParticleCreator.createParticlePacket(Particle.POOF, position.x(), position.y() + 1, position.z(), 1, 1, 1, 50); + ParticlePacket packet = new ParticlePacket(Particle.POOF, position.x(), position.y() + 1, position.z(), 1, 1, 1, 0, 50); viewers.forEach(v -> v.sendPacket(packet)); super.remove(); diff --git a/src/test/java/demo_models/tuff_golem/TuffGolemMob.java b/src/test/java/demo_models/tuff_golem/TuffGolemMob.java index 53cf4ee..720c25e 100644 --- a/src/test/java/demo_models/tuff_golem/TuffGolemMob.java +++ b/src/test/java/demo_models/tuff_golem/TuffGolemMob.java @@ -11,7 +11,6 @@ import net.minestom.server.instance.Instance; import net.minestom.server.network.packet.server.play.ParticlePacket; import net.minestom.server.particle.Particle; -import net.minestom.server.particle.ParticleCreator; import net.minestom.server.timer.Task; import net.minestom.server.utils.time.TimeUnit; import net.worldseed.multipart.animations.AnimationHandler; @@ -92,7 +91,7 @@ public void remove() { var viewers = Set.copyOf(this.getViewers()); this.model.destroy(); this.animationHandler.destroy(); - ParticlePacket packet = ParticleCreator.createParticlePacket(Particle.POOF, position.x(), position.y() + 1, position.z(), 1, 1, 1, 50); + ParticlePacket packet = new ParticlePacket(Particle.POOF, position.x(), position.y() + 1, position.z(), 1, 1, 1, 0, 50); viewers.forEach(v -> v.sendPacket(packet)); super.remove();