Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 00:23:03 +01:00
Fix most all metadatable items not showing up (for the most part)
The actual block data translation (like stair rotation) all needs to be done still, but this is a huge step toward getting that complete.
Dieser Commit ist enthalten in:
Ursprung
610ccbdc62
Commit
b6d4bf5147
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019 GeyserMC. http://geysermc.org
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* @author GeyserMC
|
||||||
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geysermc.connector.network.translators.block;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.geysermc.connector.network.translators.item.JavaItem;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class JavaBlock extends JavaItem {
|
||||||
|
|
||||||
|
private String data;
|
||||||
|
|
||||||
|
public JavaBlock(String identifier, String data, int id) {
|
||||||
|
super(identifier, id);
|
||||||
|
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return obj == this || (obj instanceof JavaBlock && ((JavaBlock) obj).id == this.id && ((JavaBlock) obj).identifier.equals(this.identifier));
|
||||||
|
}
|
||||||
|
}
|
@ -25,17 +25,20 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.item;
|
package org.geysermc.connector.network.translators.item;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
|
||||||
public class JavaItem {
|
public class JavaItem {
|
||||||
|
|
||||||
public static JavaItem AIR = new JavaItem("minecraft:air", 0);
|
public static JavaItem AIR = new JavaItem("minecraft:air", 0);
|
||||||
|
|
||||||
private String identifier;
|
protected String identifier;
|
||||||
private int id;
|
protected int id;
|
||||||
|
|
||||||
|
public JavaItem(String identifier, int id) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
@ -2,6 +2,7 @@ package org.geysermc.connector.utils;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||||
|
import org.geysermc.connector.network.translators.block.JavaBlock;
|
||||||
import org.geysermc.connector.network.translators.item.BedrockItem;
|
import org.geysermc.connector.network.translators.item.BedrockItem;
|
||||||
import org.geysermc.connector.network.translators.item.JavaItem;
|
import org.geysermc.connector.network.translators.item.JavaItem;
|
||||||
import org.geysermc.connector.network.translators.block.type.ColoredBlock;
|
import org.geysermc.connector.network.translators.block.type.ColoredBlock;
|
||||||
@ -29,7 +30,7 @@ public class Remapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Registers the conversions for bedrock <-> java
|
// Registers the conversions for bedrock <-> java
|
||||||
public void registerConversions(Map<String, BedrockItem> bedrockItems, Map<String, JavaItem> javaItems) {
|
public void registerConversions(Map<String, BedrockItem> bedrockItems, Map<Integer, ? extends JavaItem> javaItems) {
|
||||||
for (Map.Entry<String, BedrockItem> bedrockItemEntry : bedrockItems.entrySet()) {
|
for (Map.Entry<String, BedrockItem> bedrockItemEntry : bedrockItems.entrySet()) {
|
||||||
BedrockItem bedrockItem = bedrockItemEntry.getValue();
|
BedrockItem bedrockItem = bedrockItemEntry.getValue();
|
||||||
String identifier = bedrockItem.getIdentifier();
|
String identifier = bedrockItem.getIdentifier();
|
||||||
@ -96,8 +97,8 @@ public class Remapper {
|
|||||||
identifier = MINECRAFT + "coarse_dirt";
|
identifier = MINECRAFT + "coarse_dirt";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, JavaItem> javaItemEntry : javaItems.entrySet()) {
|
for (Map.Entry<Integer, ? extends JavaItem> javaItemEntry : javaItems.entrySet()) {
|
||||||
if (identifier.equalsIgnoreCase(javaItemEntry.getKey())) {
|
if (identifier.equalsIgnoreCase(javaItemEntry.getValue().getIdentifier())) {
|
||||||
bedrockToJava.put(bedrockItemEntry.getValue(), javaItemEntry.getValue());
|
bedrockToJava.put(bedrockItemEntry.getValue(), javaItemEntry.getValue());
|
||||||
javaToBedrock.put(javaItemEntry.getValue(), bedrockItemEntry.getValue());
|
javaToBedrock.put(javaItemEntry.getValue(), bedrockItemEntry.getValue());
|
||||||
}
|
}
|
||||||
@ -117,7 +118,7 @@ public class Remapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BedrockItem convertToBedrock(ItemStack item) {
|
public BedrockItem convertToBedrock(ItemStack item) {
|
||||||
for (Map.Entry<String, JavaItem> javaItem : Toolbox.JAVA_ITEMS.entrySet()) {
|
for (Map.Entry<Integer, JavaItem> javaItem : Toolbox.JAVA_ITEMS.entrySet()) {
|
||||||
if (javaItem.getValue().getId() != item.getId())
|
if (javaItem.getValue().getId() != item.getId())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ public class Remapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BedrockItem convertToBedrockB(ItemStack block) {
|
public BedrockItem convertToBedrockB(ItemStack block) {
|
||||||
for (Map.Entry<String, JavaItem> javaItem : Toolbox.JAVA_BLOCKS.entrySet()) {
|
for (Map.Entry<Integer, JavaBlock> javaItem : Toolbox.JAVA_BLOCKS.entrySet()) {
|
||||||
if (javaItem.getValue().getId() != block.getId())
|
if (javaItem.getValue().getId() != block.getId())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import org.geysermc.connector.console.GeyserLogger;
|
import org.geysermc.connector.console.GeyserLogger;
|
||||||
|
import org.geysermc.connector.network.translators.block.JavaBlock;
|
||||||
import org.geysermc.connector.network.translators.item.BedrockItem;
|
import org.geysermc.connector.network.translators.item.BedrockItem;
|
||||||
import org.geysermc.connector.network.translators.item.JavaItem;
|
import org.geysermc.connector.network.translators.item.JavaItem;
|
||||||
import org.geysermc.connector.world.GlobalBlockPalette;
|
import org.geysermc.connector.world.GlobalBlockPalette;
|
||||||
@ -35,8 +36,8 @@ public class Toolbox {
|
|||||||
VarInts.writeUnsignedInt(b, entries.size());
|
VarInts.writeUnsignedInt(b, entries.size());
|
||||||
for (Map<String, Object> e : entries) {
|
for (Map<String, Object> e : entries) {
|
||||||
BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), (int) e.get("id"), (int) e.get("data"));
|
BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), (int) e.get("id"), (int) e.get("data"));
|
||||||
bedrockItems.put(bedrockItem.getIdentifier() + ":" + bedrockItem.getData(), bedrockItem);
|
bedrockItems.put(bedrockItem.getId() + ":" + bedrockItem.getData(), bedrockItem);
|
||||||
bedrockBlocks.put(bedrockItem.getIdentifier() + ":" + bedrockItem.getData(), bedrockItem);
|
bedrockBlocks.put(bedrockItem.getId() + ":" + bedrockItem.getData(), bedrockItem);
|
||||||
|
|
||||||
GlobalBlockPalette.registerMapping((int) e.get("id") << 4 | (int) e.get("data"));
|
GlobalBlockPalette.registerMapping((int) e.get("id") << 4 | (int) e.get("data"));
|
||||||
BedrockUtils.writeString(b, (String) e.get("name"));
|
BedrockUtils.writeString(b, (String) e.get("name"));
|
||||||
@ -62,9 +63,9 @@ public class Toolbox {
|
|||||||
List<StartGamePacket.ItemEntry> l = new ArrayList<>();
|
List<StartGamePacket.ItemEntry> l = new ArrayList<>();
|
||||||
for (HashMap e : s) {
|
for (HashMap e : s) {
|
||||||
l.add(new StartGamePacket.ItemEntry((String) e.get("name"), (short) ((int) e.get("id"))));
|
l.add(new StartGamePacket.ItemEntry((String) e.get("name"), (short) ((int) e.get("id"))));
|
||||||
if (!bedrockItems.containsKey(e.get("name"))) {
|
if (!bedrockItems.containsKey(e.get("id"))) {
|
||||||
BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), ((int) e.get("id")), 0);
|
BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), ((int) e.get("id")), 0);
|
||||||
bedrockItems.put(bedrockItem.getIdentifier(), bedrockItem);
|
bedrockItems.put(String.valueOf(bedrockItem.getId()), bedrockItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,10 +82,10 @@ public class Toolbox {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, JavaItem> javaItems = new HashMap<String, JavaItem>();
|
Map<Integer, JavaItem> javaItems = new HashMap<>();
|
||||||
|
|
||||||
for (String str : javaItemList.keySet()) {
|
for (String str : javaItemList.keySet()) {
|
||||||
javaItems.put(str, new JavaItem(str, (int) javaItemList.get(str).get("protocol_id")));
|
javaItems.put(Integer.parseInt(str), new JavaItem((String) javaItemList.get(str).get("identifier"), Integer.parseInt(str)));
|
||||||
}
|
}
|
||||||
|
|
||||||
JAVA_ITEMS = javaItems;
|
JAVA_ITEMS = javaItems;
|
||||||
@ -98,10 +99,11 @@ public class Toolbox {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, JavaItem> javaBlocks = new HashMap<String, JavaItem>();
|
Map<Integer, JavaBlock> javaBlocks = new HashMap<>();
|
||||||
|
|
||||||
for (String str : javaItemList2.keySet()) {
|
for (String str : javaItemList2.keySet()) {
|
||||||
javaBlocks.put(str, new JavaItem(str, (int) javaItemList2.get(str).get("protocol_id")));
|
javaBlocks.put(Integer.parseInt(str), new JavaBlock((String) javaItemList2.get(str).get("identifier"),
|
||||||
|
(String) javaItemList2.get(str).get("data"), Integer.parseInt(str)));
|
||||||
}
|
}
|
||||||
|
|
||||||
JAVA_BLOCKS = javaBlocks;
|
JAVA_BLOCKS = javaBlocks;
|
||||||
@ -111,6 +113,7 @@ public class Toolbox {
|
|||||||
Remapper.ITEM_REMAPPER.registerConversions(bedrockItems, javaItems);
|
Remapper.ITEM_REMAPPER.registerConversions(bedrockItems, javaItems);
|
||||||
GeyserLogger.DEFAULT.info("Item remap complete!");
|
GeyserLogger.DEFAULT.info("Item remap complete!");
|
||||||
|
|
||||||
|
// TODO: Implement support for block data
|
||||||
GeyserLogger.DEFAULT.info("Remapping blocks...");
|
GeyserLogger.DEFAULT.info("Remapping blocks...");
|
||||||
Remapper.BLOCK_REMAPPER.registerConversions(bedrockBlocks, javaBlocks);
|
Remapper.BLOCK_REMAPPER.registerConversions(bedrockBlocks, javaBlocks);
|
||||||
GeyserLogger.DEFAULT.info("Block remap complete!");
|
GeyserLogger.DEFAULT.info("Block remap complete!");
|
||||||
@ -121,10 +124,8 @@ public class Toolbox {
|
|||||||
public static final ByteBuf CACHED_PALLETE;
|
public static final ByteBuf CACHED_PALLETE;
|
||||||
|
|
||||||
public static final Map<String, BedrockItem> BEDROCK_ITEMS;
|
public static final Map<String, BedrockItem> BEDROCK_ITEMS;
|
||||||
public static final Map<String, JavaItem> JAVA_ITEMS;
|
public static final Map<Integer, JavaItem> JAVA_ITEMS;
|
||||||
|
|
||||||
public static final Map<String, BedrockItem> BEDROCK_BLOCKS;
|
public static final Map<String, BedrockItem> BEDROCK_BLOCKS;
|
||||||
public static final Map<String, JavaItem> JAVA_BLOCKS;
|
public static final Map<Integer, JavaBlock> JAVA_BLOCKS;
|
||||||
|
|
||||||
//public static final byte[] EMPTY_CHUNK;
|
|
||||||
}
|
}
|
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren