From ae21d857408452714fc0f84d70083730da650641 Mon Sep 17 00:00:00 2001
From: Tofaa <82680183+Tofaa2@users.noreply.github.com>
Date: Mon, 5 Feb 2024 23:09:12 +0400
Subject: [PATCH] fix broken protocol values
---
.idea/workspace.xml | 50 +++++++----
.../java/me/tofaa/entitylib/APIConfig.java | 2 +
.../me/tofaa/entitylib/EntityIdProvider.java | 5 ++
.../java/me/tofaa/entitylib/extras/Color.java | 55 ++++++++++++
.../me/tofaa/entitylib/extras/DyeColor.java | 85 +++++++++++++++++++
.../me/tofaa/entitylib/extras/Rotation.java | 38 +++++++++
.../entitylib/meta/mobs/tameable/CatMeta.java | 3 +-
.../tofaa/entitylib/tick/TickContainer.java | 4 +-
.../wrapper/WrapperEntityCreature.java | 2 +-
.../tofaa/entitylib/wrapper/ai/AIGroup.java | 11 +++
.../common/AbstractWorldWrapper.java | 2 +-
test-plugin/build.gradle | 2 +-
.../testentitylib/TestEntityLibPlugin.java | 9 +-
13 files changed, 241 insertions(+), 27 deletions(-)
create mode 100644 api/src/main/java/me/tofaa/entitylib/extras/Color.java
create mode 100644 api/src/main/java/me/tofaa/entitylib/extras/DyeColor.java
create mode 100644 api/src/main/java/me/tofaa/entitylib/extras/Rotation.java
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 19d8f43..fcc317b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,19 +5,17 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -48,6 +46,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -97,7 +113,7 @@
"ignore.virus.scanning.warn.message": "true",
"jdk.selected.JAVA_MODULE": "corretto-17",
"kotlin-language-version-configured": "true",
- "last_opened_file_path": "D:/Github/EntityLib/api/src/main/java/me/tofaa/entitylib/meta",
+ "last_opened_file_path": "D:/Github/EntityLib/api/src/main/java/me/tofaa/entitylib/extras",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
@@ -112,11 +128,12 @@
}
+
-
+
@@ -220,9 +237,9 @@
+
-
@@ -280,7 +297,8 @@
-
+
+
diff --git a/api/src/main/java/me/tofaa/entitylib/APIConfig.java b/api/src/main/java/me/tofaa/entitylib/APIConfig.java
index b9f09f8..648644c 100644
--- a/api/src/main/java/me/tofaa/entitylib/APIConfig.java
+++ b/api/src/main/java/me/tofaa/entitylib/APIConfig.java
@@ -3,6 +3,7 @@ package me.tofaa.entitylib;
import com.github.retrooper.packetevents.PacketEventsAPI;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
+import org.jetbrains.annotations.Blocking;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -24,6 +25,7 @@ public final class APIConfig {
this.packetEvents = packetEvents;
}
+ @Blocking
public boolean requiresUpdate() throws IOException {
if (!checkForUpdates) return false;
String urlString = "https://api.github.com/repos/Tofaa2/EntityLib/releases/latest";
diff --git a/api/src/main/java/me/tofaa/entitylib/EntityIdProvider.java b/api/src/main/java/me/tofaa/entitylib/EntityIdProvider.java
index 2dc3a17..1426684 100644
--- a/api/src/main/java/me/tofaa/entitylib/EntityIdProvider.java
+++ b/api/src/main/java/me/tofaa/entitylib/EntityIdProvider.java
@@ -6,6 +6,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
+/**
+ * Represents a int provider that gives an id for each entity created. When using EntityLib with platform specific entities (Such as bukkit entities), make sure the id's do not
+ * conflict with the platform's entity id's.
+ * {@link DefaultEntityIdProvider} is a default implementation of this interface.
+ */
public interface EntityIdProvider {
int provide(@NotNull UUID entityUUID, @NotNull EntityType entityType);
diff --git a/api/src/main/java/me/tofaa/entitylib/extras/Color.java b/api/src/main/java/me/tofaa/entitylib/extras/Color.java
new file mode 100644
index 0000000..8feba87
--- /dev/null
+++ b/api/src/main/java/me/tofaa/entitylib/extras/Color.java
@@ -0,0 +1,55 @@
+package me.tofaa.entitylib.extras;
+
+import net.kyori.adventure.util.RGBLike;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Range;
+
+public final class Color implements RGBLike {
+
+ private static final int BIT_MASK = 0xFF;
+
+ private final int red, green, blue;
+
+ public Color(@Range(from = 0L, to = 255L) int red, @Range(from = 0L, to = 255L) int green, @Range(from = 0L, to = 255L) int blue) {
+ this.red = red;
+ this.green = green;
+ this.blue = blue;
+ }
+
+ public Color(int rgb) {
+ this((rgb >> 16) & BIT_MASK, (rgb >> 8) & BIT_MASK, rgb & BIT_MASK);
+ }
+
+ public @NotNull Color withRed(@Range(from = 0L, to = 255L) int red) {
+ return new Color(red, green, blue);
+ }
+
+ public @NotNull Color withGreen(@Range(from = 0L, to = 255L) int green) {
+ return new Color(red, green, blue);
+ }
+
+ public @NotNull Color withBlue(@Range(from = 0L, to = 255L) int blue) {
+ return new Color(red, green, blue);
+ }
+
+ public int asRGB() {
+ int rgb = red;
+ rgb = (rgb << 8) + green;
+ return (rgb << 8) + blue;
+ }
+
+ @Override
+ public @Range(from = 0L, to = 255L) int red() {
+ return red;
+ }
+
+ @Override
+ public @Range(from = 0L, to = 255L) int green() {
+ return green;
+ }
+
+ @Override
+ public @Range(from = 0L, to = 255L) int blue() {
+ return blue;
+ }
+}
diff --git a/api/src/main/java/me/tofaa/entitylib/extras/DyeColor.java b/api/src/main/java/me/tofaa/entitylib/extras/DyeColor.java
new file mode 100644
index 0000000..798036f
--- /dev/null
+++ b/api/src/main/java/me/tofaa/entitylib/extras/DyeColor.java
@@ -0,0 +1,85 @@
+package me.tofaa.entitylib.extras;
+
+import net.kyori.adventure.util.RGBLike;
+import org.jetbrains.annotations.NotNull;
+
+public enum DyeColor implements RGBLike {
+ WHITE(new Color(0xf9fffe), new Color(0xffffff), new Color(0xf0f0f0), 8),
+
+ ORANGE(new Color(0xf9801d), new Color(0xff681f), new Color(0xeb8844), 15),
+
+ MAGENTA(new Color(0xc74ebd), new Color(0xff00ff), new Color(0xc354cd), 16),
+
+ LIGHT_BLUE(new Color(0x3ab3da), new Color(0x9ac0cd), new Color(0x6689d3), 17),
+
+ YELLOW(new Color(0xfed83d), new Color(0xffff00), new Color(0xdecf2a), 18),
+
+ LIME(new Color(0x80c71f), new Color(0xbfff00), new Color(0x41cd34), 19),
+
+ PINK(new Color(0xf38baa), new Color(0xff69b4), new Color(0xd88198), 20),
+
+ GRAY(new Color(0x474f52), new Color(0x808080), new Color(0x434343), 21),
+
+ LIGHT_GRAY(new Color(0x9d9d97), new Color(0xd3d3d3), new Color(0xababab), 22),
+
+ CYAN(new Color(0x169c9c), new Color(0xffff), new Color(0x287697), 23),
+
+ PURPLE(new Color(0x8932b8), new Color(0xa020f0), new Color(0x7b2fbe), 24),
+
+ BLUE(new Color(0x3c44aa), new Color(0xff), new Color(0x253192), 25),
+
+ BROWN(new Color(0x835432), new Color(0x8b4513), new Color(0x51301a), 26),
+
+ GREEN(new Color(0x5e7c16), new Color(0xff00), new Color(0x3b511a), 27),
+
+ RED(new Color(0xb02e26), new Color(0xff0000), new Color(0xb3312c), 28),
+
+ BLACK(new Color(0x1d1d21), new Color(0x0), new Color(0x1e1b1b), 29);
+
+ private final Color textureDiffuseColor;
+
+ private final Color textColor;
+
+ private final Color fireworkColor;
+
+ private final int mapColorId;
+
+ DyeColor(@NotNull Color textureDiffuseColor, @NotNull Color textColor,
+ @NotNull Color fireworkColor, int mapColorId) {
+ this.textureDiffuseColor = textureDiffuseColor;
+ this.textColor = textColor;
+ this.fireworkColor = fireworkColor;
+ this.mapColorId = mapColorId;
+ }
+
+ public @NotNull Color color() {
+ return this.textureDiffuseColor;
+ }
+
+ public @NotNull Color textColor() {
+ return this.textColor;
+ }
+
+ public @NotNull Color fireworkColor() {
+ return this.fireworkColor;
+ }
+
+ @Override
+ public int red() {
+ return this.textureDiffuseColor.red();
+ }
+
+ @Override
+ public int green() {
+ return this.textureDiffuseColor.green();
+ }
+
+ @Override
+ public int blue() {
+ return this.textureDiffuseColor.blue();
+ }
+
+ public int mapColorId() {
+ return this.mapColorId;
+ }
+}
diff --git a/api/src/main/java/me/tofaa/entitylib/extras/Rotation.java b/api/src/main/java/me/tofaa/entitylib/extras/Rotation.java
new file mode 100644
index 0000000..b05b61e
--- /dev/null
+++ b/api/src/main/java/me/tofaa/entitylib/extras/Rotation.java
@@ -0,0 +1,38 @@
+package me.tofaa.entitylib.extras;
+
+public enum Rotation {
+
+ /**
+ * No rotation
+ */
+ NONE,
+ /**
+ * Rotated clockwise by 45 degrees
+ */
+ CLOCKWISE_45,
+ /**
+ * Rotated clockwise by 90 degrees
+ */
+ CLOCKWISE,
+ /**
+ * Rotated clockwise by 135 degrees
+ */
+ CLOCKWISE_135,
+ /**
+ * Flipped upside-down, a 180-degree rotation
+ */
+ FLIPPED,
+ /**
+ * Flipped upside-down + 45-degree rotation
+ */
+ FLIPPED_45,
+ /**
+ * Rotated counter-clockwise by 90 degrees
+ */
+ COUNTER_CLOCKWISE,
+ /**
+ * Rotated counter-clockwise by 45 degrees
+ */
+ COUNTER_CLOCKWISE_45;
+
+}
\ No newline at end of file
diff --git a/api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java b/api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java
index 2dde774..5dae395 100644
--- a/api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java
+++ b/api/src/main/java/me/tofaa/entitylib/meta/mobs/tameable/CatMeta.java
@@ -1,11 +1,10 @@
package me.tofaa.entitylib.meta.mobs.tameable;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
-import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import me.tofaa.entitylib.extras.DyeColor;
import me.tofaa.entitylib.meta.Metadata;
import me.tofaa.entitylib.meta.types.TameableMeta;
-import net.kyori.adventure.text.format.NamedTextColor;
+
import org.jetbrains.annotations.NotNull;
public class CatMeta extends TameableMeta {
diff --git a/api/src/main/java/me/tofaa/entitylib/tick/TickContainer.java b/api/src/main/java/me/tofaa/entitylib/tick/TickContainer.java
index f1b856f..0d9b880 100644
--- a/api/src/main/java/me/tofaa/entitylib/tick/TickContainer.java
+++ b/api/src/main/java/me/tofaa/entitylib/tick/TickContainer.java
@@ -9,11 +9,11 @@ import java.util.HashSet;
import java.util.Set;
/**
- * Represents a storage/container for {@link Tickable}s.
+ * Represents a storage/container for {@link Tickable}s. This class is extendable in case you want to provide custom logic and/or methods.
* @param The type of {@link Tickable} to store.
* @param If a platform enforces a specific method of ticking, this type represents the handler for that method.
*/
-public abstract class TickContainer {
+public class TickContainer {
private final Set tickables = new HashSet<>();
private H handle;
diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityCreature.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityCreature.java
index b797dfa..6771d15 100644
--- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityCreature.java
+++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperEntityCreature.java
@@ -32,7 +32,7 @@ public class WrapperEntityCreature extends WrapperLivingEntity {
@Override
public void tick(long time) {
super.tick(time);
- aiGroups.forEach(aiGroup -> aiGroup.update(time));
+ aiGroups.forEach(aiGroup -> aiGroup.tick(time));
}
/**
diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/ai/AIGroup.java b/api/src/main/java/me/tofaa/entitylib/wrapper/ai/AIGroup.java
index 99992b5..6818b65 100644
--- a/api/src/main/java/me/tofaa/entitylib/wrapper/ai/AIGroup.java
+++ b/api/src/main/java/me/tofaa/entitylib/wrapper/ai/AIGroup.java
@@ -11,6 +11,7 @@ public class AIGroup implements Tickable {
private final List goalSelectors = new GoalSelectorList(this);
private GoalSelector currentGoalSelector;
+ private boolean ticking = true;
public @NotNull Collection getGoalSelectors() {
return goalSelectors;
@@ -36,6 +37,16 @@ public class AIGroup implements Tickable {
currentGoalSelector = goalSelector;
}
+ @Override
+ public boolean isTicking() {
+ return ticking;
+ }
+
+ @Override
+ public void setTicking(boolean ticking) {
+ this.ticking = ticking;
+ }
+
@Override
public void tick(long time) {
GoalSelector currentGoalSelector = getCurrentGoal();
diff --git a/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java b/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java
index f203954..0bb678c 100644
--- a/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java
+++ b/common/src/main/java/me/tofaa/entitylib/common/AbstractWorldWrapper.java
@@ -31,7 +31,7 @@ public abstract class AbstractWorldWrapper implements WorldWrapper {
this.handle = handle;
this.dimension = dimension;
this.entities = new ConcurrentHashMap<>();
- this.entitiesById = Collections.emptyMap();
+ this.entitiesById = new ConcurrentHashMap<>();
}
diff --git a/test-plugin/build.gradle b/test-plugin/build.gradle
index a9755f2..29dc72d 100644
--- a/test-plugin/build.gradle
+++ b/test-plugin/build.gradle
@@ -32,6 +32,6 @@ dependencies {
tasks {
runServer {
- minecraftVersion("1.19.4")
+ minecraftVersion("1.20.4")
}
}
\ No newline at end of file
diff --git a/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java b/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java
index 812523d..849ec69 100644
--- a/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java
+++ b/test-plugin/src/main/java/me/tofaa/testentitylib/TestEntityLibPlugin.java
@@ -1,7 +1,6 @@
package me.tofaa.testentitylib;
import com.github.retrooper.packetevents.PacketEvents;
-import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import me.tofaa.entitylib.APIConfig;
@@ -43,15 +42,17 @@ public class TestEntityLibPlugin extends JavaPlugin implements Listener {
@EventHandler
public void onCrouch(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
- if (e != null) {
- e.remove();
- e = null;
+ if (e == null) {
+ world = api.wrapWorld(player.getWorld());
+ e = world.spawnEntity(EntityTypes.CHICKEN, SpigotConversionUtil.fromBukkitLocation(player.getLocation()));
}
world = api.wrapWorld(player.getWorld());
e = world.spawnEntity(EntityTypes.CHICKEN, SpigotConversionUtil.fromBukkitLocation(player.getLocation()));
ChickenMeta meta = (ChickenMeta) e.getEntityMeta();
meta.setBaby(!meta.isBaby());
meta.setHasGlowingEffect(!meta.hasGlowingEffect());
+
+ e.addViewer(player.getUniqueId());
}
}