diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/blocks/Block.java b/src/main/java/de/bixilon/minosoft/game/datatypes/blocks/Block.java
deleted file mode 100644
index 127a92ad9..000000000
--- a/src/main/java/de/bixilon/minosoft/game/datatypes/blocks/Block.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Codename Minosoft
- * Copyright (C) 2020 Moritz Zwerger
- *
- * This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program. If not, see .
- *
- * This software is not affiliated with Mojang AB, the original developer of Minecraft.
- */
-
-package de.bixilon.minosoft.game.datatypes.blocks;
-
-public class Block {
-}
diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Items.java b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Items.java
index 9e55a06ef..e8812d320 100644
--- a/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Items.java
+++ b/src/main/java/de/bixilon/minosoft/game/datatypes/entities/Items.java
@@ -16,13 +16,12 @@ package de.bixilon.minosoft.game.datatypes.entities;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import org.json.JSONObject;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
public class Items {
// ProtocolVersion-> itemId << 4 | metaData, Identifier
+ static List identifiers = new ArrayList<>();
static HashMap> itemProtocolMap = new HashMap<>();
public static String getIdentifierByLegacy(int id, int metaData, ProtocolVersion version) {
@@ -30,7 +29,12 @@ public class Items {
if (metaData > 0 && metaData <= 15) {
itemId |= metaData;
}
- return getIdentifier(itemId, version);
+ String identifier = getIdentifier(itemId, version);
+ if (identifier == null) {
+ // ignore meta data?
+ return getIdentifier(id << 4, version);
+ }
+ return identifier;
}
public static String getIdentifier(int id, ProtocolVersion version) {
@@ -42,22 +46,25 @@ public class Items {
public static void load(ProtocolVersion version, JSONObject json) {
HashMap versionMapping = new HashMap<>();
- if (version.getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
- // old format (with metadata
- for (Iterator it = json.keys(); it.hasNext(); ) {
- String identifier = it.next();
- JSONObject identifierJSON = json.getJSONObject(identifier);
- int itemId = identifierJSON.getInt("protocol_id") << 4;
+ // old format (with metadata
+ for (Iterator it = json.keys(); it.hasNext(); ) {
+ String identifier = it.next();
+ if (identifiers.contains(identifier)) {
+ identifier = identifiers.get(identifiers.indexOf(identifier));
+ } else {
+ identifiers.add(identifier);
+ }
+ JSONObject identifierJSON = json.getJSONObject(identifier);
+ int itemId;
+ if (version.getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
+ itemId = identifierJSON.getInt("protocol_id") << 4;
if (identifierJSON.has("protocol_meta")) {
itemId |= identifierJSON.getInt("protocol_meta");
}
- versionMapping.put(itemId, identifier);
- }
- } else {
- for (Iterator it = json.keys(); it.hasNext(); ) {
- String identifier = it.next();
- versionMapping.put(json.getJSONObject(identifier).getInt("protocol_id"), identifier);
+ } else {
+ itemId = json.getJSONObject(identifier).getInt("protocol_id");
}
+ versionMapping.put(itemId, identifier);
}
itemProtocolMap.put(version, versionMapping);
}
diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java
index e235c0897..52265dbfd 100644
--- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java
+++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java
@@ -274,10 +274,12 @@ public class InByteBuffer {
if (id == -1) {
return null;
}
- return new Slot(Items.getIdentifier(id, version), readByte(), readShort(), readNBT(version == ProtocolVersion.VERSION_1_7_10)); // compression
+ byte count = readByte();
+ short metaData = readShort();
+ CompoundTag nbt = readNBT(version == ProtocolVersion.VERSION_1_7_10);
+ return new Slot(Items.getIdentifierByLegacy(id, metaData, version), count, metaData, nbt);
case VERSION_1_13_2:
if (readBoolean()) {
- // nothing here
return new Slot(Items.getIdentifier(readVarInt(), version), readByte(), readNBT());
}
}