From f8b1bfa20af078264c7da06b6c166899d860693b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 16 Jan 2023 20:45:00 +0100 Subject: [PATCH 01/20] Add Getter to DisplayName --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 6c5bf80..9b7969e 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -23,6 +23,7 @@ import com.comphenix.tinyprotocol.Reflection; import de.steamwar.core.*; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; +import lombok.Getter; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; @@ -58,6 +59,7 @@ public class REntity { private FlatteningWrapper.EntityPose pose = FlatteningWrapper.EntityPose.NORMAL; private boolean bowDrawn; private int fireTick; + @Getter private String displayName; protected final Map itemSlots; From c23a6a4afc0acda8888e762bcfe5b012b1eefeb4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 16 Jan 2023 20:53:42 +0100 Subject: [PATCH 02/20] Add Getter to UUID and move to location --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 9b7969e..9e0c3e4 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -46,6 +46,7 @@ public class REntity { private final REntityServer server; private final EntityType entityType; protected final int entityId; + @Getter protected final UUID uuid; protected double x; @@ -84,6 +85,10 @@ public class REntity { server.addEntity(this); } + public void move(Location location) { + move(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), rotToByte(location.getYaw())); + } + public void move(double locX, double locY, double locZ, float pitch, float yaw, byte headYaw) { server.preEntityMove(this, locX, locZ); double fromX = this.x; From b25048257454b27f32baea14c03da05092729759 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 16 Jan 2023 21:34:13 +0100 Subject: [PATCH 03/20] No Gravity --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 9e0c3e4..94c5a90 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -40,6 +40,8 @@ public class REntity { private static final Object nameWatcher = BountifulWrapper.impl.getDataWatcherObject(2, Core.getVersion() > 12 ? Optional.class : String.class); // Optional private static final Object nameVisibleWatcher = BountifulWrapper.impl.getDataWatcherObject(3, Boolean.class); + private static final Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5,Boolean.class); + private static int entityIdCounter = -1; private static final Random random = new Random(); @@ -59,6 +61,7 @@ public class REntity { private boolean invisible; private FlatteningWrapper.EntityPose pose = FlatteningWrapper.EntityPose.NORMAL; private boolean bowDrawn; + private boolean noGravity; private int fireTick; @Getter private String displayName; @@ -185,6 +188,11 @@ public class REntity { server.removeEntity(this); } + public void setNoGravity(boolean noGravity) { + this.noGravity = noGravity; + server.updateEntity(this,getDataWatcherPacket(noGravityDataWatcher,getEntityStatus())); + } + private static int spawnPacketOffset() { switch (Core.getVersion()) { case 8: @@ -230,6 +238,9 @@ public class REntity { if(displayName != null) { packetSink.accept(getDataWatcherPacket(nameWatcher, FlatteningWrapper.impl.formatDisplayName(displayName), nameVisibleWatcher, true)); } + + if(noGravity) + packetSink.accept(getDataWatcherPacket(noGravityDataWatcher,getEntityStatus())); } void tick() { From 77cc4d6a996639cb7bdcbd31b172f01de2233833 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 17 Jan 2023 11:08:05 +0100 Subject: [PATCH 04/20] Fix RArmorStand initialization race condition --- SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java index 7e0e7a7..5513d2b 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java @@ -59,7 +59,9 @@ public class RArmorStand extends REntity { @Override void spawn(Consumer packetSink) { super.spawn(packetSink); - packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value)); + + if(size != null && size != Size.NORMAL) + packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value)); } public enum Size { From fb122edf35c5d0d15c849727a3132255a58e97e8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 17 Jan 2023 11:15:53 +0100 Subject: [PATCH 05/20] Fix packet spamming through missing last location update --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 97ecc3a..3d47eb2 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -134,6 +134,7 @@ public class REntityServer implements Listener { if(fromX == toX && fromZ == toZ) return; + lastLocation.put(player, to); int viewDistance = viewRadius(player); forChunkInView(player, from, (x, z) -> { if(Math.abs(x - toX) > viewDistance || Math.abs(z - toX) > viewDistance) { From d073d3abde23d6dd1f07b24bcc768aed5b21e2ad Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 17 Jan 2023 11:23:22 +0100 Subject: [PATCH 06/20] Fix coordinate axis typo --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 3d47eb2..708e48d 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -137,7 +137,7 @@ public class REntityServer implements Listener { lastLocation.put(player, to); int viewDistance = viewRadius(player); forChunkInView(player, from, (x, z) -> { - if(Math.abs(x - toX) > viewDistance || Math.abs(z - toX) > viewDistance) { + if(Math.abs(x - toX) > viewDistance || Math.abs(z - toZ) > viewDistance) { removePlayerFromChunk(player, x, z); } }); From 42fdc0a3dc4ab3815e32d861a41f6d8e76b005e3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 17 Jan 2023 12:04:57 +0100 Subject: [PATCH 07/20] Fix changing view distance --- .../src/de/steamwar/entity/REntityServer.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 708e48d..a35d4de 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -30,7 +30,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -46,6 +45,7 @@ public class REntityServer implements Listener { private final HashMap> entities = new HashMap<>(); private final HashMap> players = new HashMap<>(); private final HashMap lastLocation = new HashMap<>(); + private final HashMap viewDistance = new HashMap<>(); public REntityServer() { Core.getInstance().getServer().getPluginManager().registerEvents(this, Core.getInstance()); @@ -54,12 +54,13 @@ public class REntityServer implements Listener { public void addPlayer(Player player) { Location location = player.getLocation(); lastLocation.put(player, location); + viewDistance.put(player, viewRadius(player)); forChunkInView(player, location, (x, z) -> addPlayerToChunk(player, x, z)); } public void removePlayer(Player player) { - Location location = lastLocation.remove(player); - forChunkInView(player, location, (x, z) -> removePlayerFromChunk(player, x, z)); + forChunkInView(player, lastLocation.remove(player), (x, z) -> removePlayerFromChunk(player, x, z)); + viewDistance.remove(player); } public void close() { @@ -117,8 +118,6 @@ public class REntityServer implements Listener { entities.remove(id); } - //TODO on settings, on respawn? on boatmove? - @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onMove(PlayerMoveEvent e) { Player player = e.getPlayer(); @@ -135,14 +134,17 @@ public class REntityServer implements Listener { return; lastLocation.put(player, to); - int viewDistance = viewRadius(player); + + int toViewDistance = viewRadius(player); forChunkInView(player, from, (x, z) -> { - if(Math.abs(x - toX) > viewDistance || Math.abs(z - toZ) > viewDistance) { + if(Math.abs(x - toX) > toViewDistance || Math.abs(z - toZ) > toViewDistance) { removePlayerFromChunk(player, x, z); } }); + + int fromViewDistance = this.viewDistance.put(player, toViewDistance); forChunkInView(player, to, (x, z) -> { - if(Math.abs(x - fromX) > viewDistance || Math.abs(z - fromZ) > viewDistance) { + if(Math.abs(x - fromX) > fromViewDistance || Math.abs(z - fromZ) > fromViewDistance) { addPlayerToChunk(player, x, z); } }); @@ -172,7 +174,7 @@ public class REntityServer implements Listener { private void forChunkInView(Player player, Location location, BiConsumer func) { int chunkX = posToChunk(location.getX()); int chunkZ = posToChunk(location.getZ()); - int viewDistance = viewRadius(player); + int viewDistance = this.viewDistance.get(player); for(int x = chunkX - viewDistance; x <= chunkX + viewDistance; x++) { for(int z = chunkZ - viewDistance; z <= chunkZ + viewDistance; z++) { @@ -191,7 +193,7 @@ public class REntityServer implements Listener { private void removePlayerFromChunk(Player player, int x, int z) { long id = chunkToId(x, z); - players.getOrDefault(id, Collections.emptySet()).remove(player); + players.get(id).remove(player); for(REntity entity : entities.getOrDefault(id, emptyEntities)) { entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet)); } @@ -222,7 +224,6 @@ public class REntityServer implements Listener { } private long chunkToId(int x, int z) { - //TODO negative coord clash? return (long) x << 32 + z; } } From 3665e4c3cb0efb77cbcf04511b52b8e6d8937f44 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 17 Jan 2023 12:23:25 +0100 Subject: [PATCH 08/20] Fix coordinate bug (operator precedence) --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index a35d4de..70a5fee 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -224,6 +224,6 @@ public class REntityServer implements Listener { } private long chunkToId(int x, int z) { - return (long) x << 32 + z; + return ((long) x << 32) + z; } } From c9b15b6aa6a9e296fa3a7c6b1728333623e03a8a Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 12:36:30 +0100 Subject: [PATCH 09/20] fix no gravity --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 94c5a90..ddf4f35 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -85,6 +85,8 @@ public class REntity { this.itemSlots = entityType == EntityType.PLAYER ? new HashMap<>() : null; + this.noGravity = false; + server.addEntity(this); } @@ -190,7 +192,8 @@ public class REntity { public void setNoGravity(boolean noGravity) { this.noGravity = noGravity; - server.updateEntity(this,getDataWatcherPacket(noGravityDataWatcher,getEntityStatus())); + if(Core.getVersion() > 8) + server.updateEntity(this,getDataWatcherPacket(noGravityDataWatcher,noGravity)); } private static int spawnPacketOffset() { @@ -240,7 +243,7 @@ public class REntity { } if(noGravity) - packetSink.accept(getDataWatcherPacket(noGravityDataWatcher,getEntityStatus())); + packetSink.accept(getDataWatcherPacket(noGravityDataWatcher,this.noGravity)); } void tick() { From e904a296b5130eff305be8ac600518983c119691 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 12:44:50 +0100 Subject: [PATCH 10/20] add glowing --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index ddf4f35..3b7eb99 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -62,6 +62,7 @@ public class REntity { private FlatteningWrapper.EntityPose pose = FlatteningWrapper.EntityPose.NORMAL; private boolean bowDrawn; private boolean noGravity; + private boolean isGlowing; private int fireTick; @Getter private String displayName; @@ -86,6 +87,7 @@ public class REntity { this.itemSlots = entityType == EntityType.PLAYER ? new HashMap<>() : null; this.noGravity = false; + this.isGlowing = false; server.addEntity(this); } @@ -196,6 +198,13 @@ public class REntity { server.updateEntity(this,getDataWatcherPacket(noGravityDataWatcher,noGravity)); } + public void setGlowing(boolean glowing) { + this.isGlowing = glowing; + if(Core.getVersion() > 8) { + server.updateEntity(this,getDataWatcherPacket(entityStatusWatcher,getEntityStatus())); + } + } + private static int spawnPacketOffset() { switch (Core.getVersion()) { case 8: @@ -288,6 +297,8 @@ public class REntity { status |= 0x10; if(invisible) status |= 0x20; + if(Core.getVersion() > 8 && isGlowing) + status |= 0x40; return status; } From 7a8762594cc5bac782e767122f4c4656e8a32e2e Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 12:55:19 +0100 Subject: [PATCH 11/20] push fixes --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 3b7eb99..9fba9ec 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -251,7 +251,7 @@ public class REntity { packetSink.accept(getDataWatcherPacket(nameWatcher, FlatteningWrapper.impl.formatDisplayName(displayName), nameVisibleWatcher, true)); } - if(noGravity) + if(Core.getVersion() > 8 && noGravity) packetSink.accept(getDataWatcherPacket(noGravityDataWatcher,this.noGravity)); } From da9718c69c5a98ac238b6d8601b8ee53b341d4f5 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 13:50:55 +0100 Subject: [PATCH 12/20] add additional Entity data --- .../src/de/steamwar/entity/RArmorStand.java | 2 +- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 12 +++++++++--- SpigotCore_Main/src/de/steamwar/entity/RPlayer.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java index 5513d2b..152e858 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java @@ -52,7 +52,7 @@ public class RArmorStand extends REntity { private final Size size; public RArmorStand(REntityServer server, Location location, Size size) { - super(server, EntityType.ARMOR_STAND, location); + super(server, EntityType.ARMOR_STAND, location,0); this.size = size; } diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 9fba9ec..58a7720 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -64,15 +64,17 @@ public class REntity { private boolean noGravity; private boolean isGlowing; private int fireTick; + + private final int objectData; @Getter private String displayName; protected final Map itemSlots; - public REntity(REntityServer server, EntityType entityType, Location location) { - this(server, entityType, new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L), location); + public REntity(REntityServer server, EntityType entityType, Location location,int objectData) { + this(server, entityType, new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L), location,objectData); } - protected REntity(REntityServer server, EntityType entityType, UUID uuid, Location location) { + protected REntity(REntityServer server, EntityType entityType, UUID uuid, Location location,int objectData) { this.server = server; this.entityType = entityType; this.entityId = entityIdCounter--; @@ -89,6 +91,8 @@ public class REntity { this.noGravity = false; this.isGlowing = false; + this.objectData = objectData; + server.addEntity(this); } @@ -369,11 +373,13 @@ public class REntity { protected static Function spawnPacketGenerator(Class spawnPacket, int posOffset) { Reflection.FieldAccessor entityId = Reflection.getField(spawnPacket, int.class, 0); + Reflection.FieldAccessor additionalData = Reflection.getField(spawnPacket, int.class, 9); BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset); return entity -> { Object packet = Reflection.newInstance(spawnPacket); entityId.set(packet, entity.entityId); + additionalData.set(packet,entity.objectData); position.set(packet, entity.x, entity.y, entity.z); return packet; }; diff --git a/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index c5a080b..fa6d513 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -76,7 +76,7 @@ public class RPlayer extends REntity { private final String name; public RPlayer(REntityServer server, UUID uuid, String name, Location location) { - super(server, EntityType.PLAYER, uuid, location); + super(server, EntityType.PLAYER, uuid, location,0); this.name = name; //team.addEntry(name); } From fb47db67de5a41f883ac6fe154e10bfdb6c4eb1f Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 16:14:38 +0100 Subject: [PATCH 13/20] fix missmatched index throughout versions --- .../src/de/steamwar/entity/RArmorStand.java | 2 +- .../src/de/steamwar/entity/REntity.java | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java index 152e858..5513d2b 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java @@ -52,7 +52,7 @@ public class RArmorStand extends REntity { private final Size size; public RArmorStand(REntityServer server, Location location, Size size) { - super(server, EntityType.ARMOR_STAND, location,0); + super(server, EntityType.ARMOR_STAND, location); this.size = size; } diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 58a7720..281b66f 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -70,7 +70,11 @@ public class REntity { private String displayName; protected final Map itemSlots; - public REntity(REntityServer server, EntityType entityType, Location location,int objectData) { + public REntity(REntityServer server, EntityType entityType, Location location) { + this(server, entityType, new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L), location,0); + } + + protected REntity(REntityServer server, EntityType entityType, Location location,int objectData) { this(server, entityType, new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L), location,objectData); } @@ -373,7 +377,20 @@ public class REntity { protected static Function spawnPacketGenerator(Class spawnPacket, int posOffset) { Reflection.FieldAccessor entityId = Reflection.getField(spawnPacket, int.class, 0); - Reflection.FieldAccessor additionalData = Reflection.getField(spawnPacket, int.class, 9); + + //Core version 8, index = 10 + //Core version 9 to 18, index = 6 + //Core version 19, index = 7 + + int index; + switch (Core.getVersion()) { + case 8: index = 10; + case 19: index = 7; + default: index = 6; + } + + + Reflection.FieldAccessor additionalData = Reflection.getField(spawnPacket, int.class, index); BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset); return entity -> { From 9bd1088e1073b40973eba53fe15fe3a3f163991f Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 16:23:28 +0100 Subject: [PATCH 14/20] improve switchcase --- .../src/de/steamwar/entity/REntity.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 281b66f..2713318 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -71,7 +71,7 @@ public class REntity { protected final Map itemSlots; public REntity(REntityServer server, EntityType entityType, Location location) { - this(server, entityType, new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L), location,0); + this(server,entityType,location,0); } protected REntity(REntityServer server, EntityType entityType, Location location,int objectData) { @@ -384,9 +384,20 @@ public class REntity { int index; switch (Core.getVersion()) { - case 8: index = 10; - case 19: index = 7; - default: index = 6; + case 8: + index = 10; + break; + case 9: + case 14: + case 12: + case 10: + case 15: + case 18: + index = 6; + break; + default: + index = 7; + break; } From 8cff1db70bdfedee27a3f0c6d6f56d0b4661e3bf Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 16:24:25 +0100 Subject: [PATCH 15/20] Uncomment the comment --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 2713318..c850d51 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -378,10 +378,6 @@ public class REntity { protected static Function spawnPacketGenerator(Class spawnPacket, int posOffset) { Reflection.FieldAccessor entityId = Reflection.getField(spawnPacket, int.class, 0); - //Core version 8, index = 10 - //Core version 9 to 18, index = 6 - //Core version 19, index = 7 - int index; switch (Core.getVersion()) { case 8: From 537509a4e42c1309db64c6318242d367de8b2b44 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 16:34:04 +0100 Subject: [PATCH 16/20] Implement RFallingBlockEntity --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 1 - .../src/de/steamwar/entity/RFallingBlockEntity.java | 13 +++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index c850d51..7c0fa2e 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -396,7 +396,6 @@ public class REntity { break; } - Reflection.FieldAccessor additionalData = Reflection.getField(spawnPacket, int.class, index); BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset); diff --git a/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java b/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java new file mode 100644 index 0000000..0512206 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java @@ -0,0 +1,13 @@ +package de.steamwar.entity; + +import de.steamwar.techhider.BlockIds; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; + +public class RFallingBlockEntity extends REntity{ + + public RFallingBlockEntity(REntityServer server, EntityType entityType, Location location, Material material) { + super(server, entityType, location, BlockIds.impl.materialToId(material)); + } +} From 70e8fc7ff1b94453d6200536c59a0086c63fbdbf Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 16:40:34 +0100 Subject: [PATCH 17/20] Implement RFallingBlockEntity --- .../src/de/steamwar/entity/RFallingBlockEntity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java b/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java index 0512206..b1e6fc5 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java @@ -1,5 +1,6 @@ package de.steamwar.entity; +import de.steamwar.core.Core; import de.steamwar.techhider.BlockIds; import org.bukkit.Location; import org.bukkit.Material; @@ -8,6 +9,6 @@ import org.bukkit.entity.EntityType; public class RFallingBlockEntity extends REntity{ public RFallingBlockEntity(REntityServer server, EntityType entityType, Location location, Material material) { - super(server, entityType, location, BlockIds.impl.materialToId(material)); + super(server, entityType, location, BlockIds.impl.materialToId(material) >> (Core.getVersion() <= 12 ? 4 : 0)); } } From ad8c9edcc89b9a07d3a5c7fb6c765881540bbfcd Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 16:47:43 +0100 Subject: [PATCH 18/20] fix smaller things --- .../src/de/steamwar/entity/REntity.java | 1 + .../steamwar/entity/RFallingBlockEntity.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 7c0fa2e..02c7a5d 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -47,6 +47,7 @@ public class REntity { private final REntityServer server; private final EntityType entityType; + @Getter protected final int entityId; @Getter protected final UUID uuid; diff --git a/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java b/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java index b1e6fc5..b436997 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java @@ -1,3 +1,22 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.steamwar.entity; import de.steamwar.core.Core; @@ -8,7 +27,7 @@ import org.bukkit.entity.EntityType; public class RFallingBlockEntity extends REntity{ - public RFallingBlockEntity(REntityServer server, EntityType entityType, Location location, Material material) { - super(server, entityType, location, BlockIds.impl.materialToId(material) >> (Core.getVersion() <= 12 ? 4 : 0)); + public RFallingBlockEntity(REntityServer server, Location location, Material material) { + super(server, EntityType.FALLING_BLOCK, location, BlockIds.impl.materialToId(material) >> (Core.getVersion() <= 12 ? 4 : 0)); } } From 99c9518d7680b80987f14995b33da7863b8a9b55 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 17 Jan 2023 17:04:25 +0100 Subject: [PATCH 19/20] Fix ObjectData field --- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 02c7a5d..16a0d5e 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -382,7 +382,7 @@ public class REntity { int index; switch (Core.getVersion()) { case 8: - index = 10; + index = 9; break; case 9: case 14: @@ -392,8 +392,9 @@ public class REntity { case 18: index = 6; break; + case 19: default: - index = 7; + index = 4; break; } From 78a85f3d8c8f6158dbe848430c804897b7064108 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 17 Jan 2023 17:12:54 +0100 Subject: [PATCH 20/20] Fix SpawnEntity --- .../src/de/steamwar/entity/REntity.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 16a0d5e..d6ace1a 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -231,12 +231,35 @@ public class REntity { } } private static final Function spawnPacketGenerator = entitySpawnPacketGenerator(ProtocolWrapper.spawnPacket, spawnPacketOffset()); - private static final Function livingSpawnPacketGenerator = Core.getVersion() >= 19 ? spawnPacketGenerator : entitySpawnPacketGenerator(ProtocolWrapper.spawnLivingPacket, Core.getVersion() == 8 ? 2 : 0); + private static int objectDataOffset() { + switch (Core.getVersion()) { + case 8: + return 9; + case 9: + case 14: + case 12: + case 10: + case 15: + case 18: + return 6; + case 19: + default: + return 4; + } + } + private static final Reflection.FieldAccessor additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, objectDataOffset()); + private Object spawnPacketGenerator() { + Object packet = spawnPacketGenerator.apply(this); + additionalData.set(packet, objectData); + return packet; + } + + private static final Function livingSpawnPacketGenerator = Core.getVersion() >= 19 ? REntity::spawnPacketGenerator : entitySpawnPacketGenerator(ProtocolWrapper.spawnLivingPacket, Core.getVersion() == 8 ? 2 : 0); void spawn(Consumer packetSink) { if(entityType.isAlive()) { packetSink.accept(livingSpawnPacketGenerator.apply(this)); } else { - packetSink.accept(spawnPacketGenerator.apply(this)); + packetSink.accept(spawnPacketGenerator()); } postSpawn(packetSink); @@ -261,7 +284,7 @@ public class REntity { } if(Core.getVersion() > 8 && noGravity) - packetSink.accept(getDataWatcherPacket(noGravityDataWatcher,this.noGravity)); + packetSink.accept(getDataWatcherPacket(noGravityDataWatcher, true)); } void tick() { @@ -378,33 +401,11 @@ public class REntity { protected static Function spawnPacketGenerator(Class spawnPacket, int posOffset) { Reflection.FieldAccessor entityId = Reflection.getField(spawnPacket, int.class, 0); - - int index; - switch (Core.getVersion()) { - case 8: - index = 9; - break; - case 9: - case 14: - case 12: - case 10: - case 15: - case 18: - index = 6; - break; - case 19: - default: - index = 4; - break; - } - - Reflection.FieldAccessor additionalData = Reflection.getField(spawnPacket, int.class, index); BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset); return entity -> { Object packet = Reflection.newInstance(spawnPacket); entityId.set(packet, entity.entityId); - additionalData.set(packet,entity.objectData); position.set(packet, entity.x, entity.y, entity.z); return packet; };