mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
Improve new Items system
This commit is contained in:
parent
904c0c6a19
commit
a2ca7646d0
@ -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 <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.bixilon.minosoft.game.datatypes.blocks;
|
|
||||||
|
|
||||||
public class Block {
|
|
||||||
}
|
|
@ -16,13 +16,12 @@ package de.bixilon.minosoft.game.datatypes.entities;
|
|||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Items {
|
public class Items {
|
||||||
|
|
||||||
// ProtocolVersion-> itemId << 4 | metaData, Identifier
|
// ProtocolVersion-> itemId << 4 | metaData, Identifier
|
||||||
|
static List<String> identifiers = new ArrayList<>();
|
||||||
static HashMap<ProtocolVersion, HashMap<Integer, String>> itemProtocolMap = new HashMap<>();
|
static HashMap<ProtocolVersion, HashMap<Integer, String>> itemProtocolMap = new HashMap<>();
|
||||||
|
|
||||||
public static String getIdentifierByLegacy(int id, int metaData, ProtocolVersion version) {
|
public static String getIdentifierByLegacy(int id, int metaData, ProtocolVersion version) {
|
||||||
@ -30,7 +29,12 @@ public class Items {
|
|||||||
if (metaData > 0 && metaData <= 15) {
|
if (metaData > 0 && metaData <= 15) {
|
||||||
itemId |= metaData;
|
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) {
|
public static String getIdentifier(int id, ProtocolVersion version) {
|
||||||
@ -42,22 +46,25 @@ public class Items {
|
|||||||
|
|
||||||
public static void load(ProtocolVersion version, JSONObject json) {
|
public static void load(ProtocolVersion version, JSONObject json) {
|
||||||
HashMap<Integer, String> versionMapping = new HashMap<>();
|
HashMap<Integer, String> versionMapping = new HashMap<>();
|
||||||
if (version.getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
|
// old format (with metadata
|
||||||
// old format (with metadata
|
for (Iterator<String> it = json.keys(); it.hasNext(); ) {
|
||||||
for (Iterator<String> it = json.keys(); it.hasNext(); ) {
|
String identifier = it.next();
|
||||||
String identifier = it.next();
|
if (identifiers.contains(identifier)) {
|
||||||
JSONObject identifierJSON = json.getJSONObject(identifier);
|
identifier = identifiers.get(identifiers.indexOf(identifier));
|
||||||
int itemId = identifierJSON.getInt("protocol_id") << 4;
|
} 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")) {
|
if (identifierJSON.has("protocol_meta")) {
|
||||||
itemId |= identifierJSON.getInt("protocol_meta");
|
itemId |= identifierJSON.getInt("protocol_meta");
|
||||||
}
|
}
|
||||||
versionMapping.put(itemId, identifier);
|
} else {
|
||||||
}
|
itemId = json.getJSONObject(identifier).getInt("protocol_id");
|
||||||
} else {
|
|
||||||
for (Iterator<String> it = json.keys(); it.hasNext(); ) {
|
|
||||||
String identifier = it.next();
|
|
||||||
versionMapping.put(json.getJSONObject(identifier).getInt("protocol_id"), identifier);
|
|
||||||
}
|
}
|
||||||
|
versionMapping.put(itemId, identifier);
|
||||||
}
|
}
|
||||||
itemProtocolMap.put(version, versionMapping);
|
itemProtocolMap.put(version, versionMapping);
|
||||||
}
|
}
|
||||||
|
@ -274,10 +274,12 @@ public class InByteBuffer {
|
|||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
return null;
|
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:
|
case VERSION_1_13_2:
|
||||||
if (readBoolean()) {
|
if (readBoolean()) {
|
||||||
// nothing here
|
|
||||||
return new Slot(Items.getIdentifier(readVarInt(), version), readByte(), readNBT());
|
return new Slot(Items.getIdentifier(readVarInt(), version), readByte(), readNBT());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user