diff --git a/.idea/copyright/Geyser.xml b/.idea/copyright/Geyser.xml
new file mode 100644
index 00000000..568fa7b8
--- /dev/null
+++ b/.idea/copyright/Geyser.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
new file mode 100644
index 00000000..f2d5911c
--- /dev/null
+++ b/.idea/copyright/profiles_settings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
index cc5b6d23..fafa2bfa 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
@@ -43,22 +43,14 @@ import com.nukkitx.math.vector.Vector2f;
import com.nukkitx.math.vector.Vector2i;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
-import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.protocol.bedrock.BedrockServerSession;
import com.nukkitx.protocol.bedrock.data.ContainerId;
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
-import com.nukkitx.protocol.bedrock.packet.AvailableEntityIdentifiersPacket;
-import com.nukkitx.protocol.bedrock.packet.BiomeDefinitionListPacket;
-import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
-import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
-import com.nukkitx.protocol.bedrock.packet.TextPacket;
import com.nukkitx.protocol.bedrock.data.GameRuleData;
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
import com.nukkitx.protocol.bedrock.packet.*;
-
import lombok.Getter;
import lombok.Setter;
-
import org.geysermc.common.AuthType;
import org.geysermc.common.window.FormWindow;
import org.geysermc.connector.GeyserConnector;
@@ -176,7 +168,7 @@ public class GeyserSession implements CommandSender {
upstream.sendPacket(biomeDefinitionListPacket);
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
- entityPacket.setTag(CompoundTag.EMPTY);
+ entityPacket.setTag(Toolbox.ENTITY_IDENTIFIERS);
upstream.sendPacket(entityPacket);
InventoryContentPacket creativePacket = new InventoryContentPacket();
diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java
index f0b394fd..80d10b1a 100644
--- a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java
+++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java
@@ -58,13 +58,19 @@ public class EntityCache {
}
public void spawnEntity(Entity entity) {
- cacheEntity(entity);
- entity.spawnEntity(session);
+ if (cacheEntity(entity)) {
+ entity.spawnEntity(session);
+ }
}
- public void cacheEntity(Entity entity) {
- entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
- entities.put(entity.getGeyserId(), entity);
+ public boolean cacheEntity(Entity entity) {
+ // Check to see if the entity exists, otherwise we can end up with duplicated mobs
+ if (!entityIdTranslations.containsKey(entity.getEntityId())) {
+ entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
+ entities.put(entity.getGeyserId(), entity);
+ return true;
+ }
+ return false;
}
public boolean removeEntity(Entity entity, boolean force) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/ItemStackTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/ItemStackTranslator.java
index ac4bb2f2..356dcf98 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/ItemStackTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/ItemStackTranslator.java
@@ -54,7 +54,7 @@ public abstract class ItemStackTranslator {
public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
if (itemData == null) return null;
if (itemData.getTag() == null) {
- return new ItemStack(itemEntry.getJavaId(), itemData.getCount());
+ return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new com.github.steveice10.opennbt.tag.builtin.CompoundTag(""));
}
return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT(itemData.getTag()));
}
diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java
index 0df9b417..c72b9964 100644
--- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java
+++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java
@@ -55,6 +55,8 @@ public class Toolbox {
public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
+ public static CompoundTag ENTITY_IDENTIFIERS;
+
public static int BARRIER_INDEX = 0;
static {
@@ -143,6 +145,7 @@ public class Toolbox {
// Load the locale data
LocaleUtils.init();
+ /* Load creative items */
stream = getResource("bedrock/creative_items.json");
JsonNode creativeItemEntries;
@@ -172,6 +175,16 @@ public class Toolbox {
}
}
CREATIVE_ITEMS = creativeItems.toArray(new ItemData[0]);
+
+
+ /* Load entity identifiers */
+ stream = Toolbox.getResource("bedrock/entity_identifiers.dat");
+
+ try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream)) {
+ ENTITY_IDENTIFIERS = (CompoundTag) nbtInputStream.readTag();
+ } catch (Exception e) {
+ throw new AssertionError("Unable to get entities from entity identifiers", e);
+ }
}
/**
diff --git a/connector/src/main/resources/bedrock/entity_identifiers.dat b/connector/src/main/resources/bedrock/entity_identifiers.dat
index c4f1524a..cb8f0481 100644
Binary files a/connector/src/main/resources/bedrock/entity_identifiers.dat and b/connector/src/main/resources/bedrock/entity_identifiers.dat differ