Skip to content

Commit

Permalink
Rename and refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 26, 2024
1 parent 939c48b commit b88ff2c
Show file tree
Hide file tree
Showing 39 changed files with 284 additions and 135 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ModelRenderer
# BetterModel
This plugin is still on developing!

### TODO
Expand Down
60 changes: 56 additions & 4 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

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() {
if (instance != null) throw new RuntimeException();
instance = this;
}

public static @NotNull ModelRenderer inst() {
public static @NotNull BetterModel inst() {
return Objects.requireNonNull(instance);
}

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ public record ModelBlueprint(
);
}

public @NotNull List<BlueprintJson> buildJson(int tint) {
var list = new ArrayList<BlueprintJson>();
for (BlueprintChildren blueprintChildren : group) {
switch (blueprintChildren) {
case BlueprintChildren.BlueprintElement blueprintElement -> {
}
case BlueprintChildren.BlueprintGroup blueprintGroup -> blueprintGroup.buildJson(tint,this, list);
}
}
return list;
}

public @NotNull List<BlueprintImage> buildImage() {
var list = new ArrayList<BlueprintImage>();
for (BlueprintTexture texture : textures) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -95,7 +95,7 @@ public boolean addAnimationMovementModifier(@NotNull Predicate<RenderedEntity> 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);
Expand Down Expand Up @@ -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));
Expand All @@ -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<RenderedEntity> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -78,7 +78,7 @@ public void createHitBox(@NotNull Entity entity, @NotNull Predicate<RenderedEnti
hitBox.remove();
if (l == null) l = hitBox.listener();
}
hitBox = ModelRenderer.inst().nms().createHitBox(entity, this, h, l != null ? l : HitBoxListener.EMPTY);
hitBox = BetterModel.inst().nms().createHitBox(entity, this, h, l != null ? l : HitBoxListener.EMPTY);
}
for (RenderedEntity value : children.values()) {
value.createHitBox(entity, predicate, listener);
Expand Down Expand Up @@ -248,7 +248,7 @@ public void tint(boolean toggle, @NotNull PacketBundler bundler) {

private boolean applyItem() {
if (display != null) {
display.item(visible ? ModelRenderer.inst().nms().tint(itemStack.clone(), tint) : new ItemStack(Material.AIR));
display.item(visible ? BetterModel.inst().nms().tint(itemStack.clone(), tint) : new ItemStack(Material.AIR));
return true;
} else return false;
}
Expand All @@ -257,9 +257,9 @@ private boolean applyItem() {
return getGroup().getName();
}

public void teleport(@NotNull Location location) {
if (display != null) display.teleport(location);
children.values().forEach(e -> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions api/src/main/java/kr/toxicity/model/api/manager/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -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();
}
10 changes: 10 additions & 0 deletions api/src/main/java/kr/toxicity/model/api/manager/ModelManager.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
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);
@NotNull @Unmodifiable
List<BlueprintRenderer> renderers();
@NotNull @Unmodifiable
Set<String> keys();

default @Nullable EntityTracker tracker(@NotNull Entity entity) {
return EntityTracker.tracker(entity);
}
default @Nullable EntityTracker tracker(@NotNull UUID uuid) {
return EntityTracker.tracker(uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions api/src/main/java/kr/toxicity/model/api/tracker/EntityTracker.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 -> {
Expand All @@ -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();
});
}
Expand Down Expand Up @@ -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);
Expand All @@ -142,16 +142,16 @@ 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);
}

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);
}
Expand Down
Loading

0 comments on commit b88ff2c

Please sign in to comment.