From 6ef80e00c73d6a2879fb3d8ceee92a3e3021484b Mon Sep 17 00:00:00 2001
From: Mooselk <44407652+Mooselk@users.noreply.github.com>
Date: Sat, 28 Nov 2020 17:23:36 -0800
Subject: [PATCH] Fix NPCState#CROUCHED for 1.14.x -> 1.16.x
---
api/pom.xml | 2 +-
nms/pom.xml | 2 +-
nms/v1_10_R1/pom.xml | 2 +-
nms/v1_11_R1/pom.xml | 2 +-
nms/v1_12_R1/pom.xml | 2 +-
nms/v1_13_R1/pom.xml | 2 +-
nms/v1_13_R2/pom.xml | 2 +-
nms/v1_14_R1/pom.xml | 2 +-
.../PacketPlayOutEntityMetadataWrapper.java | 32 +++++++----------
nms/v1_15_R1/pom.xml | 2 +-
.../PacketPlayOutEntityMetadataWrapper.java | 36 ++++++++-----------
nms/v1_16_R1/pom.xml | 2 +-
.../PacketPlayOutEntityMetadataWrapper.java | 30 ++++++----------
nms/v1_16_R2/pom.xml | 2 +-
.../PacketPlayOutEntityMetadataWrapper.java | 32 +++++------------
nms/v1_16_R3/pom.xml | 2 +-
.../PacketPlayOutEntityMetadataWrapper.java | 32 +++++------------
nms/v1_8_R3/pom.xml | 2 +-
nms/v1_9_R1/pom.xml | 2 +-
nms/v1_9_R2/pom.xml | 2 +-
plugin/pom.xml | 2 +-
pom.xml | 2 +-
22 files changed, 71 insertions(+), 125 deletions(-)
diff --git a/api/pom.xml b/api/pom.xml
index 6d38b082..2bb3fae6 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -8,7 +8,7 @@
npclib
net.jitse
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-api
diff --git a/nms/pom.xml b/nms/pom.xml
index a93426d8..6a15536a 100644
--- a/nms/pom.xml
+++ b/nms/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms
diff --git a/nms/v1_10_R1/pom.xml b/nms/v1_10_R1/pom.xml
index 98bb8374..0751e115 100755
--- a/nms/v1_10_R1/pom.xml
+++ b/nms/v1_10_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_10_R1
diff --git a/nms/v1_11_R1/pom.xml b/nms/v1_11_R1/pom.xml
index ae85fd9f..541582a8 100755
--- a/nms/v1_11_R1/pom.xml
+++ b/nms/v1_11_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_11_R1
diff --git a/nms/v1_12_R1/pom.xml b/nms/v1_12_R1/pom.xml
index f62533c0..13811ad7 100755
--- a/nms/v1_12_R1/pom.xml
+++ b/nms/v1_12_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_12_R1
diff --git a/nms/v1_13_R1/pom.xml b/nms/v1_13_R1/pom.xml
index 0fe1aee1..78a10b6f 100755
--- a/nms/v1_13_R1/pom.xml
+++ b/nms/v1_13_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_13_R1
diff --git a/nms/v1_13_R2/pom.xml b/nms/v1_13_R2/pom.xml
index 8012cc1e..267a8d83 100755
--- a/nms/v1_13_R2/pom.xml
+++ b/nms/v1_13_R2/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_13_R2
diff --git a/nms/v1_14_R1/pom.xml b/nms/v1_14_R1/pom.xml
index 8316a0e7..a4792766 100755
--- a/nms/v1_14_R1/pom.xml
+++ b/nms/v1_14_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_14_R1
diff --git a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityMetadataWrapper.java b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityMetadataWrapper.java
index a2aab265..11245755 100644
--- a/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityMetadataWrapper.java
+++ b/nms/v1_14_R1/src/main/java/net/jitse/npclib/nms/v1_14_R1/packets/PacketPlayOutEntityMetadataWrapper.java
@@ -1,37 +1,29 @@
package net.jitse.npclib.nms.v1_14_R1.packets;
+import java.util.Collection;
+
import net.jitse.npclib.api.state.NPCState;
import net.minecraft.server.v1_14_R1.DataWatcher;
import net.minecraft.server.v1_14_R1.DataWatcherObject;
import net.minecraft.server.v1_14_R1.DataWatcherRegistry;
+import net.minecraft.server.v1_14_R1.EntityPose;
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata;
-import java.util.Collection;
-
public class PacketPlayOutEntityMetadataWrapper {
public PacketPlayOutEntityMetadata create(Collection activateStates, int entityId) {
DataWatcher dataWatcher = new DataWatcher(null);
byte masked = NPCState.getMasked(activateStates);
- // TODO: Find out why NPCState#CROUCHED doesn't work.
+
+ dataWatcher.register(new DataWatcherObject(6, DataWatcherRegistry.s), getMaskedPose(activateStates));
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
-
-// for (Player online : Bukkit.getOnlinePlayers()) {
-// DataWatcher watcher = ((CraftPlayer) online).getHandle().getDataWatcher();
-// try {
-// Field entriesField = watcher.getClass().getDeclaredField("entries");
-// entriesField.setAccessible(true);
-//
-// Int2ObjectOpenHashMap> entries = (Int2ObjectOpenHashMap>) entriesField.get(watcher);
-// entries.forEach((integer, item) -> {
-// if (item.b() instanceof Boolean || item.b() instanceof Byte)
-// online.sendMessage(integer + ": " + item.b() + " type = " + item.b().getClass().toString());
-// });
-// } catch (NoSuchFieldException | IllegalAccessException e) {
-// e.printStackTrace();
-// }
-// }
-
+
return new PacketPlayOutEntityMetadata(entityId, dataWatcher, true);
}
+
+ private EntityPose getMaskedPose(Collection states) {
+ if (states.contains(NPCState.CROUCHED))
+ return EntityPose.SNEAKING;
+ return EntityPose.STANDING;
+ }
}
diff --git a/nms/v1_15_R1/pom.xml b/nms/v1_15_R1/pom.xml
index e495c1ab..025d5a39 100644
--- a/nms/v1_15_R1/pom.xml
+++ b/nms/v1_15_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_15_R1
diff --git a/nms/v1_15_R1/src/main/java/net/jitse/npclib/nms/v1_15_R1/packets/PacketPlayOutEntityMetadataWrapper.java b/nms/v1_15_R1/src/main/java/net/jitse/npclib/nms/v1_15_R1/packets/PacketPlayOutEntityMetadataWrapper.java
index 8b28392f..8a4cffb2 100644
--- a/nms/v1_15_R1/src/main/java/net/jitse/npclib/nms/v1_15_R1/packets/PacketPlayOutEntityMetadataWrapper.java
+++ b/nms/v1_15_R1/src/main/java/net/jitse/npclib/nms/v1_15_R1/packets/PacketPlayOutEntityMetadataWrapper.java
@@ -1,39 +1,31 @@
package net.jitse.npclib.nms.v1_15_R1.packets;
+import java.util.Collection;
+
import net.jitse.npclib.api.state.NPCState;
import net.minecraft.server.v1_15_R1.DataWatcher;
import net.minecraft.server.v1_15_R1.DataWatcherObject;
import net.minecraft.server.v1_15_R1.DataWatcherRegistry;
+import net.minecraft.server.v1_15_R1.EntityPose;
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata;
-import java.util.Collection;
-
public class PacketPlayOutEntityMetadataWrapper {
public PacketPlayOutEntityMetadata create(Collection activateStates, int entityId) {
DataWatcher dataWatcher = new DataWatcher(null);
- dataWatcher.register(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);
-
byte masked = NPCState.getMasked(activateStates);
- // TODO: Find out why NPCState#CROUCHED doesn't work.
+
+ dataWatcher.register(new DataWatcherObject(6, DataWatcherRegistry.s), getMaskedPose(activateStates));
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
-
-// for (Player online : Bukkit.getOnlinePlayers()) {
-// DataWatcher watcher = ((CraftPlayer) online).getHandle().getDataWatcher();
-// try {
-// Field entriesField = watcher.getClass().getDeclaredField("entries");
-// entriesField.setAccessible(true);
-//
-// Int2ObjectOpenHashMap> entries = (Int2ObjectOpenHashMap>) entriesField.get(watcher);
-// entries.forEach((integer, item) -> {
-// if (item.b() instanceof Boolean || item.b() instanceof Byte)
-// online.sendMessage(integer + ": " + item.b() + " type = " + item.b().getClass().toString());
-// });
-// } catch (NoSuchFieldException | IllegalAccessException e) {
-// e.printStackTrace();
-// }
-// }
-
+
return new PacketPlayOutEntityMetadata(entityId, dataWatcher, true);
}
+
+ private EntityPose getMaskedPose(Collection states) {
+ if (states.contains(NPCState.CROUCHED))
+ return EntityPose.CROUCHING;
+// if (states.contains(NPCState.SLEEPING))
+// return EntityPose.SLEEPING;
+ return EntityPose.STANDING;
+ }
}
diff --git a/nms/v1_16_R1/pom.xml b/nms/v1_16_R1/pom.xml
index de468717..c20c54db 100644
--- a/nms/v1_16_R1/pom.xml
+++ b/nms/v1_16_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_16_R1
diff --git a/nms/v1_16_R1/src/main/java/net/jitse/npclib/nms/v1_16_R1/packets/PacketPlayOutEntityMetadataWrapper.java b/nms/v1_16_R1/src/main/java/net/jitse/npclib/nms/v1_16_R1/packets/PacketPlayOutEntityMetadataWrapper.java
index 33017a0e..4c0e52e3 100644
--- a/nms/v1_16_R1/src/main/java/net/jitse/npclib/nms/v1_16_R1/packets/PacketPlayOutEntityMetadataWrapper.java
+++ b/nms/v1_16_R1/src/main/java/net/jitse/npclib/nms/v1_16_R1/packets/PacketPlayOutEntityMetadataWrapper.java
@@ -6,34 +6,24 @@
import net.minecraft.server.v1_16_R1.DataWatcher;
import net.minecraft.server.v1_16_R1.DataWatcherObject;
import net.minecraft.server.v1_16_R1.DataWatcherRegistry;
+import net.minecraft.server.v1_16_R1.EntityPose;
import net.minecraft.server.v1_16_R1.PacketPlayOutEntityMetadata;
public class PacketPlayOutEntityMetadataWrapper {
public PacketPlayOutEntityMetadata create(Collection activateStates, int entityId) {
DataWatcher dataWatcher = new DataWatcher(null);
- dataWatcher.register(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);
-
byte masked = NPCState.getMasked(activateStates);
- // TODO: Find out why NPCState#CROUCHED doesn't work.
+
+ dataWatcher.register(new DataWatcherObject(6, DataWatcherRegistry.s), getMaskedPose(activateStates));
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
-
-// for (Player online : Bukkit.getOnlinePlayers()) {
-// DataWatcher watcher = ((CraftPlayer) online).getHandle().getDataWatcher();
-// try {
-// Field entriesField = watcher.getClass().getDeclaredField("entries");
-// entriesField.setAccessible(true);
-//
-// Int2ObjectOpenHashMap> entries = (Int2ObjectOpenHashMap>) entriesField.get(watcher);
-// entries.forEach((integer, item) -> {
-// if (item.b() instanceof Boolean || item.b() instanceof Byte)
-// online.sendMessage(integer + ": " + item.b() + " type = " + item.b().getClass().toString());
-// });
-// } catch (NoSuchFieldException | IllegalAccessException e) {
-// e.printStackTrace();
-// }
-// }
-
+
return new PacketPlayOutEntityMetadata(entityId, dataWatcher, true);
}
+
+ private EntityPose getMaskedPose(Collection states) {
+ if (states.contains(NPCState.CROUCHED))
+ return EntityPose.CROUCHING;
+ return EntityPose.STANDING;
+ }
}
diff --git a/nms/v1_16_R2/pom.xml b/nms/v1_16_R2/pom.xml
index 6774d998..07d5aad5 100644
--- a/nms/v1_16_R2/pom.xml
+++ b/nms/v1_16_R2/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_16_R2
diff --git a/nms/v1_16_R2/src/main/java/net/jitse/npclib/nms/v1_16_R2/packets/PacketPlayOutEntityMetadataWrapper.java b/nms/v1_16_R2/src/main/java/net/jitse/npclib/nms/v1_16_R2/packets/PacketPlayOutEntityMetadataWrapper.java
index b6a724b9..65276599 100644
--- a/nms/v1_16_R2/src/main/java/net/jitse/npclib/nms/v1_16_R2/packets/PacketPlayOutEntityMetadataWrapper.java
+++ b/nms/v1_16_R2/src/main/java/net/jitse/npclib/nms/v1_16_R2/packets/PacketPlayOutEntityMetadataWrapper.java
@@ -6,38 +6,24 @@
import net.minecraft.server.v1_16_R2.DataWatcher;
import net.minecraft.server.v1_16_R2.DataWatcherObject;
import net.minecraft.server.v1_16_R2.DataWatcherRegistry;
+import net.minecraft.server.v1_16_R2.EntityPose;
import net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata;
public class PacketPlayOutEntityMetadataWrapper {
public PacketPlayOutEntityMetadata create(Collection activateStates, int entityId) {
DataWatcher dataWatcher = new DataWatcher(null);
- dataWatcher.register(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);
-
byte masked = NPCState.getMasked(activateStates);
- // TODO: Find out why NPCState#CROUCHED doesn't work.
- dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
-
-// for (Player online : Bukkit.getOnlinePlayers()) {
-// DataWatcher watcher = ((CraftPlayer) online).getHandle().getDataWatcher();
-// try {
-// Field entriesField = watcher.getClass().getDeclaredField("entries");
-// entriesField.setAccessible(true);
-//
-// Int2ObjectOpenHashMap> entries = (Int2ObjectOpenHashMap>) entriesField.get(watcher);
-// entries.forEach((integer, item) -> {
-// if (item.b() instanceof Boolean || item.b() instanceof Byte)
-// online.sendMessage(integer + ": " + item.b() + " type = " + item.b().getClass().toString());
-// });
-// } catch (NoSuchFieldException | IllegalAccessException e) {
-// e.printStackTrace();
-// }
-// }
- // Pose pose = Pose.SNEAKING;
+ dataWatcher.register(new DataWatcherObject(6, DataWatcherRegistry.s), getMaskedPose(activateStates));
+ dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
- // dataWatcher.set(DataWatcherRegistry.s.a(6), EntityPose.values()[pose.ordinal()]);
-
return new PacketPlayOutEntityMetadata(entityId, dataWatcher, true);
}
+
+ private EntityPose getMaskedPose(Collection states) {
+ if (states.contains(NPCState.CROUCHED))
+ return EntityPose.CROUCHING;
+ return EntityPose.STANDING;
+ }
}
diff --git a/nms/v1_16_R3/pom.xml b/nms/v1_16_R3/pom.xml
index cd5ec5ce..1abb9650 100644
--- a/nms/v1_16_R3/pom.xml
+++ b/nms/v1_16_R3/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_16_R3
diff --git a/nms/v1_16_R3/src/main/java/net/jitse/npclib/nms/v1_16_R3/packets/PacketPlayOutEntityMetadataWrapper.java b/nms/v1_16_R3/src/main/java/net/jitse/npclib/nms/v1_16_R3/packets/PacketPlayOutEntityMetadataWrapper.java
index 97ac2ab6..914a463d 100644
--- a/nms/v1_16_R3/src/main/java/net/jitse/npclib/nms/v1_16_R3/packets/PacketPlayOutEntityMetadataWrapper.java
+++ b/nms/v1_16_R3/src/main/java/net/jitse/npclib/nms/v1_16_R3/packets/PacketPlayOutEntityMetadataWrapper.java
@@ -6,38 +6,24 @@
import net.minecraft.server.v1_16_R3.DataWatcher;
import net.minecraft.server.v1_16_R3.DataWatcherObject;
import net.minecraft.server.v1_16_R3.DataWatcherRegistry;
+import net.minecraft.server.v1_16_R3.EntityPose;
import net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata;
public class PacketPlayOutEntityMetadataWrapper {
public PacketPlayOutEntityMetadata create(Collection activateStates, int entityId) {
DataWatcher dataWatcher = new DataWatcher(null);
- dataWatcher.register(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);
-
byte masked = NPCState.getMasked(activateStates);
- // TODO: Find out why NPCState#CROUCHED doesn't work.
- dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
-
-// for (Player online : Bukkit.getOnlinePlayers()) {
-// DataWatcher watcher = ((CraftPlayer) online).getHandle().getDataWatcher();
-// try {
-// Field entriesField = watcher.getClass().getDeclaredField("entries");
-// entriesField.setAccessible(true);
-//
-// Int2ObjectOpenHashMap> entries = (Int2ObjectOpenHashMap>) entriesField.get(watcher);
-// entries.forEach((integer, item) -> {
-// if (item.b() instanceof Boolean || item.b() instanceof Byte)
-// online.sendMessage(integer + ": " + item.b() + " type = " + item.b().getClass().toString());
-// });
-// } catch (NoSuchFieldException | IllegalAccessException e) {
-// e.printStackTrace();
-// }
-// }
- // Pose pose = Pose.SNEAKING;
+ dataWatcher.register(new DataWatcherObject(6, DataWatcherRegistry.s), getMaskedPose(activateStates));
+ dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), masked);
- // dataWatcher.set(DataWatcherRegistry.s.a(6), EntityPose.values()[pose.ordinal()]);
-
return new PacketPlayOutEntityMetadata(entityId, dataWatcher, true);
}
+
+ private EntityPose getMaskedPose(Collection states) {
+ if (states.contains(NPCState.CROUCHED))
+ return EntityPose.CROUCHING;
+ return EntityPose.STANDING;
+ }
}
diff --git a/nms/v1_8_R3/pom.xml b/nms/v1_8_R3/pom.xml
index 39d38da7..0e57aacd 100755
--- a/nms/v1_8_R3/pom.xml
+++ b/nms/v1_8_R3/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_8_R3
diff --git a/nms/v1_9_R1/pom.xml b/nms/v1_9_R1/pom.xml
index 5471526c..03885ac6 100755
--- a/nms/v1_9_R1/pom.xml
+++ b/nms/v1_9_R1/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_9_R1
diff --git a/nms/v1_9_R2/pom.xml b/nms/v1_9_R2/pom.xml
index a496f18c..ba318b70 100755
--- a/nms/v1_9_R2/pom.xml
+++ b/nms/v1_9_R2/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib-nms
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-nms-v1_9_R2
diff --git a/plugin/pom.xml b/plugin/pom.xml
index 13886d42..34d4b5e4 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -8,7 +8,7 @@
net.jitse
npclib
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
npclib-plugin
diff --git a/pom.xml b/pom.xml
index b430d36c..6f701579 100755
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
net.jitse
npclib
- 2.11-SNAPSHOT
+ 2.11.1-SNAPSHOT
UTF-8