From b25048257454b27f32baea14c03da05092729759 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Mon, 16 Jan 2023 21:34:13 +0100 Subject: [PATCH 01/11] 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 c9b15b6aa6a9e296fa3a7c6b1728333623e03a8a Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Tue, 17 Jan 2023 12:36:30 +0100 Subject: [PATCH 02/11] 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 03/11] 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 04/11] 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 05/11] 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 06/11] 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 07/11] 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 08/11] 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 09/11] 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 10/11] 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 11/11] 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)); } }