diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 3f792c6..addaac9 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,7 +5,16 @@
+
+
+
+
+
+
+
+
+
@@ -211,7 +220,7 @@
-
+
@@ -226,6 +235,15 @@
6787
+
+ file://$PROJECT_DIR$/src/main/java/me/tofaa/entitylib/meta/types/DisplayMeta.java
+ 153
+
+
+
+
+
+
diff --git a/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java b/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java
index 96deb40..c759d5c 100644
--- a/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java
+++ b/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java
@@ -152,13 +152,6 @@ public class EntityMeta implements EntityMetadataProvider {
return metadata.createPacket();
}
-
- protected static void isVersion(ServerVersion version) {
- if (!EntityLib.getPacketEvents().getServerManager().getVersion().is(VersionComparison.EQUALS, version)) {
- throw new InvalidVersionException("This method is only available for " + version.name() + " and above.");
- }
- }
-
protected static void isVersionOlder(ServerVersion version) {
if (!EntityLib.getPacketEvents().getServerManager().getVersion().is(VersionComparison.OLDER_THAN, version)) {
throw new InvalidVersionException("This method is only available for versions older than " + version.name() + ".");
@@ -171,6 +164,14 @@ public class EntityMeta implements EntityMetadataProvider {
}
}
+ protected static boolean isVersion(ServerVersion version, VersionComparison comparison) {
+ return EntityLib.getPacketEvents().getServerManager().getVersion().is(comparison, version);
+ }
+
+ protected static boolean isVersion(ServerVersion version) {
+ return EntityLib.getPacketEvents().getServerManager().getVersion().is(VersionComparison.EQUALS, version);
+ }
+
/**
* Annoying java 8 not letting me do OFFSET + amount in the method call so this is a workaround
* @param value the value to offset
diff --git a/src/main/java/me/tofaa/entitylib/meta/display/BlockDisplayMeta.java b/src/main/java/me/tofaa/entitylib/meta/display/BlockDisplayMeta.java
index 6a7330b..80cf218 100644
--- a/src/main/java/me/tofaa/entitylib/meta/display/BlockDisplayMeta.java
+++ b/src/main/java/me/tofaa/entitylib/meta/display/BlockDisplayMeta.java
@@ -7,7 +7,7 @@ import me.tofaa.entitylib.meta.types.DisplayMeta;
public class BlockDisplayMeta extends DisplayMeta {
public static final byte OFFSET = DisplayMeta.MAX_OFFSET;
- public static final byte MAX_OFFSET = OFFSET + 1;
+ public static final byte MAX_OFFSET = offset(OFFSET, 1);
public BlockDisplayMeta(int entityId, Metadata metadata) {
super(entityId, metadata);
diff --git a/src/main/java/me/tofaa/entitylib/meta/display/ItemDisplayMeta.java b/src/main/java/me/tofaa/entitylib/meta/display/ItemDisplayMeta.java
index 79330c9..eee43fe 100644
--- a/src/main/java/me/tofaa/entitylib/meta/display/ItemDisplayMeta.java
+++ b/src/main/java/me/tofaa/entitylib/meta/display/ItemDisplayMeta.java
@@ -8,7 +8,7 @@ import me.tofaa.entitylib.meta.types.DisplayMeta;
public class ItemDisplayMeta extends DisplayMeta {
public static final byte OFFSET = DisplayMeta.MAX_OFFSET;
- public static final byte MAX_OFFSET = OFFSET + 1;
+ public static final byte MAX_OFFSET = offset(OFFSET, 1);
public ItemDisplayMeta(int entityId, Metadata metadata) {
super(entityId, metadata);
diff --git a/src/main/java/me/tofaa/entitylib/meta/display/TextDisplayMeta.java b/src/main/java/me/tofaa/entitylib/meta/display/TextDisplayMeta.java
index 94ead89..314323b 100644
--- a/src/main/java/me/tofaa/entitylib/meta/display/TextDisplayMeta.java
+++ b/src/main/java/me/tofaa/entitylib/meta/display/TextDisplayMeta.java
@@ -8,7 +8,7 @@ import net.kyori.adventure.text.Component;
public class TextDisplayMeta extends DisplayMeta {
public static final byte OFFSET = DisplayMeta.MAX_OFFSET;
- public static final byte MAX_OFFSET = OFFSET + 5;
+ public static final byte MAX_OFFSET = offset(OFFSET, 5);
private static final byte SHADOW = 1;
private static final byte SEE_THROUGH = 2;
diff --git a/src/main/java/me/tofaa/entitylib/meta/types/DisplayMeta.java b/src/main/java/me/tofaa/entitylib/meta/types/DisplayMeta.java
index 957bbb2..cd450bc 100644
--- a/src/main/java/me/tofaa/entitylib/meta/types/DisplayMeta.java
+++ b/src/main/java/me/tofaa/entitylib/meta/types/DisplayMeta.java
@@ -1,6 +1,7 @@
package me.tofaa.entitylib.meta.types;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
+import com.github.retrooper.packetevents.manager.server.VersionComparison;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.util.Quaternion4f;
import com.github.retrooper.packetevents.util.Vector3f;
@@ -10,7 +11,15 @@ import me.tofaa.entitylib.meta.Metadata;
public class DisplayMeta extends EntityMeta {
public static final byte OFFSET = EntityMeta.MAX_OFFSET;
- public static final byte MAX_OFFSET = OFFSET + 15;
+ public static final byte MAX_OFFSET;
+ static {
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.NEWER_THAN_OR_EQUALS)) {
+ MAX_OFFSET = OFFSET + 15;
+ }
+ else {
+ MAX_OFFSET = OFFSET + 14;
+ }
+ }
public DisplayMeta(int entityId, Metadata metadata) {
super(entityId, metadata);
@@ -42,43 +51,83 @@ public class DisplayMeta extends EntityMeta {
}
public Vector3f getTranslation() {
- return super.metadata.getIndex(offset(OFFSET, 3), Vector3f.zero());
+ byte offset = offset(OFFSET, 3);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 2);
+ }
+ return super.metadata.getIndex(offset, Vector3f.zero());
}
public void setTranslation(Vector3f value) {
- super.metadata.setIndex(offset(OFFSET, 3), EntityDataTypes.VECTOR3F, value);
+ byte offset = offset(OFFSET, 3);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 2);
+ }
+ super.metadata.setIndex(offset, EntityDataTypes.VECTOR3F, value);
}
public Vector3f getScale() {
- return super.metadata.getIndex(offset(OFFSET, 4), new Vector3f(1.0f, 1.0f, 1.0f));
+ byte offset = offset(OFFSET, 4);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 3);
+ }
+ return super.metadata.getIndex(offset, new Vector3f(1.0f, 1.0f, 1.0f));
}
public void setScale(Vector3f value) {
- super.metadata.setIndex(offset(OFFSET, 4), EntityDataTypes.VECTOR3F, value);
+ byte offset = offset(OFFSET, 4);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 3);
+ }
+ super.metadata.setIndex(offset, EntityDataTypes.VECTOR3F, value);
}
public Quaternion4f getLeftRotation() {
- return super.metadata.getIndex(offset(OFFSET, 5), new Quaternion4f(0.0f, 0.0f, 0.0f, 1.0f));
+ byte offset = offset(OFFSET, 5);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 4);
+ }
+ return super.metadata.getIndex(offset, new Quaternion4f(0.0f, 0.0f, 0.0f, 1.0f));
}
public void setLeftRotation(Quaternion4f value) {
- super.metadata.setIndex(offset(OFFSET, 5), EntityDataTypes.QUATERNION, value);
+ byte offset = offset(OFFSET, 5);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 4);
+ }
+ super.metadata.setIndex(offset, EntityDataTypes.QUATERNION, value);
}
public Quaternion4f getRightRotation() {
- return super.metadata.getIndex(offset(OFFSET, 6), new Quaternion4f(0.0f, 0.0f, 0.0f, 1.0f));
+ byte offset = offset(OFFSET, 6);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 5);
+ }
+ return super.metadata.getIndex(offset, new Quaternion4f(0.0f, 0.0f, 0.0f, 1.0f));
}
public void setRightRotation(Quaternion4f value) {
- super.metadata.setIndex(offset(OFFSET, 6), EntityDataTypes.QUATERNION, value);
+ byte offset = offset(OFFSET, 6);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 5);
+ }
+ super.metadata.setIndex(offset, EntityDataTypes.QUATERNION, value);
}
public BillboardConstraints getBillboardConstraints() {
- return BillboardConstraints.VALUES[super.metadata.getIndex(offset(OFFSET, 7), (byte) 0)];
+ byte offset = offset(OFFSET, 7);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 6);
+ }
+ return BillboardConstraints.VALUES[super.metadata.getIndex(offset, (byte) 0)];
}
public void setBillboardConstraints(BillboardConstraints value) {
- super.metadata.setIndex(offset(OFFSET, 7), EntityDataTypes.BYTE, (byte) value.ordinal());
+ byte offset = offset(OFFSET, 7);
+ if (isVersion(ServerVersion.V_1_20_2, VersionComparison.OLDER_THAN)) {
+ offset = offset(OFFSET, 6);
+ }
+ super.metadata.setIndex(offset, EntityDataTypes.BYTE, (byte) value.ordinal());
}
//(blockLight << 4 | skyLight << 20)
diff --git a/test-plugin/build.gradle b/test-plugin/build.gradle
index 4e03610..f8a7b47 100644
--- a/test-plugin/build.gradle
+++ b/test-plugin/build.gradle
@@ -32,6 +32,6 @@ dependencies {
tasks {
runServer {
- minecraftVersion("1.20.4")
+ minecraftVersion("1.19.4")
}
}
\ No newline at end of file
diff --git a/test-plugin/src/main/java/me/tofaa/entitylib/TestCommand.java b/test-plugin/src/main/java/me/tofaa/entitylib/TestCommand.java
index d5e13f8..60d4267 100644
--- a/test-plugin/src/main/java/me/tofaa/entitylib/TestCommand.java
+++ b/test-plugin/src/main/java/me/tofaa/entitylib/TestCommand.java
@@ -40,7 +40,7 @@ public class TestCommand implements CommandExecutor {
passenger.addViewer(player.getUniqueId());
base.spawn(location);
passenger.spawn(pass);
- base.addPassenger(passenger);
+ base.addPassenger(player.getEntityId());
player.sendMessage("Spawned");
return true;
diff --git a/test-plugin/src/main/java/me/tofaa/entitylib/TestDisplayCommand.java b/test-plugin/src/main/java/me/tofaa/entitylib/TestDisplayCommand.java
index 0a97087..b003f08 100644
--- a/test-plugin/src/main/java/me/tofaa/entitylib/TestDisplayCommand.java
+++ b/test-plugin/src/main/java/me/tofaa/entitylib/TestDisplayCommand.java
@@ -66,6 +66,7 @@ public class TestDisplayCommand implements CommandExecutor, TabCompleter {
meta.setHasGlowingEffect(true);
meta.setText(Component.text("Hello World!"));
meta.setBillboardConstraints(DisplayMeta.BillboardConstraints.CENTER);
+ meta.setTranslation(new Vector3f(4.0f, 0.0f, 0.0f));
meta.setScale(new Vector3f(2, 2, 2));
e.addViewer(player.getUniqueId());
e.spawn(fromPlayer(player));
diff --git a/test-plugin/src/main/resources/plugin.yml b/test-plugin/src/main/resources/plugin.yml
index 7467116..6fbc2c9 100644
--- a/test-plugin/src/main/resources/plugin.yml
+++ b/test-plugin/src/main/resources/plugin.yml
@@ -3,7 +3,7 @@ version: 1.0.0
depend:
- packetevents
main: me.tofaa.entitylib.EntityLibPlugin
-api-version: 1.20
+api-version: "1.19"
commands:
testapi:
description: Test PEEntityMeta API