From a7bf542eb34d08de32377a08f0d01515a3a8d81f Mon Sep 17 00:00:00 2001
From: D3v1s0m
Date: Tue, 10 Dec 2024 10:56:20 +0400
Subject: [PATCH 01/10] Added entity_sitting property to allow player and some
other entities to sit
---
.../entity/ArmorStandVehicleEntity.java | 72 +++++++++++++++++++
.../entity/EntityPropertyRegistryImpl.java | 2 +
.../pyr/znpcsplus/entity/PacketEntity.java | 41 +++++++++++
.../properties/EntitySittingProperty.java | 53 ++++++++++++++
.../java/lol/pyr/znpcsplus/npc/NpcImpl.java | 4 ++
.../lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 2 +-
6 files changed, 173 insertions(+), 1 deletion(-)
create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java
create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java
new file mode 100644
index 0000000..0bc3886
--- /dev/null
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java
@@ -0,0 +1,72 @@
+package lol.pyr.znpcsplus.entity;
+
+import io.github.retrooper.packetevents.util.SpigotConversionUtil;
+import lol.pyr.znpcsplus.api.entity.EntityProperty;
+import lol.pyr.znpcsplus.api.entity.PropertyHolder;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Represents an armor stand vehicle entity.
+ *
+ * This entity is used to make the NPC sit on an invisible armor stand.
+ *
+ */
+public class ArmorStandVehicleEntity implements PropertyHolder {
+
+ private final Map, Object> propertyMap = new HashMap<>();
+
+ public ArmorStandVehicleEntity(EntityPropertyRegistryImpl propertyRegistry) {
+ setProperty(propertyRegistry.getByName("small", Boolean.class), true);
+ setProperty(propertyRegistry.getByName("invisible", Boolean.class), true);
+ setProperty(propertyRegistry.getByName("base_plate", Boolean.class), false);
+ }
+
+ @SuppressWarnings("unchecked")
+ public T getProperty(EntityProperty key) {
+ return hasProperty(key) ? (T) propertyMap.get((EntityPropertyImpl>) key) : key.getDefaultValue();
+ }
+
+ @Override
+ public boolean hasProperty(EntityProperty> key) {
+ return propertyMap.containsKey((EntityPropertyImpl>) key);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void setProperty(EntityProperty key, T value) {
+ Object val = value;
+ if (val instanceof ItemStack) val = SpigotConversionUtil.fromBukkitItemStack((ItemStack) val);
+
+ setProperty((EntityPropertyImpl) key, (T) val);
+ }
+
+ @Override
+ public void setItemProperty(EntityProperty> key, ItemStack value) {
+ throw new UnsupportedOperationException("Cannot set item properties on armor stands");
+ }
+
+ @Override
+ public ItemStack getItemProperty(EntityProperty> key) {
+ throw new UnsupportedOperationException("Cannot get item properties on armor stands");
+ }
+
+ public void setProperty(EntityPropertyImpl key, T value) {
+ if (key == null) return;
+ if (value == null || value.equals(key.getDefaultValue())) propertyMap.remove(key);
+ else propertyMap.put(key, value);
+ }
+
+ public Set> getAllProperties() {
+ return Collections.unmodifiableSet(propertyMap.keySet());
+ }
+
+ @Override
+ public Set> getAppliedProperties() {
+ return Collections.unmodifiableSet(propertyMap.keySet());
+ }
+}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java
index 6bb9b3c..f097962 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java
@@ -182,6 +182,8 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
register(new BooleanProperty("baby", babyIndex, false, legacyBooleans));
}
+ register(new EntitySittingProperty(packetFactory, this));
+
// Player
register(new DummyProperty<>("skin", SkinDescriptor.class, false));
final int skinLayersIndex;
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java
index 4418152..5687adc 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java
@@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
+import lol.pyr.znpcsplus.ZNpcsPlusBootstrap;
import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
import lol.pyr.znpcsplus.packets.PacketFactory;
@@ -13,6 +14,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
@@ -26,6 +28,8 @@ public class PacketEntity implements PropertyHolder {
private final EntityType type;
private NpcLocation location;
+ private final HashMap metadata = new HashMap<>();
+
public PacketEntity(PacketFactory packetFactory, PropertyHolder properties, EntityType type, NpcLocation location) {
this.packetFactory = packetFactory;
this.properties = properties;
@@ -67,6 +71,15 @@ public class PacketEntity implements PropertyHolder {
public void despawn(Player player) {
packetFactory.destroyEntity(player, this, properties);
+ if (hasMetadata("ridingVehicle")) {
+ try {
+ PacketEntity armorStand = (PacketEntity) getMetadata("ridingVehicle");
+ armorStand.despawn(player);
+ } catch (Exception e) {
+ //noinspection CallToPrintStackTrace
+ e.printStackTrace();
+ }
+ }
}
public void refreshMeta(Player player) {
@@ -116,4 +129,32 @@ public class PacketEntity implements PropertyHolder {
public Set> getAppliedProperties() {
return properties.getAppliedProperties();
}
+
+ public void setMetadata(String key, Object value) {
+ metadata.put(key, value);
+ }
+
+ public Object getMetadata(String key) {
+ return metadata.get(key);
+ }
+
+ public T getMetadata(String key, Class type) {
+ try {
+ return type.cast(metadata.get(key));
+ } catch (ClassCastException e) {
+ return null;
+ }
+ }
+
+ public void removeMetadata(String key) {
+ metadata.remove(key);
+ }
+
+ public boolean hasMetadata(String key) {
+ return metadata.containsKey(key);
+ }
+
+ public void clearMetadata() {
+ metadata.clear();
+ }
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
new file mode 100644
index 0000000..fb8fc2c
--- /dev/null
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
@@ -0,0 +1,53 @@
+package lol.pyr.znpcsplus.entity.properties;
+
+import com.github.retrooper.packetevents.PacketEvents;
+import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
+import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
+import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetPassengers;
+import lol.pyr.znpcsplus.entity.ArmorStandVehicleEntity;
+import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
+import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
+import lol.pyr.znpcsplus.entity.PacketEntity;
+import lol.pyr.znpcsplus.packets.PacketFactory;
+import org.bukkit.entity.Player;
+
+import java.util.Map;
+
+public class EntitySittingProperty extends EntityPropertyImpl {
+ private final PacketFactory packetFactory;
+ private final EntityPropertyRegistryImpl propertyRegistry;
+
+ public EntitySittingProperty(PacketFactory packetFactory, EntityPropertyRegistryImpl propertyRegistry) {
+ super("entity_sitting", false, Boolean.class);
+ this.packetFactory = packetFactory;
+ this.propertyRegistry = propertyRegistry;
+ }
+
+ @Override
+ public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) {
+ boolean sitting = entity.getProperty(this);
+ if (sitting) {
+ ArmorStandVehicleEntity vehicleEntity = new ArmorStandVehicleEntity(propertyRegistry);
+ PacketEntity vehiclePacketEntity = new PacketEntity(packetFactory, vehicleEntity, EntityTypes.ARMOR_STAND, entity.getLocation().withY(entity.getLocation().getY() - 0.9));
+ vehiclePacketEntity.spawn(player);
+ entity.setMetadata("ridingVehicle", vehiclePacketEntity);
+ PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSetPassengers(
+ vehiclePacketEntity.getEntityId(),
+ new int[]{entity.getEntityId()}
+ ));
+ } else {
+ if (entity.hasMetadata("ridingVehicle")) {
+ PacketEntity vehicleEntity = (PacketEntity) entity.getMetadata("ridingVehicle");
+ PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSetPassengers(
+ vehicleEntity.getEntityId(),
+ new int[]{}
+ ));
+ vehicleEntity.despawn(player);
+ entity.removeMetadata("ridingVehicle");
+ // Send a packet to reset the npc's position
+ packetFactory.teleportEntity(player, entity);
+ }
+ }
+ }
+
+}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java
index 4fa6b67..0a5695a 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java
@@ -86,6 +86,10 @@ public class NpcImpl extends Viewable implements Npc {
public void setLocation(NpcLocation location) {
this.location = location;
entity.setLocation(location, getViewers());
+ if (entity.hasMetadata("ridingVehicle")) {
+ PacketEntity armorStand = (PacketEntity) entity.getMetadata("ridingVehicle");
+ armorStand.setLocation(location.withY(location.getY() - 0.9), getViewers());
+ }
hologram.setLocation(location.withY(location.getY() + type.getHologramOffset()));
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
index d072740..1e6a26d 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
@@ -118,7 +118,7 @@ public class NpcTypeImpl implements NpcType {
"potion_color", "potion_ambient", "display_name", "permission_required",
"player_knockback", "player_knockback_exempt_permission", "player_knockback_distance", "player_knockback_vertical",
"player_knockback_horizontal", "player_knockback_cooldown", "player_knockback_sound", "player_knockback_sound_name",
- "player_knockback_sound_volume", "player_knockback_sound_pitch");
+ "player_knockback_sound_volume", "player_knockback_sound_pitch", "entity_sitting");
if (!type.equals(EntityTypes.PLAYER)) addProperties("dinnerbone");
// TODO: make this look nicer after completing the rest of the properties
if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow");
From 8aed2ba5dc36c9650d7c00fbd65bee6862d6e993 Mon Sep 17 00:00:00 2001
From: D3v1s0m
Date: Thu, 12 Dec 2024 14:27:29 +0400
Subject: [PATCH 02/10] chore: bump packetevents version
---
plugin/build.gradle | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugin/build.gradle b/plugin/build.gradle
index 35783cc..7cbf95f 100644
--- a/plugin/build.gradle
+++ b/plugin/build.gradle
@@ -19,7 +19,7 @@ dependencies {
compileOnly "me.clip:placeholderapi:2.11.6" // Placeholder support
implementation "com.google.code.gson:gson:2.10.1" // JSON parsing
implementation "org.bstats:bstats-bukkit:3.0.2" // Plugin stats
- implementation "com.github.retrooper:packetevents-spigot:2.6.0" // Packets
+ implementation "com.github.retrooper:packetevents-spigot:2.7.0" // Packets
implementation "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1" // Configs
implementation "lol.pyr:director-adventure:2.1.2" // Commands
From 7fbe42e2078d13012aa077724e722bb84dd8a1cc Mon Sep 17 00:00:00 2001
From: D3v1s0m
Date: Thu, 12 Dec 2024 14:30:22 +0400
Subject: [PATCH 03/10] feat: Creaking NPC Type and its properties
---
.../znpcsplus/entity/EntityPropertyRegistryImpl.java | 10 ++++++++++
.../main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 5 +++++
.../lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 6 ++++++
3 files changed, 21 insertions(+)
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java
index f097962..6e02d58 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java
@@ -667,6 +667,16 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
// Bogged
register(new BooleanProperty("bogged_sheared", 16, false, legacyBooleans));
+
+ if (!ver.isNewerThanOrEquals(ServerVersion.V_1_21_2)) return;
+
+ // Creaking
+ register(new BooleanProperty("creaking_active", 17, false, legacyBooleans));
+
+ if (!ver.isNewerThanOrEquals(ServerVersion.V_1_21_4)) return;
+
+ // Creaking
+ register(new BooleanProperty("creaking_crumbling", 18, false, legacyBooleans));
}
private void registerSerializer(PropertySerializer> serializer) {
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
index 1e6a26d..1a9bb9c 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
@@ -176,6 +176,11 @@ public class NpcTypeImpl implements NpcType {
addProperties("wolf_variant");
}
}
+ if (version.isNewerThanOrEquals(ServerVersion.V_1_21_4)) {
+ if (EntityTypes.isTypeInstanceOf(type, EntityTypes.CREAKING)) {
+ addProperties("creaking_crumbling");
+ }
+ }
return new NpcTypeImpl(name, type, hologramOffset, new HashSet<>(allowedProperties), defaultProperties);
}
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
index 39f52b7..78c217e 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
@@ -386,6 +386,12 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "breeze", EntityTypes.BREEZE)
.setHologramOffset(-0.205));
+
+ if (!version.isNewerThanOrEquals(ServerVersion.V_1_21_2)) return;
+
+ register(builder(p, "creaking", EntityTypes.CREAKING)
+ .setHologramOffset(0.725)
+ .addProperties("creaking_active"));
}
public Collection getAll() {
From e20bd9ba57a0b6722206d1bcb12b936649ba211c Mon Sep 17 00:00:00 2001
From: D3v1s0m
Date: Thu, 12 Dec 2024 16:12:52 +0400
Subject: [PATCH 04/10] fix: multiple polar bear npc type registrations
---
.../main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 3 ---
1 file changed, 3 deletions(-)
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
index 78c217e..ebc12e0 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
@@ -205,9 +205,6 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
.setHologramOffset(-0.025)
.addEquipmentProperties());
- register(builder(p, "polar_bear", EntityTypes.POLAR_BEAR)
- .setHologramOffset(-0.575));
-
register(builder(p, "stray", EntityTypes.STRAY)
.setHologramOffset(0.015)
.addEquipmentProperties());
From f8d5700b9a188a870689faad6a762927a3e92c08 Mon Sep 17 00:00:00 2001
From: Pyrbu
Date: Fri, 13 Dec 2024 00:57:36 +0100
Subject: [PATCH 05/10] make set property private on ArmorStandVehicleEntity
---
.../znpcsplus/entity/ArmorStandVehicleEntity.java | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java
index 0bc3886..ff53417 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java
@@ -21,9 +21,9 @@ public class ArmorStandVehicleEntity implements PropertyHolder {
private final Map, Object> propertyMap = new HashMap<>();
public ArmorStandVehicleEntity(EntityPropertyRegistryImpl propertyRegistry) {
- setProperty(propertyRegistry.getByName("small", Boolean.class), true);
- setProperty(propertyRegistry.getByName("invisible", Boolean.class), true);
- setProperty(propertyRegistry.getByName("base_plate", Boolean.class), false);
+ _setProperty(propertyRegistry.getByName("small", Boolean.class), true);
+ _setProperty(propertyRegistry.getByName("invisible", Boolean.class), true);
+ _setProperty(propertyRegistry.getByName("base_plate", Boolean.class), false);
}
@SuppressWarnings("unchecked")
@@ -37,14 +37,18 @@ public class ArmorStandVehicleEntity implements PropertyHolder {
}
@SuppressWarnings("unchecked")
- @Override
- public void setProperty(EntityProperty key, T value) {
+ private void _setProperty(EntityProperty key, T value) {
Object val = value;
if (val instanceof ItemStack) val = SpigotConversionUtil.fromBukkitItemStack((ItemStack) val);
setProperty((EntityPropertyImpl) key, (T) val);
}
+ @Override
+ public void setProperty(EntityProperty key, T value) {
+ throw new UnsupportedOperationException("Cannot set properties on armor stands");
+ }
+
@Override
public void setItemProperty(EntityProperty> key, ItemStack value) {
throw new UnsupportedOperationException("Cannot set item properties on armor stands");
From aed6ee178c38ba8730e802f97ddf2b9fea4d6c45 Mon Sep 17 00:00:00 2001
From: Pyrbu
Date: Fri, 13 Dec 2024 01:37:53 +0100
Subject: [PATCH 06/10] remove metadata and add direct vehicle support to
PacketEntity
---
....java => ArmorStandVehicleProperties.java} | 4 +-
.../pyr/znpcsplus/entity/PacketEntity.java | 88 +++++++++----------
.../properties/EntitySittingProperty.java | 32 ++-----
.../pyr/znpcsplus/hologram/HologramImpl.java | 22 ++---
.../pyr/znpcsplus/hologram/HologramItem.java | 12 ++-
.../pyr/znpcsplus/hologram/HologramLine.java | 10 +--
.../pyr/znpcsplus/hologram/HologramText.java | 5 +-
.../java/lol/pyr/znpcsplus/npc/NpcImpl.java | 10 +--
.../pyr/znpcsplus/packets/PacketFactory.java | 1 +
.../znpcsplus/packets/V1_8PacketFactory.java | 6 ++
10 files changed, 85 insertions(+), 105 deletions(-)
rename plugin/src/main/java/lol/pyr/znpcsplus/entity/{ArmorStandVehicleEntity.java => ArmorStandVehicleProperties.java} (94%)
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleProperties.java
similarity index 94%
rename from plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java
rename to plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleProperties.java
index ff53417..4e4605a 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleEntity.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/ArmorStandVehicleProperties.java
@@ -16,11 +16,11 @@ import java.util.Set;
* This entity is used to make the NPC sit on an invisible armor stand.
*
*/
-public class ArmorStandVehicleEntity implements PropertyHolder {
+public class ArmorStandVehicleProperties implements PropertyHolder {
private final Map, Object> propertyMap = new HashMap<>();
- public ArmorStandVehicleEntity(EntityPropertyRegistryImpl propertyRegistry) {
+ public ArmorStandVehicleProperties(EntityPropertyRegistryImpl propertyRegistry) {
_setProperty(propertyRegistry.getByName("small", Boolean.class), true);
_setProperty(propertyRegistry.getByName("invisible", Boolean.class), true);
_setProperty(propertyRegistry.getByName("base_plate", Boolean.class), false);
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java
index 5687adc..255a201 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java
@@ -4,17 +4,15 @@ import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
-import lol.pyr.znpcsplus.ZNpcsPlusBootstrap;
import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.reflection.Reflections;
import lol.pyr.znpcsplus.util.NpcLocation;
+import lol.pyr.znpcsplus.util.Viewable;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
-import java.util.Collection;
-import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
@@ -22,17 +20,19 @@ public class PacketEntity implements PropertyHolder {
private final PacketFactory packetFactory;
private final PropertyHolder properties;
+ private final Viewable viewable;
private final int entityId;
private final UUID uuid;
private final EntityType type;
private NpcLocation location;
- private final HashMap metadata = new HashMap<>();
+ private PacketEntity vehicle;
- public PacketEntity(PacketFactory packetFactory, PropertyHolder properties, EntityType type, NpcLocation location) {
+ public PacketEntity(PacketFactory packetFactory, PropertyHolder properties, Viewable viewable, EntityType type, NpcLocation location) {
this.packetFactory = packetFactory;
this.properties = properties;
+ this.viewable = viewable;
this.entityId = reserveEntityID();
this.uuid = UUID.randomUUID();
this.type = type;
@@ -55,31 +55,59 @@ public class PacketEntity implements PropertyHolder {
return type;
}
- public void setLocation(NpcLocation location, Collection viewers) {
+ public void setLocation(NpcLocation location) {
this.location = location;
- for (Player viewer : viewers) packetFactory.teleportEntity(viewer, this);
+ if (vehicle != null) {
+ vehicle.setLocation(location.withY(location.getY() - 0.9));
+ return;
+ }
+ for (Player viewer : viewable.getViewers()) packetFactory.teleportEntity(viewer, this);
}
public void spawn(Player player) {
if (type == EntityTypes.PLAYER) packetFactory.spawnPlayer(player, this, properties);
else packetFactory.spawnEntity(player, this, properties);
+ if (vehicle != null) {
+ vehicle.spawn(player);
+ packetFactory.setPassenger(player, vehicle, this);
+ }
}
public void setHeadRotation(Player player, float yaw, float pitch) {
packetFactory.sendHeadRotation(player, this, yaw, pitch);
}
- public void despawn(Player player) {
- packetFactory.destroyEntity(player, this, properties);
- if (hasMetadata("ridingVehicle")) {
- try {
- PacketEntity armorStand = (PacketEntity) getMetadata("ridingVehicle");
- armorStand.despawn(player);
- } catch (Exception e) {
- //noinspection CallToPrintStackTrace
- e.printStackTrace();
+ public PacketEntity getVehicle() {
+ return vehicle;
+ }
+
+ public Viewable getViewable() {
+ return viewable;
+ }
+
+ public void setVehicle(PacketEntity vehicle) {
+ // remove old vehicle
+ if (this.vehicle != null) {
+ for (Player player : viewable.getViewers()) {
+ packetFactory.setPassenger(player, this.vehicle, null);
+ this.vehicle.despawn(player);
+ packetFactory.teleportEntity(player, this);
}
}
+
+ this.vehicle = vehicle;
+ if (this.vehicle == null) return;
+
+ vehicle.setLocation(location.withY(location.getY() - 0.9));
+ for (Player player : viewable.getViewers()) {
+ vehicle.spawn(player);
+ packetFactory.setPassenger(player, vehicle, this);
+ }
+ }
+
+ public void despawn(Player player) {
+ packetFactory.destroyEntity(player, this, properties);
+ if (vehicle != null) vehicle.despawn(player);
}
public void refreshMeta(Player player) {
@@ -129,32 +157,4 @@ public class PacketEntity implements PropertyHolder {
public Set> getAppliedProperties() {
return properties.getAppliedProperties();
}
-
- public void setMetadata(String key, Object value) {
- metadata.put(key, value);
- }
-
- public Object getMetadata(String key) {
- return metadata.get(key);
- }
-
- public T getMetadata(String key, Class type) {
- try {
- return type.cast(metadata.get(key));
- } catch (ClassCastException e) {
- return null;
- }
- }
-
- public void removeMetadata(String key) {
- metadata.remove(key);
- }
-
- public boolean hasMetadata(String key) {
- return metadata.containsKey(key);
- }
-
- public void clearMetadata() {
- metadata.clear();
- }
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
index fb8fc2c..e9b66c5 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
@@ -1,10 +1,8 @@
package lol.pyr.znpcsplus.entity.properties;
-import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
-import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetPassengers;
-import lol.pyr.znpcsplus.entity.ArmorStandVehicleEntity;
+import lol.pyr.znpcsplus.entity.ArmorStandVehicleProperties;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
import lol.pyr.znpcsplus.entity.PacketEntity;
@@ -26,28 +24,12 @@ public class EntitySittingProperty extends EntityPropertyImpl {
@Override
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) {
boolean sitting = entity.getProperty(this);
- if (sitting) {
- ArmorStandVehicleEntity vehicleEntity = new ArmorStandVehicleEntity(propertyRegistry);
- PacketEntity vehiclePacketEntity = new PacketEntity(packetFactory, vehicleEntity, EntityTypes.ARMOR_STAND, entity.getLocation().withY(entity.getLocation().getY() - 0.9));
- vehiclePacketEntity.spawn(player);
- entity.setMetadata("ridingVehicle", vehiclePacketEntity);
- PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSetPassengers(
- vehiclePacketEntity.getEntityId(),
- new int[]{entity.getEntityId()}
- ));
- } else {
- if (entity.hasMetadata("ridingVehicle")) {
- PacketEntity vehicleEntity = (PacketEntity) entity.getMetadata("ridingVehicle");
- PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSetPassengers(
- vehicleEntity.getEntityId(),
- new int[]{}
- ));
- vehicleEntity.despawn(player);
- entity.removeMetadata("ridingVehicle");
- // Send a packet to reset the npc's position
- packetFactory.teleportEntity(player, entity);
- }
+ if (sitting) if (entity.getVehicle() == null) {
+ PacketEntity vehiclePacketEntity = new PacketEntity(packetFactory, new ArmorStandVehicleProperties(propertyRegistry),
+ entity.getViewable(), EntityTypes.ARMOR_STAND, entity.getLocation().withY(entity.getLocation().getY() - 0.9));
+ entity.setVehicle(vehiclePacketEntity);
+ } else if (entity.getVehicle() != null) {
+ entity.setVehicle(null);
}
}
-
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java
index 4092e92..c1a4556 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java
@@ -38,9 +38,9 @@ public class HologramImpl extends Viewable implements Hologram {
}
public void addTextLineComponent(Component line) {
- HologramText newLine = new HologramText(propertyRegistry, packetFactory, null, line);
+ HologramText newLine = new HologramText(this, propertyRegistry, packetFactory, null, line);
lines.add(newLine);
- relocateLines(newLine);
+ relocateLines();
for (Player viewer : getViewers()) newLine.show(viewer.getPlayer());
}
@@ -57,9 +57,9 @@ public class HologramImpl extends Viewable implements Hologram {
}
public void addItemLinePEStack(ItemStack item) {
- HologramItem newLine = new HologramItem(propertyRegistry, packetFactory, null, item);
+ HologramItem newLine = new HologramItem(this, propertyRegistry, packetFactory, null, item);
lines.add(newLine);
- relocateLines(newLine);
+ relocateLines();
for (Player viewer : getViewers()) newLine.show(viewer.getPlayer());
}
@@ -99,9 +99,9 @@ public class HologramImpl extends Viewable implements Hologram {
}
public void insertTextLineComponent(int index, Component line) {
- HologramText newLine = new HologramText(propertyRegistry, packetFactory, null, line);
+ HologramText newLine = new HologramText(this, propertyRegistry, packetFactory, null, line);
lines.add(index, newLine);
- relocateLines(newLine);
+ relocateLines();
for (Player viewer : getViewers()) newLine.show(viewer.getPlayer());
}
@@ -114,9 +114,9 @@ public class HologramImpl extends Viewable implements Hologram {
}
public void insertItemLinePEStack(int index, ItemStack item) {
- HologramItem newLine = new HologramItem(propertyRegistry, packetFactory, null, item);
+ HologramItem newLine = new HologramItem(this, propertyRegistry, packetFactory, null, item);
lines.add(index, newLine);
- relocateLines(newLine);
+ relocateLines();
for (Player viewer : getViewers()) newLine.show(viewer.getPlayer());
}
@@ -172,14 +172,10 @@ public class HologramImpl extends Viewable implements Hologram {
}
private void relocateLines() {
- relocateLines(null);
- }
-
- private void relocateLines(HologramLine> newLine) {
final double lineSpacing = configManager.getConfig().lineSpacing();
double height = location.getY() + (lines.size() - 1) * lineSpacing + getOffset();
for (HologramLine> line : lines) {
- line.setLocation(location.withY(height), line == newLine ? Collections.emptySet() : getViewers());
+ line.setLocation(location.withY(height));
height -= lineSpacing;
}
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramItem.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramItem.java
index c25e434..da17da4 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramItem.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramItem.java
@@ -15,13 +15,11 @@ import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.util.NpcLocation;
-import org.bukkit.entity.Player;
-
-import java.util.Collection;
+import lol.pyr.znpcsplus.util.Viewable;
public class HologramItem extends HologramLine {
- public HologramItem(EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, ItemStack item) {
- super(item, packetFactory, EntityTypes.ITEM, location);
+ public HologramItem(Viewable viewable, EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, ItemStack item) {
+ super(viewable, item, packetFactory, EntityTypes.ITEM, location);
addProperty(propertyRegistry.getByName("holo_item"));
}
@@ -33,8 +31,8 @@ public class HologramItem extends HologramLine {
}
@Override
- public void setLocation(NpcLocation location, Collection viewers) {
- super.setLocation(location.withY(location.getY() + 2.05), viewers);
+ public void setLocation(NpcLocation location) {
+ super.setLocation(location.withY(location.getY() + 2.05));
}
public static boolean ensureValidItemInput(String in) {
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java
index 3b572e5..79e45c1 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramLine.java
@@ -7,10 +7,10 @@ import lol.pyr.znpcsplus.api.entity.PropertyHolder;
import lol.pyr.znpcsplus.entity.PacketEntity;
import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.util.NpcLocation;
+import lol.pyr.znpcsplus.util.Viewable;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
-import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -19,9 +19,9 @@ public class HologramLine implements PropertyHolder {
private final PacketEntity entity;
private final Set> properties;
- public HologramLine(M value, PacketFactory packetFactory, EntityType type, NpcLocation location) {
+ public HologramLine(Viewable viewable, M value, PacketFactory packetFactory, EntityType type, NpcLocation location) {
this.value = value;
- this.entity = new PacketEntity(packetFactory, this, type, location);
+ this.entity = new PacketEntity(packetFactory, this, viewable, type, location);
this.properties = new HashSet<>();
}
@@ -45,8 +45,8 @@ public class HologramLine implements PropertyHolder {
entity.despawn(player);
}
- public void setLocation(NpcLocation location, Collection viewers) {
- entity.setLocation(location, viewers);
+ public void setLocation(NpcLocation location) {
+ entity.setLocation(location);
}
public int getEntityId() {
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java
index 47e5e91..40c8995 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramText.java
@@ -5,6 +5,7 @@ import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
import lol.pyr.znpcsplus.packets.PacketFactory;
import lol.pyr.znpcsplus.util.NpcLocation;
+import lol.pyr.znpcsplus.util.Viewable;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
@@ -12,8 +13,8 @@ public class HologramText extends HologramLine {
private static final Component BLANK = Component.text("%blank%");
- public HologramText(EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, Component text) {
- super(text, packetFactory, EntityTypes.ARMOR_STAND, location);
+ public HologramText(Viewable viewable, EntityPropertyRegistryImpl propertyRegistry, PacketFactory packetFactory, NpcLocation location, Component text) {
+ super(viewable, text, packetFactory, EntityTypes.ARMOR_STAND, location);
addProperty(propertyRegistry.getByName("name"));
addProperty(propertyRegistry.getByName("invisible"));
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java
index 0a5695a..e29948a 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java
@@ -48,14 +48,14 @@ public class NpcImpl extends Viewable implements Npc {
this.type = type;
this.location = location;
this.uuid = uuid;
- entity = new PacketEntity(packetFactory, this, type.getType(), location);
+ entity = new PacketEntity(packetFactory, this, this, type.getType(), location);
hologram = new HologramImpl(propertyRegistry, configManager, packetFactory, textSerializer, location.withY(location.getY() + type.getHologramOffset()));
}
public void setType(NpcTypeImpl type) {
UNSAFE_hideAll();
this.type = type;
- entity = new PacketEntity(packetFactory, this, type.getType(), entity.getLocation());
+ entity = new PacketEntity(packetFactory, this, this, type.getType(), entity.getLocation());
hologram.setLocation(location.withY(location.getY() + type.getHologramOffset()));
UNSAFE_showAll();
}
@@ -85,11 +85,7 @@ public class NpcImpl extends Viewable implements Npc {
public void setLocation(NpcLocation location) {
this.location = location;
- entity.setLocation(location, getViewers());
- if (entity.hasMetadata("ridingVehicle")) {
- PacketEntity armorStand = (PacketEntity) entity.getMetadata("ridingVehicle");
- armorStand.setLocation(location.withY(location.getY() - 0.9), getViewers());
- }
+ entity.setLocation(location);
hologram.setLocation(location.withY(location.getY() + type.getHologramOffset()));
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java
index 98cc382..824ef31 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java
@@ -24,4 +24,5 @@ public interface PacketFactory {
void sendMetadata(Player player, PacketEntity entity, List data);
void sendHeadRotation(Player player, PacketEntity entity, float yaw, float pitch);
void sendHandSwing(Player player, PacketEntity entity, boolean offHand);
+ void setPassenger(Player player, PacketEntity vehicle, PacketEntity passenger);
}
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java
index 74490ce..e1134f8 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java
@@ -153,6 +153,12 @@ public class V1_8PacketFactory implements PacketFactory {
sendPacket(player, new WrapperPlayServerEntityEquipment(entity.getEntityId(), Collections.singletonList(equipment)));
}
+ @Override
+ public void setPassenger(Player player, PacketEntity vehicle, PacketEntity passenger) {
+ sendPacket(player, new WrapperPlayServerSetPassengers(vehicle.getEntityId(),
+ passenger == null ? new int[] {} : new int[] {passenger.getEntityId()}));
+ }
+
protected void sendPacket(Player player, PacketWrapper> packet) {
packetEvents.getPlayerManager().sendPacket(player, packet);
}
From 670bc9623b3a48ceae9fe344f13aed6f5cf5c1b2 Mon Sep 17 00:00:00 2001
From: Pyrbu
Date: Fri, 13 Dec 2024 01:38:19 +0100
Subject: [PATCH 07/10] make entity_sitting only available to player since it
doesn't really do anything for any other npc type
---
plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java | 2 +-
.../main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
index 1a9bb9c..bfb259e 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeImpl.java
@@ -118,7 +118,7 @@ public class NpcTypeImpl implements NpcType {
"potion_color", "potion_ambient", "display_name", "permission_required",
"player_knockback", "player_knockback_exempt_permission", "player_knockback_distance", "player_knockback_vertical",
"player_knockback_horizontal", "player_knockback_cooldown", "player_knockback_sound", "player_knockback_sound_name",
- "player_knockback_sound_volume", "player_knockback_sound_pitch", "entity_sitting");
+ "player_knockback_sound_volume", "player_knockback_sound_pitch");
if (!type.equals(EntityTypes.PLAYER)) addProperties("dinnerbone");
// TODO: make this look nicer after completing the rest of the properties
if (version.isNewerThanOrEquals(ServerVersion.V_1_9)) addProperties("glow");
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
index 78c217e..742ea0a 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
@@ -36,7 +36,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "player", EntityTypes.PLAYER)
.setHologramOffset(-0.15D)
.addEquipmentProperties()
- .addProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat", "shoulder_entity_left", "shoulder_entity_right", "force_body_rotation")
+ .addProperties("skin_cape", "skin_jacket", "skin_left_sleeve", "skin_right_sleeve", "skin_left_leg", "skin_right_leg", "skin_hat", "shoulder_entity_left", "shoulder_entity_right", "force_body_rotation", "entity_sitting")
.addDefaultProperty("skin_cape", true)
.addDefaultProperty("skin_jacket", true)
.addDefaultProperty("skin_left_sleeve", true)
From f5d1a1914aaf7aa55d2bec4c86d8eac655294d52 Mon Sep 17 00:00:00 2001
From: D3v1s0m
Date: Fri, 13 Dec 2024 10:54:29 +0400
Subject: [PATCH 08/10] chore: added entity_sitting property to more npc types
---
.../znpcsplus/npc/NpcTypeRegistryImpl.java | 48 ++++++++++++-------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
index 2878880..2a9e775 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
@@ -82,7 +82,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "enderman", EntityTypes.ENDERMAN)
.setHologramOffset(0.925)
- .addProperties("enderman_held_block", "enderman_screaming", "enderman_staring"));
+ .addProperties("enderman_held_block", "enderman_screaming", "enderman_staring", "entity_sitting"));
register(builder(p, "endermite", EntityTypes.ENDERMITE)
.setHologramOffset(-1.675));
@@ -93,7 +93,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "giant", EntityTypes.GIANT)
.setHologramOffset(10.025)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
register(builder(p, "guardian", EntityTypes.GUARDIAN)
.setHologramOffset(-1.125)
@@ -133,7 +134,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "skeleton", EntityTypes.SKELETON)
.setHologramOffset(0.015)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
register(builder(p, "skeleton_horse", EntityTypes.SKELETON_HORSE)
.setHologramOffset(-0.375));
@@ -169,14 +171,16 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "zombie", EntityTypes.ZOMBIE)
.setHologramOffset(-0.025)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
register(builder(p, "zombie_horse", EntityTypes.ZOMBIE_HORSE)
.setHologramOffset(-0.375));
register(builder(p, "zombified_piglin", EntityTypes.ZOMBIFIED_PIGLIN)
.setHologramOffset(-0.025)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
if (!version.isNewerThanOrEquals(ServerVersion.V_1_9)) return;
@@ -203,14 +207,17 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "husk", EntityTypes.HUSK)
.setHologramOffset(-0.025)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
register(builder(p, "stray", EntityTypes.STRAY)
.setHologramOffset(0.015)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
register(builder(p, "evoker", EntityTypes.EVOKER)
- .setHologramOffset(-0.025));
+ .setHologramOffset(-0.025)
+ .addProperties("entity_sitting"));
register(builder(p, "llama", EntityTypes.LLAMA)
.setHologramOffset(-0.105)
@@ -222,20 +229,23 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "vindicator", EntityTypes.VINDICATOR)
.setHologramOffset(-0.025)
- .addProperties("celebrating"));
+ .addProperties("celebrating", "entity_sitting"));
register(builder(p, "wither_skeleton", EntityTypes.WITHER_SKELETON)
.setHologramOffset(0.425)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
register(builder(p, "zombie_villager", EntityTypes.ZOMBIE_VILLAGER)
.setHologramOffset(-0.025)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
if (!version.isNewerThanOrEquals(ServerVersion.V_1_12)) return;
register(builder(p, "illusioner", EntityTypes.ILLUSIONER)
- .setHologramOffset(-0.025));
+ .setHologramOffset(-0.025)
+ .addProperties("entity_sitting"));
register(builder(p, "parrot", EntityTypes.PARROT)
.setHologramOffset(-1.075)
@@ -252,7 +262,8 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "drowned", EntityTypes.DROWNED)
.setHologramOffset(-0.025)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
register(builder(p, "phantom", EntityTypes.PHANTOM)
.setHologramOffset(-1.475));
@@ -288,7 +299,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "pillager", EntityTypes.PILLAGER)
.setHologramOffset(-0.025)
.addHandProperties()
- .addProperties("pillager_charging"));
+ .addProperties("pillager_charging", "entity_sitting"));
register(builder(p, "ravager", EntityTypes.RAVAGER)
.setHologramOffset(0.225));
@@ -316,11 +327,12 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "piglin", EntityTypes.PIGLIN)
.setHologramOffset(-0.025)
.addEquipmentProperties()
- .addProperties("piglin_baby", "piglin_charging_crossbow", "piglin_dancing"));
+ .addProperties("piglin_baby", "piglin_charging_crossbow", "piglin_dancing", "entity_sitting"));
register(builder(p, "piglin_brute", EntityTypes.PIGLIN_BRUTE)
.setHologramOffset(-0.025)
- .addEquipmentProperties());
+ .addEquipmentProperties()
+ .addProperties("entity_sitting"));
register(builder(p, "strider", EntityTypes.STRIDER)
.setHologramOffset(-0.275)
@@ -379,7 +391,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "bogged", EntityTypes.BOGGED)
.setHologramOffset(0.015)
- .addProperties("bogged_sheared"));
+ .addProperties("bogged_sheared", "entity_sitting"));
register(builder(p, "breeze", EntityTypes.BREEZE)
.setHologramOffset(-0.205));
@@ -388,7 +400,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "creaking", EntityTypes.CREAKING)
.setHologramOffset(0.725)
- .addProperties("creaking_active"));
+ .addProperties("creaking_active", "entity_sitting"));
}
public Collection getAll() {
From 41244fb86bb679dece30c95993b438a349662841 Mon Sep 17 00:00:00 2001
From: D3v1s0m
Date: Fri, 13 Dec 2024 10:58:52 +0400
Subject: [PATCH 09/10] fix: disabling entity_sitting property
---
.../entity/properties/EntitySittingProperty.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
index e9b66c5..5e59221 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/EntitySittingProperty.java
@@ -24,10 +24,12 @@ public class EntitySittingProperty extends EntityPropertyImpl {
@Override
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) {
boolean sitting = entity.getProperty(this);
- if (sitting) if (entity.getVehicle() == null) {
- PacketEntity vehiclePacketEntity = new PacketEntity(packetFactory, new ArmorStandVehicleProperties(propertyRegistry),
- entity.getViewable(), EntityTypes.ARMOR_STAND, entity.getLocation().withY(entity.getLocation().getY() - 0.9));
- entity.setVehicle(vehiclePacketEntity);
+ if (sitting) {
+ if (entity.getVehicle() == null) {
+ PacketEntity vehiclePacketEntity = new PacketEntity(packetFactory, new ArmorStandVehicleProperties(propertyRegistry),
+ entity.getViewable(), EntityTypes.ARMOR_STAND, entity.getLocation().withY(entity.getLocation().getY() - 0.9));
+ entity.setVehicle(vehiclePacketEntity);
+ }
} else if (entity.getVehicle() != null) {
entity.setVehicle(null);
}
From 79c0897de9b435cfd670b14c57ad52ccf3f4b6fb Mon Sep 17 00:00:00 2001
From: D3v1s0m
Date: Fri, 13 Dec 2024 11:02:56 +0400
Subject: [PATCH 10/10] fix: remove entity_sitting property from creaking
---
.../main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
index 2a9e775..5a23efc 100644
--- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
+++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcTypeRegistryImpl.java
@@ -400,7 +400,7 @@ public class NpcTypeRegistryImpl implements NpcTypeRegistry {
register(builder(p, "creaking", EntityTypes.CREAKING)
.setHologramOffset(0.725)
- .addProperties("creaking_active", "entity_sitting"));
+ .addProperties("creaking_active"));
}
public Collection getAll() {