fix some bugs with new itemIds

This commit is contained in:
Bixilon 2020-07-12 00:06:53 +02:00
parent 68b7cca778
commit 904c0c6a19
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 38 additions and 8 deletions

View File

@ -24,6 +24,7 @@ import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import de.bixilon.minosoft.util.OSUtil;
import de.bixilon.minosoft.util.Util;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
@ -121,7 +122,6 @@ public class Minosoft {
}
private static void loadMappings() {
try {
for (ProtocolVersion version : ProtocolVersion.versionMappingArray) {
if (version.getVersionNumber() < ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
@ -137,8 +137,8 @@ public class Minosoft {
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (IOException | JSONException e) {
Log.fatal("Error occurred while loading version mapping: " + e.getLocalizedMessage());
System.exit(1);
}
}

View File

@ -0,0 +1,17 @@
/*
* 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 {
}

View File

@ -16,7 +16,6 @@ package de.bixilon.minosoft.game.datatypes.entities;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import org.json.JSONObject;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -27,7 +26,11 @@ public class Items {
static HashMap<ProtocolVersion, HashMap<Integer, String>> itemProtocolMap = new HashMap<>();
public static String getIdentifierByLegacy(int id, int metaData, ProtocolVersion version) {
return getIdentifier((id << 4 | metaData), version);
int itemId = id << 4;
if (metaData > 0 && metaData <= 15) {
itemId |= metaData;
}
return getIdentifier(itemId, version);
}
public static String getIdentifier(int id, ProtocolVersion version) {
@ -37,10 +40,20 @@ public class Items {
return itemProtocolMap.get(version).get(id);
}
public static void load(ProtocolVersion version, JSONObject json) throws IOException {
public static void load(ProtocolVersion version, JSONObject json) {
HashMap<Integer, String> versionMapping = new HashMap<>();
if (version == ProtocolVersion.VERSION_1_13_2) {
// old format
if (version.getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
// old format (with metadata
for (Iterator<String> it = json.keys(); it.hasNext(); ) {
String identifier = it.next();
JSONObject identifierJSON = json.getJSONObject(identifier);
int itemId = identifierJSON.getInt("protocol_id") << 4;
if (identifierJSON.has("protocol_meta")) {
itemId |= identifierJSON.getInt("protocol_meta");
}
versionMapping.put(itemId, identifier);
}
} else {
for (Iterator<String> it = json.keys(); it.hasNext(); ) {
String identifier = it.next();
versionMapping.put(json.getJSONObject(identifier).getInt("protocol_id"), identifier);