From b88ff2cd5f16dc68e3ec4547606f109fa08d55be Mon Sep 17 00:00:00 2001 From: Yang Seong Mo Date: Thu, 26 Dec 2024 22:24:26 +0900 Subject: [PATCH] Rename and refactoring. --- README.md | 2 +- api/build.gradle.kts | 60 +++++++++++++++++-- .../{ModelRenderer.java => BetterModel.java} | 7 ++- .../api/data/blueprint/BlueprintChildren.java | 2 +- .../api/data/blueprint/ModelBlueprint.java | 12 ---- .../api/data/renderer/RenderInstance.java | 14 ++--- .../api/data/renderer/RendererGroup.java | 4 +- .../model/api/entity/RenderedEntity.java | 12 ++-- .../model/api/entity/TrackerMovement.java | 7 --- .../model/api/event/ModelInteractEvent.java | 4 +- .../model/api/manager/ConfigManager.java | 12 ++++ .../model/api/manager/ModelManager.java | 10 ++++ .../toxicity/model/api/nms/ModelDisplay.java | 2 +- .../model/api/tracker/EntityTracker.java | 22 +++---- .../toxicity/model/api/tracker/Tracker.java | 10 ++-- .../model/api/tracker/VoidTracker.java | 15 +++-- .../toxicity/model/api/util/EntityUtil.java | 10 ++-- .../toxicity/model/api/util/VectorPair.java | 7 --- build.gradle.kts | 7 ++- ...odelRendererImpl.kt => BetterModelImpl.kt} | 8 ++- .../mythicmobs/BindHitBoxMechanic.kt | 2 +- .../mythicmobs/DefaultStateMechanic.kt | 2 +- .../compatibility/mythicmobs/ModelMechanic.kt | 2 +- .../mythicmobs/PartVisibilityMechanic.kt | 2 +- .../compatibility/mythicmobs/StateMechanic.kt | 2 +- .../configuration/PluginConfiguration.kt | 34 +++++++++++ .../model/manager/CommandManagerImpl.kt | 18 +++--- .../model/manager/ConfigManagerImpl.kt | 38 ++++++++++++ .../model/manager/ModelManagerImpl.kt | 11 ++-- .../kr/toxicity/model/util/Functions.kt | 3 + .../kotlin/kr/toxicity/model/util/Plugins.kt | 4 +- .../kotlin/kr/toxicity/model/util/Yamls.kt | 12 ++++ core/src/main/resources/config.yml | 5 ++ .../kr/toxicity/model/nms/v1_20_R3/NMSImpl.kt | 9 +-- .../kr/toxicity/model/nms/v1_20_R4/NMSImpl.kt | 9 +-- .../kr/toxicity/model/nms/v1_21_R1/NMSImpl.kt | 9 +-- .../kr/toxicity/model/nms/v1_21_R2/NMSImpl.kt | 14 ++--- .../kr/toxicity/model/nms/v1_21_R3/NMSImpl.kt | 14 ++--- settings.gradle.kts | 2 +- 39 files changed, 284 insertions(+), 135 deletions(-) rename api/src/main/java/kr/toxicity/model/api/{ModelRenderer.java => BetterModel.java} (85%) create mode 100644 api/src/main/java/kr/toxicity/model/api/manager/ConfigManager.java delete mode 100644 api/src/main/java/kr/toxicity/model/api/util/VectorPair.java rename core/src/main/kotlin/kr/toxicity/model/{ModelRendererImpl.kt => BetterModelImpl.kt} (91%) create mode 100644 core/src/main/kotlin/kr/toxicity/model/configuration/PluginConfiguration.kt create mode 100644 core/src/main/kotlin/kr/toxicity/model/manager/ConfigManagerImpl.kt create mode 100644 core/src/main/kotlin/kr/toxicity/model/util/Functions.kt create mode 100644 core/src/main/kotlin/kr/toxicity/model/util/Yamls.kt create mode 100644 core/src/main/resources/config.yml diff --git a/README.md b/README.md index e2c7067..2bfd1ca 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ModelRenderer +# BetterModel This plugin is still on developing! ### TODO diff --git a/api/build.gradle.kts b/api/build.gradle.kts index bf2a39b..e31a727 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -1,7 +1,59 @@ +import com.vanniktech.maven.publish.JavaLibrary +import com.vanniktech.maven.publish.JavadocJar +import com.vanniktech.maven.publish.SonatypeHost + +plugins { + id("com.vanniktech.maven.publish") version "0.30.0" + signing +} + +java { + withSourcesJar() + withJavadocJar() +} + +signing { + useGpgCmd() +} + dependencies { - compileOnly("org.projectlombok:lombok:1.18.34") - annotationProcessor("org.projectlombok:lombok:1.18.34") + compileOnly("org.projectlombok:lombok:1.18.36") + annotationProcessor("org.projectlombok:lombok:1.18.36") + + testCompileOnly("org.projectlombok:lombok:1.18.36") + testAnnotationProcessor("org.projectlombok:lombok:1.18.36") +} - testCompileOnly("org.projectlombok:lombok:1.18.34") - testAnnotationProcessor("org.projectlombok:lombok:1.18.34") +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + signAllPublications() + coordinates("io.github.toxicity188", rootProject.name, project.version as String) + configure(JavaLibrary( + javadocJar = JavadocJar.None(), + sourcesJar = true, + )) + pom { + name = rootProject.name + description = "cross-platform command library implementing brigadier, adventure." + inceptionYear = "2024" + url = "https://github.com/toxicity188/BetterModel/" + licenses { + license { + name = "MIT License" + url = "https://mit-license.org/" + } + } + developers { + developer { + id = "toxicity188" + name = "toxicity188" + url = "https://github.com/toxicity188/" + } + } + scm { + url = "https://github.com/toxicity188/BetterModel/" + connection = "scm:git:git://github.com/toxicity188/BetterModel.git" + developerConnection = "scm:git:ssh://git@github.com/toxicity188/BetterModel.git" + } + } } \ No newline at end of file diff --git a/api/src/main/java/kr/toxicity/model/api/ModelRenderer.java b/api/src/main/java/kr/toxicity/model/api/BetterModel.java similarity index 85% rename from api/src/main/java/kr/toxicity/model/api/ModelRenderer.java rename to api/src/main/java/kr/toxicity/model/api/BetterModel.java index 5a38644..e1593ac 100644 --- a/api/src/main/java/kr/toxicity/model/api/ModelRenderer.java +++ b/api/src/main/java/kr/toxicity/model/api/BetterModel.java @@ -8,9 +8,9 @@ import java.util.Objects; -public abstract class ModelRenderer extends JavaPlugin { +public abstract class BetterModel extends JavaPlugin { - private static ModelRenderer instance; + private static BetterModel instance; @Override public final void onLoad() { @@ -18,7 +18,7 @@ public final void onLoad() { instance = this; } - public static @NotNull ModelRenderer inst() { + public static @NotNull BetterModel inst() { return Objects.requireNonNull(instance); } @@ -32,6 +32,7 @@ public final void onLoad() { public abstract @NotNull EntityManager entityManager(); public abstract @NotNull CommandManager commandManager(); public abstract @NotNull CompatibilityManager compatibilityManager(); + public abstract @NotNull ConfigManager configManager(); public sealed interface ReloadResult { record Success(long time) implements ReloadResult { diff --git a/api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintChildren.java b/api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintChildren.java index 03404ac..cfd1df6 100644 --- a/api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintChildren.java +++ b/api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintChildren.java @@ -48,7 +48,7 @@ public boolean buildJson( var textureObject = new JsonObject(); var index = 0; for (BlueprintTexture texture : parent.textures()) { - textureObject.addProperty(Integer.toString(index++), "modelrenderer:item/" + parent.name() + "_" + texture.name()); + textureObject.addProperty(Integer.toString(index++), "bettermodel:item/" + parent.name() + "_" + texture.name()); } object.add("textures", textureObject); var elements = new JsonArray(); diff --git a/api/src/main/java/kr/toxicity/model/api/data/blueprint/ModelBlueprint.java b/api/src/main/java/kr/toxicity/model/api/data/blueprint/ModelBlueprint.java index fdc4b56..89176f3 100644 --- a/api/src/main/java/kr/toxicity/model/api/data/blueprint/ModelBlueprint.java +++ b/api/src/main/java/kr/toxicity/model/api/data/blueprint/ModelBlueprint.java @@ -40,18 +40,6 @@ public record ModelBlueprint( ); } - public @NotNull List buildJson(int tint) { - var list = new ArrayList(); - for (BlueprintChildren blueprintChildren : group) { - switch (blueprintChildren) { - case BlueprintChildren.BlueprintElement blueprintElement -> { - } - case BlueprintChildren.BlueprintGroup blueprintGroup -> blueprintGroup.buildJson(tint,this, list); - } - } - return list; - } - public @NotNull List buildImage() { var list = new ArrayList(); for (BlueprintTexture texture : textures) { diff --git a/api/src/main/java/kr/toxicity/model/api/data/renderer/RenderInstance.java b/api/src/main/java/kr/toxicity/model/api/data/renderer/RenderInstance.java index 2ffe3c8..e3a5c3c 100644 --- a/api/src/main/java/kr/toxicity/model/api/data/renderer/RenderInstance.java +++ b/api/src/main/java/kr/toxicity/model/api/data/renderer/RenderInstance.java @@ -1,6 +1,6 @@ package kr.toxicity.model.api.data.renderer; -import kr.toxicity.model.api.ModelRenderer; +import kr.toxicity.model.api.BetterModel; import kr.toxicity.model.api.data.blueprint.AnimationMovement; import kr.toxicity.model.api.data.blueprint.BlueprintAnimation; import kr.toxicity.model.api.entity.RenderedEntity; @@ -63,8 +63,8 @@ public void close() { playerMap.clear(); } - public void teleport(@NotNull Location location) { - entityMap.values().forEach(e -> e.teleport(location)); + public void teleport(@NotNull Location location, @NotNull PacketBundler bundler) { + entityMap.values().forEach(e -> e.teleport(location, bundler)); } public void move(@NotNull TrackerMovement movement, @NotNull PacketBundler bundler) { @@ -95,7 +95,7 @@ public boolean addAnimationMovementModifier(@NotNull Predicate p } public void tint(boolean toggle) { - var bundler = ModelRenderer.inst().nms().createBundler(); + var bundler = BetterModel.inst().nms().createBundler(); entityMap.values().forEach(e -> e.tint(toggle, bundler)); if (!bundler.isEmpty()) for (Player player : viewedPlayer()) { bundler.send(player); @@ -156,7 +156,7 @@ public boolean replaceSingle(@NotNull String target, @NotNull String animation) } public void spawn(@NotNull Player player, @NotNull PacketBundler bundler) { - var get = ModelRenderer.inst().playerManager().player(player.getUniqueId()); + var get = BetterModel.inst().playerManager().player(player.getUniqueId()); if (get == null) return; playerMap.computeIfAbsent(player.getUniqueId(), u -> { entityMap.values().forEach(e -> e.spawn(bundler)); @@ -168,13 +168,13 @@ public void remove(@NotNull Player player) { remove0(player); } private void remove0(@NotNull Player player) { - var bundler = ModelRenderer.inst().nms().createBundler(); + var bundler = BetterModel.inst().nms().createBundler(); entityMap.values().forEach(e -> e.remove(bundler)); bundler.send(player); } public void togglePart(@NotNull Predicate predicate, boolean toggle) { - var bundler = ModelRenderer.inst().nms().createBundler(); + var bundler = BetterModel.inst().nms().createBundler(); entityMap.values().forEach(e -> e.togglePart(bundler, predicate, toggle)); if (!bundler.isEmpty()) for (Player player : viewedPlayer()) { bundler.send(player); diff --git a/api/src/main/java/kr/toxicity/model/api/data/renderer/RendererGroup.java b/api/src/main/java/kr/toxicity/model/api/data/renderer/RendererGroup.java index 2bcaae0..cda9f98 100644 --- a/api/src/main/java/kr/toxicity/model/api/data/renderer/RendererGroup.java +++ b/api/src/main/java/kr/toxicity/model/api/data/renderer/RendererGroup.java @@ -1,6 +1,6 @@ package kr.toxicity.model.api.data.renderer; -import kr.toxicity.model.api.ModelRenderer; +import kr.toxicity.model.api.BetterModel; import kr.toxicity.model.api.data.blueprint.BlueprintChildren; import kr.toxicity.model.api.data.blueprint.NamedBoundingBox; import kr.toxicity.model.api.entity.EntityMovement; @@ -58,7 +58,7 @@ public RendererGroup( rotation = group.rotation().toVector(); if (itemStack != null) { displayFunction = l -> { - var display = ModelRenderer.inst().nms().create(l); + var display = BetterModel.inst().nms().create(l); display.item(parent.visibility() ? itemStack : new ItemStack(Material.AIR)); return display; }; diff --git a/api/src/main/java/kr/toxicity/model/api/entity/RenderedEntity.java b/api/src/main/java/kr/toxicity/model/api/entity/RenderedEntity.java index 583f6fe..6506404 100644 --- a/api/src/main/java/kr/toxicity/model/api/entity/RenderedEntity.java +++ b/api/src/main/java/kr/toxicity/model/api/entity/RenderedEntity.java @@ -1,6 +1,6 @@ package kr.toxicity.model.api.entity; -import kr.toxicity.model.api.ModelRenderer; +import kr.toxicity.model.api.BetterModel; import kr.toxicity.model.api.data.blueprint.AnimationMovement; import kr.toxicity.model.api.data.blueprint.BlueprintAnimation; import kr.toxicity.model.api.data.blueprint.BlueprintAnimator; @@ -78,7 +78,7 @@ public void createHitBox(@NotNull Entity entity, @NotNull Predicate e.teleport(location)); + public void teleport(@NotNull Location location, @NotNull PacketBundler bundler) { + if (display != null) display.teleport(location, bundler); + children.values().forEach(e -> e.teleport(location, bundler)); } public void spawn(@NotNull PacketBundler bundler) { diff --git a/api/src/main/java/kr/toxicity/model/api/entity/TrackerMovement.java b/api/src/main/java/kr/toxicity/model/api/entity/TrackerMovement.java index 65b4a1b..41c3df8 100644 --- a/api/src/main/java/kr/toxicity/model/api/entity/TrackerMovement.java +++ b/api/src/main/java/kr/toxicity/model/api/entity/TrackerMovement.java @@ -19,13 +19,6 @@ public record TrackerMovement( new Vector3f(movement.rawRotation()) ); } - public @NotNull TrackerMovement plus(@NotNull TrackerMovement movement) { - return new TrackerMovement( - new Vector3f(transform).add(movement.transform), - new Vector3f(scale).add(movement.scale), - new Vector3f(rotation).add(movement.rotation) - ); - } public @NotNull TrackerMovement copy() { return new TrackerMovement( new Vector3f(transform), diff --git a/api/src/main/java/kr/toxicity/model/api/event/ModelInteractEvent.java b/api/src/main/java/kr/toxicity/model/api/event/ModelInteractEvent.java index d4962dc..a87563b 100644 --- a/api/src/main/java/kr/toxicity/model/api/event/ModelInteractEvent.java +++ b/api/src/main/java/kr/toxicity/model/api/event/ModelInteractEvent.java @@ -16,8 +16,8 @@ public class ModelInteractEvent extends PlayerEvent implements Cancellable { @Setter private boolean cancelled; - private final HitBox hitBox; - private final Hand hand; + private final @NotNull HitBox hitBox; + private final @NotNull Hand hand; public ModelInteractEvent(@NotNull Player who, @NotNull HitBox hitBox, @NotNull Hand hand) { super(who); diff --git a/api/src/main/java/kr/toxicity/model/api/manager/ConfigManager.java b/api/src/main/java/kr/toxicity/model/api/manager/ConfigManager.java new file mode 100644 index 0000000..5ffcab7 --- /dev/null +++ b/api/src/main/java/kr/toxicity/model/api/manager/ConfigManager.java @@ -0,0 +1,12 @@ +package kr.toxicity.model.api.manager; + +import org.bukkit.Material; +import org.jetbrains.annotations.NotNull; + +public interface ConfigManager { + boolean metrics(); + boolean sightTrace(); + @NotNull Material item(); + double maxSight(); + double minSight(); +} diff --git a/api/src/main/java/kr/toxicity/model/api/manager/ModelManager.java b/api/src/main/java/kr/toxicity/model/api/manager/ModelManager.java index 4a91c7d..981c1b6 100644 --- a/api/src/main/java/kr/toxicity/model/api/manager/ModelManager.java +++ b/api/src/main/java/kr/toxicity/model/api/manager/ModelManager.java @@ -1,12 +1,15 @@ package kr.toxicity.model.api.manager; import kr.toxicity.model.api.data.renderer.BlueprintRenderer; +import kr.toxicity.model.api.tracker.EntityTracker; +import org.bukkit.entity.Entity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; import java.util.List; import java.util.Set; +import java.util.UUID; public interface ModelManager extends GlobalManager { @Nullable BlueprintRenderer renderer(@NotNull String name); @@ -14,4 +17,11 @@ public interface ModelManager extends GlobalManager { List renderers(); @NotNull @Unmodifiable Set keys(); + + default @Nullable EntityTracker tracker(@NotNull Entity entity) { + return EntityTracker.tracker(entity); + } + default @Nullable EntityTracker tracker(@NotNull UUID uuid) { + return EntityTracker.tracker(uuid); + } } diff --git a/api/src/main/java/kr/toxicity/model/api/nms/ModelDisplay.java b/api/src/main/java/kr/toxicity/model/api/nms/ModelDisplay.java index bf8088f..f4de2cd 100644 --- a/api/src/main/java/kr/toxicity/model/api/nms/ModelDisplay.java +++ b/api/src/main/java/kr/toxicity/model/api/nms/ModelDisplay.java @@ -10,7 +10,7 @@ public interface ModelDisplay { void spawn(@NotNull PacketBundler bundler); void remove(@NotNull PacketBundler bundler); - void teleport(@NotNull Location location); + void teleport(@NotNull Location location, @NotNull PacketBundler bundler); void item(@NotNull ItemStack itemStack); void transform(@NotNull Transformation transformation); void send(@NotNull PacketBundler bundler); diff --git a/api/src/main/java/kr/toxicity/model/api/tracker/EntityTracker.java b/api/src/main/java/kr/toxicity/model/api/tracker/EntityTracker.java index 0e412af..cfdaaa1 100644 --- a/api/src/main/java/kr/toxicity/model/api/tracker/EntityTracker.java +++ b/api/src/main/java/kr/toxicity/model/api/tracker/EntityTracker.java @@ -1,6 +1,6 @@ package kr.toxicity.model.api.tracker; -import kr.toxicity.model.api.ModelRenderer; +import kr.toxicity.model.api.BetterModel; import kr.toxicity.model.api.data.renderer.AnimationModifier; import kr.toxicity.model.api.data.renderer.RenderInstance; import kr.toxicity.model.api.entity.RenderedEntity; @@ -43,7 +43,7 @@ public final class EntityTracker extends Tracker { if (t == null) { var tag = entity.getPersistentDataContainer().get(TRACKING_ID, PersistentDataType.STRING); if (tag == null) return null; - var render = ModelRenderer.inst().modelManager().renderer(tag); + var render = BetterModel.inst().modelManager().renderer(tag); if (render != null) return render.create(entity); } return t; @@ -58,8 +58,8 @@ public final class EntityTracker extends Tracker { public EntityTracker(@NotNull Entity entity, @NotNull RenderInstance instance) { super(instance); this.entity = entity; - var adapt = entity instanceof LivingEntity livingEntity ? ModelRenderer.inst().nms().adapt(livingEntity) : EntityAdapter.EMPTY; - instance.defaultPosition(new Vector3f(0, -ModelRenderer.inst().nms().passengerPosition(entity).y, 0)); + var adapt = entity instanceof LivingEntity livingEntity ? BetterModel.inst().nms().adapt(livingEntity) : EntityAdapter.EMPTY; + instance.defaultPosition(new Vector3f(0, -BetterModel.inst().nms().passengerPosition(entity).y, 0)); instance.addAnimationMovementModifier( r -> r.getName().startsWith("h_"), a -> { @@ -79,7 +79,7 @@ public EntityTracker(@NotNull Entity entity, @NotNull RenderInstance instance) { )); entity.getPersistentDataContainer().set(TRACKING_ID, PersistentDataType.STRING, instance.getParent().getParent().name()); TRACKER_MAP.put(entity.getUniqueId(), this); - Bukkit.getRegionScheduler().run(ModelRenderer.inst(), entity.getLocation(), s -> { + Bukkit.getRegionScheduler().run(BetterModel.inst(), entity.getLocation(), s -> { if (!closed.get() && !forRemoval()) createHitBox(); }); } @@ -125,10 +125,10 @@ public void close() throws Exception { } public void spawn(@NotNull Player player) { - var bundler = ModelRenderer.inst().nms().createBundler(); + var bundler = BetterModel.inst().nms().createBundler(); spawn(player, bundler); - ModelRenderer.inst().nms().mount(this, bundler); - var handler = ModelRenderer.inst() + BetterModel.inst().nms().mount(this, bundler); + var handler = BetterModel.inst() .playerManager() .player(player.getUniqueId()); if (handler != null) handler.startTrack(this); @@ -142,7 +142,7 @@ public void spawn(@NotNull Player player) { @Override public void remove(@NotNull Player player) { super.remove(player); - var handler = ModelRenderer.inst() + var handler = BetterModel.inst() .playerManager() .player(player.getUniqueId()); if (handler != null) handler.endTrack(this); @@ -150,8 +150,8 @@ public void remove(@NotNull Player player) { public void refresh() { instance.createHitBox(entity, r -> r.getHitBox() != null, null); - var bundler = ModelRenderer.inst().nms().createBundler(); - ModelRenderer.inst().nms().mount(this, bundler); + var bundler = BetterModel.inst().nms().createBundler(); + BetterModel.inst().nms().mount(this, bundler); if (!bundler.isEmpty()) for (Player player : viewedPlayer()) { bundler.send(player); } diff --git a/api/src/main/java/kr/toxicity/model/api/tracker/Tracker.java b/api/src/main/java/kr/toxicity/model/api/tracker/Tracker.java index db97418..9d34916 100644 --- a/api/src/main/java/kr/toxicity/model/api/tracker/Tracker.java +++ b/api/src/main/java/kr/toxicity/model/api/tracker/Tracker.java @@ -1,7 +1,7 @@ package kr.toxicity.model.api.tracker; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; -import kr.toxicity.model.api.ModelRenderer; +import kr.toxicity.model.api.BetterModel; import kr.toxicity.model.api.data.renderer.AnimationModifier; import kr.toxicity.model.api.data.renderer.RenderInstance; import kr.toxicity.model.api.entity.RenderedEntity; @@ -26,7 +26,7 @@ import java.util.function.Supplier; public abstract class Tracker implements AutoCloseable { - public static final NamespacedKey TRACKING_ID = Objects.requireNonNull(NamespacedKey.fromString("betterengine_tracker")); + public static final NamespacedKey TRACKING_ID = Objects.requireNonNull(NamespacedKey.fromString("bettermodel_tracker")); protected final RenderInstance instance; private final ScheduledTask task; @@ -37,16 +37,16 @@ public abstract class Tracker implements AutoCloseable { private Supplier movement = () -> new TrackerMovement(new Vector3f(), new Vector3f(1), new Vector3f()); public Tracker(@NotNull RenderInstance instance) { this.instance = instance; - task = Bukkit.getAsyncScheduler().runAtFixedRate(ModelRenderer.inst(), task -> { + task = Bukkit.getAsyncScheduler().runAtFixedRate(BetterModel.inst(), task -> { if (viewedPlayerSize() == 0) return; - var bundle = ModelRenderer.inst().nms().createBundler(); + var bundle = BetterModel.inst().nms().createBundler(); instance.move(movement.get(), bundle); if (!bundle.isEmpty()) for (Player player : instance.viewedPlayer()) { bundle.send(player); } }, 50, 50, TimeUnit.MILLISECONDS); tint(false); - instance.move(movement.get(), ModelRenderer.inst().nms().createBundler()); + instance.move(movement.get(), BetterModel.inst().nms().createBundler()); instance.filter(p -> EntityUtil.canSee(p.getLocation(), location())); } diff --git a/api/src/main/java/kr/toxicity/model/api/tracker/VoidTracker.java b/api/src/main/java/kr/toxicity/model/api/tracker/VoidTracker.java index 32e373e..1901429 100644 --- a/api/src/main/java/kr/toxicity/model/api/tracker/VoidTracker.java +++ b/api/src/main/java/kr/toxicity/model/api/tracker/VoidTracker.java @@ -1,6 +1,6 @@ package kr.toxicity.model.api.tracker; -import kr.toxicity.model.api.ModelRenderer; +import kr.toxicity.model.api.BetterModel; import kr.toxicity.model.api.data.renderer.RenderInstance; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -12,15 +12,22 @@ public final class VoidTracker extends Tracker { private Location location; private final UUID uuid; + public VoidTracker(@NotNull UUID uuid, @NotNull RenderInstance instance, @NotNull Location location) { super(instance); this.uuid = uuid; this.location = location; } - public void setLocation(Location location) { + + public void location(Location location) { this.location = Objects.requireNonNull(location, "location"); - instance.teleport(location); + var bundler = BetterModel.inst().nms().createBundler(); + instance.teleport(location, bundler); + if (!bundler.isEmpty()) for (Player player : viewedPlayer()) { + bundler.send(player); + } } + @Override public @NotNull Location location() { return location; @@ -32,7 +39,7 @@ public void setLocation(Location location) { } public void spawn(@NotNull Player player) { - var bundler = ModelRenderer.inst().nms().createBundler(); + var bundler = BetterModel.inst().nms().createBundler(); spawn(player, bundler); bundler.send(player); } diff --git a/api/src/main/java/kr/toxicity/model/api/util/EntityUtil.java b/api/src/main/java/kr/toxicity/model/api/util/EntityUtil.java index 8bfadf9..5a7eb04 100644 --- a/api/src/main/java/kr/toxicity/model/api/util/EntityUtil.java +++ b/api/src/main/java/kr/toxicity/model/api/util/EntityUtil.java @@ -1,5 +1,6 @@ package kr.toxicity.model.api.util; +import kr.toxicity.model.api.BetterModel; import kr.toxicity.model.api.data.blueprint.ModelBoundingBox; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -18,15 +19,14 @@ private EntityUtil() { public static final double RENDER_DISTANCE = Bukkit.getSimulationDistance() << 4; - public static final double MAX_RADIUS = 45; - public static final double MIN_RADIUS = 5; - public static boolean canSee(@NotNull Location player, @NotNull Location target) { + var manager = BetterModel.inst().configManager(); + if (!manager.sightTrace()) return true; if (player.getWorld() != target.getWorld()) return false; var d = player.distance(target); - if (d > MAX_RADIUS) return false; - if (d <= MIN_RADIUS) return true; + if (d > manager.maxSight()) return false; + if (d <= manager.minSight()) return true; var playerYaw = toRadians(player.getYaw()); var playerPitch = toRadians(-player.getPitch()) * 2; diff --git a/api/src/main/java/kr/toxicity/model/api/util/VectorPair.java b/api/src/main/java/kr/toxicity/model/api/util/VectorPair.java deleted file mode 100644 index 8a13b12..0000000 --- a/api/src/main/java/kr/toxicity/model/api/util/VectorPair.java +++ /dev/null @@ -1,7 +0,0 @@ -package kr.toxicity.model.api.util; - -import org.jetbrains.annotations.NotNull; -import org.joml.Vector3f; - -public record VectorPair(@NotNull Vector3f min, @NotNull Vector3f max) { -} diff --git a/build.gradle.kts b/build.gradle.kts index 26d4737..ccae6ff 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,6 +23,7 @@ allprojects { dependencies { testImplementation(kotlin("test")) implementation("dev.jorel:commandapi-bukkit-shade:9.7.0") + implementation("org.bstats:bstats-bukkit:3.1.0") compileOnly("io.lumine:Mythic-Dist:5.7.2") } tasks { @@ -98,19 +99,21 @@ tasks { fun prefix(pattern: String) { relocate(pattern, "${project.group}.shaded.$pattern") } + exclude("LICENSE") prefix("kotlin") prefix("dev.jorel.commandapi") + prefix("org.bstats") } } bukkitPluginYaml { - main = "${project.group}.ModelRendererImpl" + main = "${project.group}.BetterModelImpl" version = project.version.toString() name = rootProject.name foliaSupported = true apiVersion = "1.20" author = "toxicity" - description = "Simple Model API." + description = "Simple Model plugin." softDepend = listOf( "MythicMobs" ) diff --git a/core/src/main/kotlin/kr/toxicity/model/ModelRendererImpl.kt b/core/src/main/kotlin/kr/toxicity/model/BetterModelImpl.kt similarity index 91% rename from core/src/main/kotlin/kr/toxicity/model/ModelRendererImpl.kt rename to core/src/main/kotlin/kr/toxicity/model/BetterModelImpl.kt index b4e0c09..ab4bb76 100644 --- a/core/src/main/kotlin/kr/toxicity/model/ModelRendererImpl.kt +++ b/core/src/main/kotlin/kr/toxicity/model/BetterModelImpl.kt @@ -1,7 +1,7 @@ package kr.toxicity.model -import kr.toxicity.model.api.ModelRenderer -import kr.toxicity.model.api.ModelRenderer.ReloadResult.* +import kr.toxicity.model.api.BetterModel +import kr.toxicity.model.api.BetterModel.ReloadResult.* import kr.toxicity.model.api.manager.* import kr.toxicity.model.api.nms.NMS import kr.toxicity.model.api.version.MinecraftVersion @@ -12,7 +12,7 @@ import org.bukkit.Bukkit import java.util.concurrent.atomic.AtomicBoolean @Suppress("UNUSED") -class ModelRendererImpl : ModelRenderer() { +class BetterModelImpl : BetterModel() { private val version = MinecraftVersion(Bukkit.getBukkitVersion().substringBefore('-')) private lateinit var nms: NMS @@ -21,6 +21,7 @@ class ModelRendererImpl : ModelRenderer() { private val managers by lazy { listOf( CompatibilityManagerImpl, + ConfigManagerImpl, ModelManagerImpl, PlayerManagerImpl, EntityManagerImpl, @@ -73,6 +74,7 @@ class ModelRendererImpl : ModelRenderer() { override fun entityManager(): EntityManager = EntityManagerImpl override fun commandManager(): CommandManager = CommandManagerImpl override fun compatibilityManager(): CompatibilityManager = CompatibilityManagerImpl + override fun configManager(): ConfigManager = ConfigManagerImpl override fun version(): MinecraftVersion = version override fun nms(): NMS = nms diff --git a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/BindHitBoxMechanic.kt b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/BindHitBoxMechanic.kt index e4a4c56..3cda830 100644 --- a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/BindHitBoxMechanic.kt +++ b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/BindHitBoxMechanic.kt @@ -12,7 +12,7 @@ import kr.toxicity.model.api.tracker.EntityTracker import org.bukkit.damage.DamageSource import org.bukkit.entity.Damageable -class BindHitBoxMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[ModelRenderer]", mlc), INoTargetSkill { +class BindHitBoxMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[BetterModel]", mlc), INoTargetSkill { private val partId = mlc.getString(arrayOf("partid", "p", "pid", "part"))!! private val type = mlc.getString(arrayOf("type", "t", "mob", "m"))?.let { diff --git a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/DefaultStateMechanic.kt b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/DefaultStateMechanic.kt index 33a952d..a1f805a 100644 --- a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/DefaultStateMechanic.kt +++ b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/DefaultStateMechanic.kt @@ -8,7 +8,7 @@ import io.lumine.mythic.bukkit.MythicBukkit import io.lumine.mythic.core.skills.SkillMechanic import kr.toxicity.model.api.tracker.EntityTracker -class DefaultStateMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[ModelRenderer]", mlc), INoTargetSkill { +class DefaultStateMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[BetterModel]", mlc), INoTargetSkill { private val t = mlc.getString(arrayOf("t", "type"))!! private val s = mlc.getString(arrayOf("state", "s"))!! diff --git a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/ModelMechanic.kt b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/ModelMechanic.kt index a0eaa0e..096bd9c 100644 --- a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/ModelMechanic.kt +++ b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/ModelMechanic.kt @@ -9,7 +9,7 @@ import io.lumine.mythic.core.skills.SkillMechanic import kr.toxicity.model.api.util.EntityUtil import kr.toxicity.model.manager.ModelManagerImpl -class ModelMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[ModelRenderer]", mlc), INoTargetSkill { +class ModelMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[BetterModel]", mlc), INoTargetSkill { private val mid = mlc.getString(arrayOf("mid", "m", "model"))!! diff --git a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/PartVisibilityMechanic.kt b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/PartVisibilityMechanic.kt index fd6b42f..cc64605 100644 --- a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/PartVisibilityMechanic.kt +++ b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/PartVisibilityMechanic.kt @@ -8,7 +8,7 @@ import io.lumine.mythic.bukkit.MythicBukkit import io.lumine.mythic.core.skills.SkillMechanic import kr.toxicity.model.api.tracker.EntityTracker -class PartVisibilityMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[ModelRenderer]", mlc), INoTargetSkill { +class PartVisibilityMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[BetterModel]", mlc), INoTargetSkill { private val p = mlc.getString(arrayOf("part", "p"))!! private val v = mlc.getBoolean(arrayOf("value", "v"), true) diff --git a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/StateMechanic.kt b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/StateMechanic.kt index 964ad8e..5f1aca2 100644 --- a/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/StateMechanic.kt +++ b/core/src/main/kotlin/kr/toxicity/model/compatibility/mythicmobs/StateMechanic.kt @@ -9,7 +9,7 @@ import io.lumine.mythic.core.skills.SkillMechanic import kr.toxicity.model.api.data.renderer.AnimationModifier import kr.toxicity.model.api.tracker.EntityTracker -class StateMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[ModelRenderer]", mlc), INoTargetSkill { +class StateMechanic(mlc: MythicLineConfig) : SkillMechanic(MythicBukkit.inst().skillManager, null, "[BetterModel]", mlc), INoTargetSkill { private val s = mlc.getString(arrayOf("state", "s"))!! private val li = mlc.getInteger(arrayOf("li"), 0) diff --git a/core/src/main/kotlin/kr/toxicity/model/configuration/PluginConfiguration.kt b/core/src/main/kotlin/kr/toxicity/model/configuration/PluginConfiguration.kt new file mode 100644 index 0000000..91df168 --- /dev/null +++ b/core/src/main/kotlin/kr/toxicity/model/configuration/PluginConfiguration.kt @@ -0,0 +1,34 @@ +package kr.toxicity.model.configuration + +import kr.toxicity.model.util.* +import org.bukkit.configuration.file.YamlConfiguration +import java.io.File + +enum class PluginConfiguration( + private val dir: String +) { + CONFIG("config.yml"), + ; + + fun create(): YamlConfiguration { + val file = File(DATA_FOLDER, dir) + val exists = file.exists() + if (!exists) PLUGIN.saveResource(dir, false) + val yaml = file.toYaml() + val newYaml = PLUGIN.getResource(dir).ifNull("Resource '$dir' not found.").toYaml() + yaml.getKeys(true).forEach { + if (!newYaml.contains(it)) yaml.set(it, null) + } + newYaml.getKeys(true).forEach { + if (!yaml.contains(it)) { + yaml.set(it, newYaml.get(it)) + yaml.setComments(it ,newYaml.getComments(it)) + yaml.setInlineComments(it, newYaml.getComments(it)) + } + } + yaml.set("plugin-version", PLUGIN.description.version) + return yaml.apply { + save(file) + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/kr/toxicity/model/manager/CommandManagerImpl.kt b/core/src/main/kotlin/kr/toxicity/model/manager/CommandManagerImpl.kt index ae0a1a5..066c2b2 100644 --- a/core/src/main/kotlin/kr/toxicity/model/manager/CommandManagerImpl.kt +++ b/core/src/main/kotlin/kr/toxicity/model/manager/CommandManagerImpl.kt @@ -7,23 +7,21 @@ import dev.jorel.commandapi.arguments.ArgumentSuggestions import dev.jorel.commandapi.arguments.StringArgument import dev.jorel.commandapi.executors.CommandExecutionInfo import dev.jorel.commandapi.executors.PlayerCommandExecutor -import kr.toxicity.model.api.ModelRenderer.ReloadResult.* +import kr.toxicity.model.api.BetterModel.ReloadResult.* import kr.toxicity.model.api.manager.CommandManager import kr.toxicity.model.util.PLUGIN -import org.bukkit.attribute.Attribute import org.bukkit.entity.EntityType -import org.bukkit.entity.LivingEntity object CommandManagerImpl : CommandManager, GlobalManagerImpl { override fun start() { CommandAPI.onLoad(CommandAPIBukkitConfig(PLUGIN).silentLogs(true)) - CommandAPICommand("modelrenderer") - .withAliases("mr") - .withPermission("modelrenderer") + CommandAPICommand("bettermodel") + .withAliases("br") + .withPermission("bettermodel") .withSubcommands( CommandAPICommand("spawn") .withAliases("s") - .withPermission("modelrenderer.spawn") + .withPermission("bettermodel.spawn") .withArguments(StringArgument("name") .replaceSuggestions(ArgumentSuggestions.strings { ModelManagerImpl.keys().toTypedArray() @@ -40,7 +38,7 @@ object CommandManagerImpl : CommandManager, GlobalManagerImpl { }), CommandAPICommand("reload") .withAliases("re", "rl") - .withPermission("modelrenderer.reload") + .withPermission("bettermodel.reload") .executes(CommandExecutionInfo { when (val result = PLUGIN.reload()) { is OnReload -> it.sender().sendMessage("The plugin still on reload!") @@ -53,8 +51,8 @@ object CommandManagerImpl : CommandManager, GlobalManagerImpl { }), ) .executes(CommandExecutionInfo { - it.sender().sendMessage("/modelrenderer reload - reloads this plugin.") - it.sender().sendMessage("/modelrenderer summon - summons some model to husk.") + it.sender().sendMessage("/bettermodel reload - reloads this plugin.") + it.sender().sendMessage("/bettermodel summon - summons some model to husk.") }) .register(PLUGIN) } diff --git a/core/src/main/kotlin/kr/toxicity/model/manager/ConfigManagerImpl.kt b/core/src/main/kotlin/kr/toxicity/model/manager/ConfigManagerImpl.kt new file mode 100644 index 0000000..04a7ea7 --- /dev/null +++ b/core/src/main/kotlin/kr/toxicity/model/manager/ConfigManagerImpl.kt @@ -0,0 +1,38 @@ +package kr.toxicity.model.manager + +import kr.toxicity.model.api.manager.ConfigManager +import kr.toxicity.model.configuration.PluginConfiguration +import kr.toxicity.model.util.PLUGIN +import kr.toxicity.model.util.ifNull +import org.bstats.bukkit.Metrics +import org.bukkit.Material + +object ConfigManagerImpl : ConfigManager, GlobalManagerImpl { + + private var metrics: Metrics? = null + private var sightTrace = true + private var item = Material.LEATHER_HORSE_ARMOR + private var maxSight = 45.0 + private var minSight = 5.0 + + override fun item(): Material = item + override fun metrics(): Boolean = metrics != null + override fun sightTrace(): Boolean = sightTrace + override fun maxSight(): Double = maxSight + override fun minSight(): Double = minSight + + override fun reload() { + val yaml = PluginConfiguration.CONFIG.create() + if (yaml.getBoolean("metrics", true)) { + if (metrics == null) metrics = Metrics(PLUGIN, 24237) + } else metrics?.shutdown() + sightTrace = yaml.getBoolean("sight-trace", true) + item = yaml.getString("item")?.let { + runCatching { + Material.getMaterial(it).ifNull("This item doesn't exist: $it") + }.getOrDefault(Material.LEATHER_HORSE_ARMOR) + } ?: Material.LEATHER_HORSE_ARMOR + maxSight = yaml.getDouble("max-sight", 45.0) + minSight = yaml.getDouble("min-sight", 5.0) + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/kr/toxicity/model/manager/ModelManagerImpl.kt b/core/src/main/kotlin/kr/toxicity/model/manager/ModelManagerImpl.kt index efaab0a..ae316df 100644 --- a/core/src/main/kotlin/kr/toxicity/model/manager/ModelManagerImpl.kt +++ b/core/src/main/kotlin/kr/toxicity/model/manager/ModelManagerImpl.kt @@ -15,7 +15,6 @@ import java.util.Collections object ModelManagerImpl : ModelManager, GlobalManagerImpl { - private val item = Material.LEATHER_HORSE_ARMOR private var index = 1 private val renderMap = HashMap() @@ -27,12 +26,12 @@ object ModelManagerImpl : ModelManager, GlobalManagerImpl { .subFolder("build") .clear() .subFolder("assets") - val renderer = assets.subFolder("modelrenderer") + val renderer = assets.subFolder("bettermodel") val textures = renderer.subFolder("textures").subFolder("item") val model = renderer.subFolder("models").subFolder("item") val modernMode = renderer.subFolder("models").subFolder("modern_item") - val itemName = item.name.lowercase() + val itemName = ConfigManagerImpl.item().name.lowercase() val modelJson = JsonObject().apply { addProperty("parent", "minecraft:item/generated") add("textures", JsonObject().apply { @@ -64,7 +63,7 @@ object ModelManagerImpl : ModelManager, GlobalManagerImpl { add("predicate", JsonObject().apply { addProperty("custom_model_data", index) }) - addProperty("model", "modelrenderer:item/${blueprintGroup.jsonName(load)}") + addProperty("model", "bettermodel:item/${blueprintGroup.jsonName(load)}") }) } else return@render null if (blueprintGroup.buildJson(0, load, modernJsonList)) { @@ -72,7 +71,7 @@ object ModelManagerImpl : ModelManager, GlobalManagerImpl { addProperty("threshold", index) add("model", JsonObject().apply { addProperty("type", "minecraft:model") - addProperty("model", "modelrenderer:modern_item/${blueprintGroup.jsonName(load)}") + addProperty("model", "bettermodel:modern_item/${blueprintGroup.jsonName(load)}") add("tints", JsonArray().apply { add(JsonObject().apply { addProperty("type", "minecraft:custom_model_data") @@ -113,7 +112,7 @@ object ModelManagerImpl : ModelManager, GlobalManagerImpl { name, scale.toFloat(), consumer(this)?.let { i -> - ItemStack(item).apply { + ItemStack(ConfigManagerImpl.item()).apply { itemMeta = itemMeta.apply { setCustomModelData(i) } diff --git a/core/src/main/kotlin/kr/toxicity/model/util/Functions.kt b/core/src/main/kotlin/kr/toxicity/model/util/Functions.kt new file mode 100644 index 0000000..fc739e6 --- /dev/null +++ b/core/src/main/kotlin/kr/toxicity/model/util/Functions.kt @@ -0,0 +1,3 @@ +package kr.toxicity.model.util + +fun T?.ifNull(message: String): T & Any = this ?: throw RuntimeException(message) \ No newline at end of file diff --git a/core/src/main/kotlin/kr/toxicity/model/util/Plugins.kt b/core/src/main/kotlin/kr/toxicity/model/util/Plugins.kt index 3cdd867..7dd7338 100644 --- a/core/src/main/kotlin/kr/toxicity/model/util/Plugins.kt +++ b/core/src/main/kotlin/kr/toxicity/model/util/Plugins.kt @@ -1,9 +1,9 @@ package kr.toxicity.model.util -import kr.toxicity.model.api.ModelRenderer +import kr.toxicity.model.api.BetterModel val PLUGIN - get() = ModelRenderer.inst() + get() = BetterModel.inst() val DATA_FOLDER get() = PLUGIN.dataFolder diff --git a/core/src/main/kotlin/kr/toxicity/model/util/Yamls.kt b/core/src/main/kotlin/kr/toxicity/model/util/Yamls.kt new file mode 100644 index 0000000..21da509 --- /dev/null +++ b/core/src/main/kotlin/kr/toxicity/model/util/Yamls.kt @@ -0,0 +1,12 @@ +package kr.toxicity.model.util + +import org.bukkit.configuration.file.YamlConfiguration +import java.io.File +import java.io.InputStream +import java.io.InputStreamReader +import java.nio.charset.StandardCharsets + +fun File.toYaml() = YamlConfiguration.loadConfiguration(this) +fun InputStream.toYaml() = InputStreamReader(this, StandardCharsets.UTF_8).buffered().use { + YamlConfiguration.loadConfiguration(it) +} \ No newline at end of file diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml new file mode 100644 index 0000000..388eaad --- /dev/null +++ b/core/src/main/resources/config.yml @@ -0,0 +1,5 @@ +metrics: true +sight-trace: true +item: leather_horse_armor +max-sight: 45 +min-sight: 5 \ No newline at end of file diff --git a/nms/v1_20_R3/src/main/kotlin/kr/toxicity/model/nms/v1_20_R3/NMSImpl.kt b/nms/v1_20_R3/src/main/kotlin/kr/toxicity/model/nms/v1_20_R3/NMSImpl.kt index e60a2ec..8cb7388 100644 --- a/nms/v1_20_R3/src/main/kotlin/kr/toxicity/model/nms/v1_20_R3/NMSImpl.kt +++ b/nms/v1_20_R3/src/main/kotlin/kr/toxicity/model/nms/v1_20_R3/NMSImpl.kt @@ -5,7 +5,7 @@ import com.mojang.datafixers.util.Pair import io.netty.channel.ChannelDuplexHandler import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelPromise -import kr.toxicity.model.api.ModelRenderer +import kr.toxicity.model.api.BetterModel import kr.toxicity.model.api.data.blueprint.NamedBoundingBox import kr.toxicity.model.api.nms.* import kr.toxicity.model.api.tracker.EntityTracker @@ -45,7 +45,7 @@ import kotlin.math.roundToInt class NMSImpl : NMS { companion object { - private const val INJECT_NAME = "betterengine_channel_handler" + private const val INJECT_NAME = "bettermodel_channel_handler" private val hitBoxMap = ConcurrentHashMap() @Suppress("UNCHECKED_CAST") @@ -146,7 +146,7 @@ class NMSImpl : NMS { when (msg) { is ClientboundAddEntityPacket -> { msg.id.toEntity()?.let { e -> - Bukkit.getRegionScheduler().run(ModelRenderer.inst(), e.bukkitEntity.location) { + Bukkit.getRegionScheduler().run(BetterModel.inst(), e.bukkitEntity.location) { EntityTracker.tracker(e.bukkitEntity)?.spawn(player) } } @@ -243,7 +243,7 @@ class NMSImpl : NMS { bundler.unwrap().add(removePacket) } - override fun teleport(location: Location) { + override fun teleport(location: Location, bundler: PacketBundler) { display.moveTo( location.x, location.y, @@ -251,6 +251,7 @@ class NMSImpl : NMS { location.yaw, 0F ) + bundler.unwrap().add(ClientboundTeleportEntityPacket(display)) } private var itemChanged = false diff --git a/nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/NMSImpl.kt b/nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/NMSImpl.kt index d042836..15ec2cf 100644 --- a/nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/NMSImpl.kt +++ b/nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/NMSImpl.kt @@ -5,7 +5,7 @@ import com.mojang.datafixers.util.Pair import io.netty.channel.ChannelDuplexHandler import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelPromise -import kr.toxicity.model.api.ModelRenderer +import kr.toxicity.model.api.BetterModel import kr.toxicity.model.api.data.blueprint.NamedBoundingBox import kr.toxicity.model.api.nms.* import kr.toxicity.model.api.tracker.EntityTracker @@ -39,7 +39,7 @@ import java.util.concurrent.ConcurrentHashMap class NMSImpl : NMS { companion object { - private const val INJECT_NAME = "betterengine_channel_handler" + private const val INJECT_NAME = "bettermodel_channel_handler" private val hitBoxMap = ConcurrentHashMap() private fun Class<*>.serializers() = declaredFields.filter { f -> @@ -132,7 +132,7 @@ class NMSImpl : NMS { when (msg) { is ClientboundAddEntityPacket -> { msg.id.toEntity()?.let { e -> - Bukkit.getRegionScheduler().run(ModelRenderer.inst(), e.bukkitEntity.location) { + Bukkit.getRegionScheduler().run(BetterModel.inst(), e.bukkitEntity.location) { EntityTracker.tracker(e.bukkitEntity)?.spawn(player) } } @@ -229,7 +229,7 @@ class NMSImpl : NMS { bundler.unwrap().add(removePacket) } - override fun teleport(location: Location) { + override fun teleport(location: Location, bundler: PacketBundler) { display.moveTo( location.x, location.y, @@ -237,6 +237,7 @@ class NMSImpl : NMS { location.yaw, 0F ) + bundler.unwrap().add(ClientboundTeleportEntityPacket(display)) } private var itemChanged = false diff --git a/nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/NMSImpl.kt b/nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/NMSImpl.kt index 59fe795..e7a1152 100644 --- a/nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/NMSImpl.kt +++ b/nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/NMSImpl.kt @@ -5,7 +5,7 @@ import com.mojang.datafixers.util.Pair import io.netty.channel.ChannelDuplexHandler import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelPromise -import kr.toxicity.model.api.ModelRenderer +import kr.toxicity.model.api.BetterModel import kr.toxicity.model.api.data.blueprint.NamedBoundingBox import kr.toxicity.model.api.nms.* import kr.toxicity.model.api.tracker.EntityTracker @@ -42,7 +42,7 @@ import java.util.concurrent.ConcurrentHashMap class NMSImpl : NMS { companion object { - private const val INJECT_NAME = "betterengine_channel_handler" + private const val INJECT_NAME = "bettermodel_channel_handler" private val hitBoxMap = ConcurrentHashMap() private fun Class<*>.serializers() = declaredFields.filter { f -> @@ -135,7 +135,7 @@ class NMSImpl : NMS { when (msg) { is ClientboundAddEntityPacket -> { msg.id.toEntity()?.let { e -> - Bukkit.getRegionScheduler().run(ModelRenderer.inst(), e.bukkitEntity.location) { + Bukkit.getRegionScheduler().run(BetterModel.inst(), e.bukkitEntity.location) { EntityTracker.tracker(e.bukkitEntity)?.spawn(player) } } @@ -232,7 +232,7 @@ class NMSImpl : NMS { bundler.unwrap().add(removePacket) } - override fun teleport(location: Location) { + override fun teleport(location: Location, bundler: PacketBundler) { display.moveTo( location.x, location.y, @@ -240,6 +240,7 @@ class NMSImpl : NMS { location.yaw, 0F ) + bundler.unwrap().add(ClientboundTeleportEntityPacket(display)) } private var itemChanged = false diff --git a/nms/v1_21_R2/src/main/kotlin/kr/toxicity/model/nms/v1_21_R2/NMSImpl.kt b/nms/v1_21_R2/src/main/kotlin/kr/toxicity/model/nms/v1_21_R2/NMSImpl.kt index 2c627af..e03b6dd 100644 --- a/nms/v1_21_R2/src/main/kotlin/kr/toxicity/model/nms/v1_21_R2/NMSImpl.kt +++ b/nms/v1_21_R2/src/main/kotlin/kr/toxicity/model/nms/v1_21_R2/NMSImpl.kt @@ -5,7 +5,7 @@ import com.mojang.datafixers.util.Pair import io.netty.channel.ChannelDuplexHandler import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelPromise -import kr.toxicity.model.api.ModelRenderer +import kr.toxicity.model.api.BetterModel import kr.toxicity.model.api.data.blueprint.NamedBoundingBox import kr.toxicity.model.api.nms.* import kr.toxicity.model.api.tracker.EntityTracker @@ -14,11 +14,8 @@ import net.minecraft.network.protocol.Packet import net.minecraft.network.protocol.game.* import net.minecraft.network.syncher.EntityDataAccessor import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.Display +import net.minecraft.world.entity.* import net.minecraft.world.entity.Display.ItemDisplay -import net.minecraft.world.entity.Entity -import net.minecraft.world.entity.EntityType -import net.minecraft.world.entity.EquipmentSlot import net.minecraft.world.entity.ai.attributes.Attributes import net.minecraft.world.item.ItemDisplayContext import net.minecraft.world.item.Items @@ -42,7 +39,7 @@ import java.util.concurrent.ConcurrentHashMap class NMSImpl : NMS { companion object { - private const val INJECT_NAME = "betterengine_channel_handler" + private const val INJECT_NAME = "bettermodel_channel_handler" private val hitBoxMap = ConcurrentHashMap() private fun Class<*>.serializers() = declaredFields.filter { f -> @@ -136,7 +133,7 @@ class NMSImpl : NMS { when (msg) { is ClientboundAddEntityPacket -> { msg.id.toEntity()?.let { e -> - Bukkit.getRegionScheduler().run(ModelRenderer.inst(), e.bukkitEntity.location) { + Bukkit.getRegionScheduler().run(BetterModel.inst(), e.bukkitEntity.location) { EntityTracker.tracker(e.bukkitEntity)?.spawn(player) } } @@ -233,7 +230,7 @@ class NMSImpl : NMS { bundler.unwrap().add(removePacket) } - override fun teleport(location: Location) { + override fun teleport(location: Location, bundler: PacketBundler) { display.moveTo( location.x, location.y, @@ -241,6 +238,7 @@ class NMSImpl : NMS { location.yaw, 0F ) + bundler.unwrap().add(ClientboundTeleportEntityPacket.teleport(display.id, PositionMoveRotation.of(display), emptySet(), display.onGround)) } private var itemChanged = false diff --git a/nms/v1_21_R3/src/main/kotlin/kr/toxicity/model/nms/v1_21_R3/NMSImpl.kt b/nms/v1_21_R3/src/main/kotlin/kr/toxicity/model/nms/v1_21_R3/NMSImpl.kt index f7963d0..604774c 100644 --- a/nms/v1_21_R3/src/main/kotlin/kr/toxicity/model/nms/v1_21_R3/NMSImpl.kt +++ b/nms/v1_21_R3/src/main/kotlin/kr/toxicity/model/nms/v1_21_R3/NMSImpl.kt @@ -5,7 +5,7 @@ import com.mojang.datafixers.util.Pair import io.netty.channel.ChannelDuplexHandler import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelPromise -import kr.toxicity.model.api.ModelRenderer +import kr.toxicity.model.api.BetterModel import kr.toxicity.model.api.data.blueprint.NamedBoundingBox import kr.toxicity.model.api.nms.* import kr.toxicity.model.api.tracker.EntityTracker @@ -15,11 +15,8 @@ import net.minecraft.network.protocol.Packet import net.minecraft.network.protocol.game.* import net.minecraft.network.syncher.EntityDataAccessor import net.minecraft.server.MinecraftServer -import net.minecraft.world.entity.Display +import net.minecraft.world.entity.* import net.minecraft.world.entity.Display.ItemDisplay -import net.minecraft.world.entity.Entity -import net.minecraft.world.entity.EntityType -import net.minecraft.world.entity.EquipmentSlot import net.minecraft.world.entity.ai.attributes.Attributes import net.minecraft.world.item.ItemDisplayContext import net.minecraft.world.item.Items @@ -43,7 +40,7 @@ import java.util.concurrent.ConcurrentHashMap class NMSImpl : NMS { companion object { - private const val INJECT_NAME = "betterengine_channel_handler" + private const val INJECT_NAME = "bettermodel_channel_handler" private val hitBoxMap = ConcurrentHashMap() private fun Class<*>.serializers() = declaredFields.filter { f -> @@ -137,7 +134,7 @@ class NMSImpl : NMS { when (msg) { is ClientboundAddEntityPacket -> { msg.id.toEntity()?.let { e -> - Bukkit.getRegionScheduler().run(ModelRenderer.inst(), e.bukkitEntity.location) { + Bukkit.getRegionScheduler().run(BetterModel.inst(), e.bukkitEntity.location) { EntityTracker.tracker(e.bukkitEntity)?.spawn(player) } } @@ -234,7 +231,7 @@ class NMSImpl : NMS { bundler.unwrap().add(removePacket) } - override fun teleport(location: Location) { + override fun teleport(location: Location, bundler: PacketBundler) { display.moveTo( location.x, location.y, @@ -242,6 +239,7 @@ class NMSImpl : NMS { location.yaw, 0F ) + bundler.unwrap().add(ClientboundTeleportEntityPacket.teleport(display.id, PositionMoveRotation.of(display), emptySet(), display.onGround)) } private var itemChanged = false diff --git a/settings.gradle.kts b/settings.gradle.kts index f5d0d7f..c45f54d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" } -rootProject.name = "ModelRenderer" +rootProject.name = "BetterModel" include( "api",