Merge branch 'master' into chunks

This commit is contained in:
RednedEpic 2019-08-30 16:56:34 -05:00
commit bd8a00b5eb
15 changed files with 358 additions and 378 deletions

View file

@ -1,10 +1,10 @@
<img src="https://geysermc.org/img/oss_logo.png" alt="Geyser" width="600" height="170"/>
<img src="https://geysermc.org/img/oss_logo.png" alt="Geyser" width="600" height="170"/>
[![forthebadge made-with-java](http://ForTheBadge.com/images/badges/made-with-java.svg)](https://java.com/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Build Status](https://ci.nukkitx.com/job/Geyser/job/master/badge/icon)](https://ci.nukkitx.com/job/Geyser/job/master/)
[![Discord](https://img.shields.io/discord/597838753859633172.svg?color=%237289da&label=discord)](https://discord.gg/mRjbCsS)
[![Discord](https://img.shields.io/discord/597838753859633172.svg?color=%237289da&label=discord)](https://discord.gg/7ZDSKa5)
[![HitCount](http://hits.dwyl.io/Geyser/GeyserMC.svg)](http://hits.dwyl.io/Geyser/GeyserMC)
A bridge between Minecraft: Bedrock Edition and Minecraft: Java Edition, closing the gap from those wanting to play together.

View file

@ -147,7 +147,7 @@ public class GeyserConnector implements Connector {
}
}).join();
metrics = new Metrics("GeyserMC", instance.getConfig().getUUID(), true, java.util.logging.Logger.getLogger(""));
metrics = new Metrics("GeyserMC", config.getUUID(), true, java.util.logging.Logger.getLogger(""));
metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1));
metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount));
}

View file

@ -158,7 +158,7 @@ public class GeyserSession implements PlayerSession, Player {
public void disconnected(DisconnectedEvent event) {
loggedIn = false;
connector.getLogger().info(authenticationData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress() + " because of " + event.getReason());
// upstream.disconnect(event.getReason());
upstream.disconnect(event.getReason());
}
@Override
@ -299,4 +299,4 @@ public class GeyserSession implements PlayerSession, Player {
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
upstream.sendPacket(playStatusPacket);
}
}
}

View file

@ -1,30 +0,0 @@
package org.geysermc.connector.network.translators.item;
import lombok.Getter;
public enum DyeColor {
WHITE,
ORANGE,
MAGENTA,
LIGHT_BLUE,
YELLOW,
LIME,
PINK,
GRAY,
LIGHT_GRAY,
CYAN,
PURPLE,
BLUE,
BROWN,
GREEN,
RED,
BLACK;
@Getter
private final int id = ordinal();
public String getName() {
return name().toLowerCase();
}
}

View file

@ -43,11 +43,9 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.nukkitx.protocol.bedrock.data.ItemData;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.utils.MessageUtils;
import org.geysermc.connector.utils.Remapper;
import org.geysermc.connector.utils.Toolbox;
import org.geysermc.connector.utils.MessageUtils;
import java.rmi.MarshalException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -55,7 +53,7 @@ import java.util.Map;
public class ItemTranslator {
public static ItemStack translateToJava(ItemData data) {
public ItemStack translateToJava(ItemData data) {
JavaItem javaItem = getJavaItem(data);
if (data.getTag() == null) {
@ -64,7 +62,7 @@ public class ItemTranslator {
return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag()));
}
public static ItemData translateToBedrock(ItemStack stack) {
public ItemData translateToBedrock(ItemStack stack) {
// Most likely air if null
if (stack == null) {
return ItemData.AIR;
@ -77,54 +75,38 @@ public class ItemTranslator {
return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount(), translateToBedrockNBT(stack.getNBT()));
}
public static BedrockItem getBedrockItem(ItemStack stack) {
Map<String, Object> m = Remapper.JAVA_TO_BEDROCK.get(stack.getId());
if (m == null) {
public BedrockItem getBedrockItem(ItemStack stack) {
BedrockItem bedrockItem = Remapper.ITEM_REMAPPER.convertToBedrock(stack);
if (bedrockItem == null) {
GeyserLogger.DEFAULT.debug("Missing mapping for java item " + stack.getId());
return BedrockItem.AIR;
}
return new BedrockItem((String) m.get("name"), (Integer) m.get("id"), (Integer) m.get("data"));
return bedrockItem;
}
public static JavaItem getJavaItem(ItemData data) {
Map<String, Object> m = Remapper.BEDROCK_TO_JAVA.get(data.getId()).get(data.getDamage());
if (m == null) {
GeyserLogger.DEFAULT.debug("Missing mapping for bedrock item " + data.getId() + ":" + data.getDamage());
public JavaItem getJavaItem(ItemData data) {
JavaItem javaItem = Remapper.ITEM_REMAPPER.convertToJava(data);
if (javaItem == null) {
GeyserLogger.DEFAULT.debug("Missing mapping for bedrock item " + data.getId() + ":" + data.getDamage());
return JavaItem.AIR;
}
return new JavaItem((String) m.get("name"), (Integer) m.get("id"));
return javaItem;
}
public static BedrockItem getBedrockBlock(BlockState stack) {
Map<String, Object> m = Remapper.JAVA_TO_BEDROCK_BLOCKS.get(stack.getId());
if (m == null)
public BedrockItem getBedrockBlock(BlockState state) {
BedrockItem bedrockItem = Remapper.BLOCK_REMAPPER.convertToBedrock(new ItemStack(state.getId()));
if (bedrockItem == null) {
//GeyserLogger.DEFAULT.debug("Missing mapping for java item " + state.getId());
return BedrockItem.AIR;
return new BedrockItem((String) m.get("name"), (Integer) m.get("id"), (Integer) m.get("data"));
}
public static String getBedrockIdentifier(String javaIdentifier) {
if (!Remapper.JAVA_TO_BEDROCK.containsKey(javaIdentifier)) {
return javaIdentifier;
}
if ((int) Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("data") > 0) {
return Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("name") + ":" + Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("data");
}
return (String) Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("name");
return bedrockItem;
}
public static String getJavaIdentifier(String bedrockIdentifier, int data) {
if (!Remapper.BEDROCK_TO_JAVA.containsKey(bedrockIdentifier)) {
return bedrockIdentifier;
}
return (String) Remapper.BEDROCK_TO_JAVA.get(bedrockIdentifier).get(data).get("name");
}
private static CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
private CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
CompoundTag javaTag = new CompoundTag(tag.getName());
Map<String, Tag> javaValue = javaTag.getValue();
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
@ -141,7 +123,7 @@ public class ItemTranslator {
return javaTag;
}
private static Tag translateToJavaNBT(com.nukkitx.nbt.tag.Tag tag) {
private Tag translateToJavaNBT(com.nukkitx.nbt.tag.Tag tag) {
if (tag instanceof com.nukkitx.nbt.tag.ByteArrayTag) {
com.nukkitx.nbt.tag.ByteArrayTag byteArrayTag = (com.nukkitx.nbt.tag.ByteArrayTag) tag;
return new ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue());
@ -215,7 +197,7 @@ public class ItemTranslator {
return null;
}
private static com.nukkitx.nbt.tag.CompoundTag translateToBedrockNBT(CompoundTag tag) {
private com.nukkitx.nbt.tag.CompoundTag translateToBedrockNBT(CompoundTag tag) {
Map<String, com.nukkitx.nbt.tag.Tag<?>> javaValue = new HashMap<String, com.nukkitx.nbt.tag.Tag<?>>();
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
for (String str : tag.getValue().keySet()) {
@ -232,7 +214,7 @@ public class ItemTranslator {
return bedrockTag;
}
private static com.nukkitx.nbt.tag.Tag translateToBedrockNBT(Tag tag) {
private com.nukkitx.nbt.tag.Tag translateToBedrockNBT(Tag tag) {
if (tag instanceof ByteArrayTag) {
ByteArrayTag byteArrayTag = (ByteArrayTag) tag;
return new com.nukkitx.nbt.tag.ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue());

View file

@ -1,21 +0,0 @@
package org.geysermc.connector.network.translators.item;
import lombok.Getter;
public enum StoneType {
STONE,
GRANITE,
POLISHED_GRANITE,
DIORITE,
POLISHED_DIORITE,
ANDESITE,
POLISHED_ANDESITE;
@Getter
private final int id = ordinal();
public String getName() {
return name().toLowerCase();
}
}

View file

@ -1,20 +0,0 @@
package org.geysermc.connector.network.translators.item;
import lombok.Getter;
public enum WoodType {
OAK,
SPRUCE,
BIRCH,
JUNGLE,
ACACIA,
DARK_OAK;
@Getter
private final int id = ordinal();
public String getName() {
return name().toLowerCase();
}
}

View file

@ -0,0 +1,41 @@
/*
* 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.item.block;
public enum ColoredBlock {
BANNER,
CARPET,
CONCRETE,
CONCRETE_POWDER,
DYE,
SHULKER_BOX,
STAINED_GLASS,
STAINED_GLASS_PANE,
TERRACOTTA,
WOOL,
}

View file

@ -0,0 +1,38 @@
/*
* 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.item.block;
public enum WoodBlock {
BOAT,
FENCE,
LEAVES,
LOG,
PLANKS,
SAPLING,
SLAB,
}

View file

@ -0,0 +1,55 @@
/*
* 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.item.type;
import lombok.Getter;
public enum DyeColor {
WHITE,
ORANGE,
MAGENTA,
LIGHT_BLUE,
YELLOW,
LIME,
PINK,
GRAY,
LIGHT_GRAY,
CYAN,
PURPLE,
BLUE,
BROWN,
GREEN,
RED,
BLACK;
@Getter
private final int id = ordinal();
public String getName() {
return name().toLowerCase();
}
}

View file

@ -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.item.type;
import lombok.Getter;
public enum StoneType {
STONE,
GRANITE,
POLISHED_GRANITE,
DIORITE,
POLISHED_DIORITE,
ANDESITE,
POLISHED_ANDESITE;
@Getter
private final int id = ordinal();
public String getName() {
return name().toLowerCase();
}
}

View file

@ -0,0 +1,45 @@
/*
* 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.item.type;
import lombok.Getter;
public enum WoodType {
OAK,
SPRUCE,
BIRCH,
JUNGLE,
ACACIA,
DARK_OAK;
@Getter
private final int id = ordinal();
public String getName() {
return name().toLowerCase();
}
}

View file

@ -1,102 +0,0 @@
package org.geysermc.connector.utils;
import org.geysermc.connector.network.translators.item.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.jar.JarEntry;
class RemapUtils {
private static final String MINECRAFT = "minecraft:";
static void start() {
//colors
Remapper.predicates.put((x) -> x.getF().contains("white"), (x, y) -> {
//System.out.println(x.getIdentifier());
if(customColorIfNeeded(y)) return;
if (y.getIdentifier().replaceAll("terracotta", "stained_hardened_clay")
.replaceAll("white_", "")
.equalsIgnoreCase(x.getIdentifier()) && x.getData() == 0) {
for (DyeColor dyeColor : DyeColor.values()) {
JavaItem j = new JavaItem(y.getIdentifier().replaceAll("white", dyeColor.getName()), y.getId() + dyeColor.getId());
Remapper.convertions.computeIfAbsent(j, (q) -> new ArrayList<>());
Remapper.convertions.get(j).add(new BedrockItem(x.getIdentifier(), x.getId(), dyeColor.getId()));
}
}
});
//stone
Remapper.predicates.put((x) -> x.getF().contains("stone"), (x, y) -> {
//System.out.println(x.getIdentifier());
if(customStoneIfNeeded(y)) return;
if (y.getIdentifier().replaceAll("stone_", "")
.equalsIgnoreCase(x.getIdentifier()) && x.getData() == 0) {
/*for (WoodType woodType : WoodType.values()) {
JavaItem j = new JavaItem(y.getIdentifier().replaceAll("oak", woodType.getName()), y.getId());
Remapper.convertions.computeIfAbsent(j, (q) -> new ArrayList<>());
Remapper.convertions.get(j).add(new BedrockItem(x.getIdentifier(), x.getId(), woodType.getId()));
}*/
}
});
//shared name
Remapper.predicates.put((x) -> x.getF().equalsIgnoreCase(x.getS()), (x, y) -> {
try {
Remapper.convertions.computeIfAbsent(y, (q) -> new ArrayList<>());
Remapper.convertions.get(y).add(x);
} catch (Exception e) {
//
}
});
//wood
Remapper.predicates.put((x) -> x.getF().contains("oak"), (x, y) -> {
//System.out.println(x.getIdentifier());
if(customWoodIfNeeded(y)) return;
if (y.getIdentifier().replaceAll("oak_", "")
.equalsIgnoreCase(x.getIdentifier()) && x.getData() == 0) {
for (WoodType woodType : WoodType.values()) {
JavaItem j = new JavaItem(y.getIdentifier().replaceAll("oak", woodType.getName()), y.getId() + woodType.getId());
Remapper.convertions.computeIfAbsent(j, (q) -> new ArrayList<>());
Remapper.convertions.get(j).add(new BedrockItem(x.getIdentifier(), x.getId(), woodType.getId()));
}
}
});
}
private static boolean customColorIfNeeded(JavaItem j) {
if(j.getIdentifier().equalsIgnoreCase(MINECRAFT + "shulker_box")) {
Remapper.convertions.put(j, Arrays.asList(new BedrockItem(MINECRAFT + "undyed_shulker_box", 205, 0)));
return true;
}
return false;
}
private static boolean customWoodIfNeeded(JavaItem j) {
if(j.getIdentifier().contains("fence_gate")) return true;
for(WoodType t : WoodType.values()) {
if (j.getIdentifier().equalsIgnoreCase(MINECRAFT + "stripped_" + t.getName() +"_wood")) {
Remapper.convertions.put(j, Arrays.asList(new BedrockItem(MINECRAFT + "wood", 467, t.getId() + 8)));
return false;
}
}
return false;
}
private static boolean customStoneIfNeeded(JavaItem j) {
if (j.getIdentifier().equalsIgnoreCase(MINECRAFT + "stone")) {
for (StoneType type : StoneType.values()) {
Remapper.convertions.put(new JavaItem(MINECRAFT + type.getName(), type.getId() + 1), Arrays.asList(new BedrockItem(MINECRAFT + "stone", 1, type.getId())));
}
return true;
}
return false;
}
}

View file

@ -1,177 +1,121 @@
package org.geysermc.connector.utils;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.nukkitx.protocol.bedrock.data.ItemData;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.item.DyeColor;
import org.geysermc.connector.network.translators.item.JavaItem;
import org.geysermc.connector.network.translators.item.StoneType;
import org.geysermc.connector.network.translators.item.WoodType;
import org.geysermc.connector.network.translators.item.block.ColoredBlock;
import org.geysermc.connector.network.translators.item.type.DyeColor;
import org.geysermc.connector.network.translators.item.type.StoneType;
import org.geysermc.connector.network.translators.item.block.WoodBlock;
import org.geysermc.connector.network.translators.item.type.WoodType;
import java.io.File;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.HashMap;
import java.util.Map;
public class Remapper {
static final Map<JavaItem, List<BedrockItem>> convertions = new HashMap<>();
static final Map<Predicate<BiValue<String, String>>, BiConsumer<BedrockItem, JavaItem>> predicates = new LinkedHashMap<>();
public static final String MINECRAFT = "minecraft:";
private static List<String> specials = new ArrayList<>();
public static final Remapper ITEM_REMAPPER = new Remapper();
public static final Remapper BLOCK_REMAPPER = new Remapper();
public static Map<Object, Map<Integer, Map<String, Object>>> BEDROCK_TO_JAVA = new HashMap<>();
public static Map<Object, Map<String, Object>> JAVA_TO_BEDROCK = new HashMap<>();
private final Map<BedrockItem, JavaItem> bedrockToJava;
private final Map<JavaItem, BedrockItem> javaToBedrock;
public static Map<Object, Map<Integer, Map<String, Object>>> BEDROCK_TO_JAVA_BLOCKS = new HashMap<>();
public static Map<Object, Map<String, Object>> JAVA_TO_BEDROCK_BLOCKS = new HashMap<>();
public Remapper() {
bedrockToJava = new HashMap<>();
javaToBedrock = new HashMap<>();
}
// Method to convert java to bedrock
public static void addConversions(Map<String, BedrockItem> items1, Map<String, JavaItem> java) {
for (StoneType type : StoneType.values()) {
specials.add(type.getName());
}
// Registers the conversions for bedrock <-> java
public void registerConversions(Map<String, BedrockItem> bedrockItems, Map<String, JavaItem> javaItems) {
for (Map.Entry<String, BedrockItem> bedrockItemEntry : bedrockItems.entrySet()) {
BedrockItem bedrockItem = bedrockItemEntry.getValue();
String identifier = bedrockItem.getIdentifier();
RemapUtils.start();
for (ColoredBlock coloredBlock : ColoredBlock.values()) {
if (!getBedrockIdentifier(coloredBlock.name()).equalsIgnoreCase(bedrockItem.getIdentifier().replace(MINECRAFT, "")))
continue;
for (Map.Entry<String, JavaItem> javaItem : java.entrySet()) {
for (Map.Entry<String, BedrockItem> bedrockItem : items1.entrySet()) {
for(Predicate<BiValue<String, String>> predicate : predicates.keySet()) {
BiValue<String, String> b = new BiValue<>(javaItem.getKey(), bedrockItem.getKey());
BiValue<String, String> b2 = new BiValue<>(javaItem.getKey().replaceAll("_", ""), bedrockItem.getKey().replaceAll("_", ""));
if(predicate.test(b) || predicate.test(b2)) {
predicates.get(predicate).accept(bedrockItem.getValue(), javaItem.getValue());
}
// The item must be colorable
for (DyeColor color : DyeColor.values()) {
if (color.getId() != bedrockItem.getData())
continue;
// Add the color to the identifier
identifier = MINECRAFT + color.name().toLowerCase() + "_" + coloredBlock.name().toLowerCase();
}
}
for (WoodBlock woodBlock : WoodBlock.values()) {
if (!getBedrockIdentifier(woodBlock.name()).equalsIgnoreCase(bedrockItem.getIdentifier().replace(MINECRAFT, "")))
continue;
if (isTool(bedrockItem.getIdentifier()))
continue;
if (woodBlock == WoodBlock.SLAB && !bedrockItem.getIdentifier().contains("wooden"))
continue;
for (WoodType woodType : WoodType.values()) {
if (woodType.getId() != bedrockItem.getData())
continue;
identifier = MINECRAFT + woodType.name().toLowerCase() + "_" + woodBlock.name().toLowerCase();
}
}
if (bedrockItem.getIdentifier().replace(MINECRAFT, "").equalsIgnoreCase("stone") && !isTool(bedrockItem.getIdentifier())) {
for (StoneType stoneType : StoneType.values()) {
if (stoneType.getId() != bedrockItem.getData())
continue;
// Set the identifier to stone
identifier = MINECRAFT + stoneType.name().toLowerCase();
}
}
for (Map.Entry<String, JavaItem> javaItemEntry : javaItems.entrySet()) {
if (identifier.equalsIgnoreCase(javaItemEntry.getKey())) {
bedrockToJava.put(bedrockItemEntry.getValue(), javaItemEntry.getValue());
javaToBedrock.put(javaItemEntry.getValue(), bedrockItemEntry.getValue());
}
}
}
//for(BedrockItem item : )
for (DyeColor dyeColor : DyeColor.values()) {
JavaItem j = java.get("minecraft:white_shulker_box".replaceAll("white_", dyeColor.getName() + "_"));
// System.out.println(j.getIdentifier() + " " + convertions.get(j).get(0).getIdentifier() + ":" + convertions.get(j).get(0).getData());
}
for (Map.Entry<JavaItem, List<BedrockItem>> entry : convertions.entrySet()) {
for (BedrockItem item : entry.getValue()) {
JAVA_TO_BEDROCK.computeIfAbsent(entry.getKey().getIdentifier(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA.computeIfAbsent(item.getIdentifier(), (x) -> new HashMap<>());
JAVA_TO_BEDROCK.computeIfAbsent(entry.getKey().getId(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA.computeIfAbsent(item.getId(), (x) -> new HashMap<>());
Map<String, Object> map = JAVA_TO_BEDROCK.get(entry.getKey().getIdentifier());
Map<String, Object> map2 = JAVA_TO_BEDROCK.get(entry.getKey().getId());
map.put("name", item.getIdentifier());
map2.put("name", item.getIdentifier());
map.put("id", item.getId());
map2.put("id", item.getId());
map.put("data", item.getData());
map2.put("data", item.getData());
BEDROCK_TO_JAVA.get(item.getIdentifier()).computeIfAbsent(item.getData(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA.get(item.getId()).computeIfAbsent(item.getData(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA.get(item.getIdentifier()).get(item.getData()).put("name", entry.getKey().getIdentifier());
BEDROCK_TO_JAVA.get(item.getIdentifier()).get(item.getData()).put("id", entry.getKey().getId());
BEDROCK_TO_JAVA.get(item.getId()).get(item.getData()).put("name", entry.getKey().getIdentifier());
BEDROCK_TO_JAVA.get(item.getId()).get(item.getData()).put("id", entry.getKey().getId());
}
}
// Uncomment this for updated mappings
writeMappings();
}
public static void addConversions2(Map<String, BedrockItem> items1, Map<String, JavaItem> java) {
convertions.clear();
for (StoneType type : StoneType.values()) {
specials.add(type.getName());
public JavaItem convertToJava(ItemData item) {
for (Map.Entry<String, BedrockItem> bedrockItem : Toolbox.BEDROCK_ITEMS.entrySet()) {
if (bedrockItem.getValue().getId() != item.getId() || bedrockItem.getValue().getData() != item.getDamage())
continue;
return bedrockToJava.get(bedrockItem.getValue());
}
for (Map.Entry<String, JavaItem> javaItem : java.entrySet()) {
for (Map.Entry<String, BedrockItem> bedrockItem : items1.entrySet()) {
for (Predicate<BiValue<String, String>> predicate : predicates.keySet()) {
BiValue<String, String> b = new BiValue<>(javaItem.getKey(), bedrockItem.getKey());
BiValue<String, String> b2 = new BiValue<>(javaItem.getKey().replaceAll("_", ""), bedrockItem.getKey().replaceAll("_", ""));
if (predicate.test(b) || predicate.test(b2)) {
predicates.get(predicate).accept(bedrockItem.getValue(), javaItem.getValue());
}
}
}
}
//for(BedrockItem item : )
for (DyeColor dyeColor : DyeColor.values()) {
JavaItem j = java.get("minecraft:white_shulker_box".replaceAll("white_", dyeColor.getName() + "_"));
// System.out.println(j.getIdentifier() + " " + convertions.get(j).get(0).getIdentifier() + ":" + convertions.get(j).get(0).getData());
}
for (Map.Entry<JavaItem, List<BedrockItem>> entry : convertions.entrySet()) {
for (BedrockItem item : entry.getValue()) {
JAVA_TO_BEDROCK_BLOCKS.computeIfAbsent(entry.getKey().getIdentifier(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA_BLOCKS.computeIfAbsent(item.getIdentifier(), (x) -> new HashMap<>());
JAVA_TO_BEDROCK_BLOCKS.computeIfAbsent(entry.getKey().getId(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA_BLOCKS.computeIfAbsent(item.getId(), (x) -> new HashMap<>());
Map<String, Object> map = JAVA_TO_BEDROCK_BLOCKS.get(entry.getKey().getIdentifier());
Map<String, Object> map2 = JAVA_TO_BEDROCK_BLOCKS.get(entry.getKey().getId());
map.put("name", item.getIdentifier());
map2.put("name", item.getIdentifier());
map.put("id", item.getId());
map2.put("id", item.getId());
map.put("data", item.getData());
map2.put("data", item.getData());
BEDROCK_TO_JAVA_BLOCKS.get(item.getIdentifier()).computeIfAbsent(item.getData(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA_BLOCKS.get(item.getId()).computeIfAbsent(item.getData(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA_BLOCKS.get(item.getIdentifier()).get(item.getData()).put("name", entry.getKey().getIdentifier());
BEDROCK_TO_JAVA_BLOCKS.get(item.getIdentifier()).get(item.getData()).put("id", entry.getKey().getId());
BEDROCK_TO_JAVA_BLOCKS.get(item.getId()).get(item.getData()).put("name", entry.getKey().getIdentifier());
BEDROCK_TO_JAVA_BLOCKS.get(item.getId()).get(item.getData()).put("id", entry.getKey().getId());
}
}
writeMappings2();
return null;
}
private static void writeMappings() {
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
try {
writer.writeValue(new File("java_to_bedrock.json"), JAVA_TO_BEDROCK);
writer.writeValue(new File("bedrock_to_java.json"), BEDROCK_TO_JAVA);
} catch (Exception e) {
e.printStackTrace();
public BedrockItem convertToBedrock(ItemStack item) {
for (Map.Entry<String, JavaItem> javaItem : Toolbox.JAVA_ITEMS.entrySet()) {
if (javaItem.getValue().getId() != item.getId())
continue;
return javaToBedrock.get(javaItem.getValue());
}
return null;
}
private static void writeMappings2() {
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
try {
writer.writeValue(new File("java_to_bedrock_blocks.json"), JAVA_TO_BEDROCK_BLOCKS);
writer.writeValue(new File("bedrock_to_java_blocks.json"), BEDROCK_TO_JAVA_BLOCKS);
} catch (Exception e) {
e.printStackTrace();
}
private static String getBedrockIdentifier(String javaIdentifier) {
javaIdentifier = javaIdentifier.toLowerCase();
javaIdentifier = javaIdentifier.replace("terracotta", "stained_hardened_clay");
javaIdentifier = javaIdentifier.replace("slab", "wooden_slab");
javaIdentifier = javaIdentifier.replace("concrete_powder", "concretePowder");
return javaIdentifier;
}
private static boolean notSpecial(String key) {
for (String spec : specials) {
if (key.contains(spec)) {
return false;
}
}
return true;
}
private static boolean tool(String s) {
private static boolean isTool(String s) {
return s.contains("shovel") || s.contains("sword") || s.contains("axe") || s.contains("pickaxe") || s.contains("spade") || s.contains("hoe");
}
}

View file

@ -7,6 +7,7 @@ import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.item.JavaItem;
import org.geysermc.connector.world.GlobalBlockPalette;
@ -27,15 +28,15 @@ public class Toolbox {
e.printStackTrace();
}
Map<String, BedrockItem> m = new HashMap<>();
Map<String, BedrockItem> bedrockBlocks = new HashMap<>();
Map<String, BedrockItem> bedrockItems = new HashMap<>();
for (Map<String, Object> e : entries) {
BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), (int) e.get("id"), (int) e.get("data"));
m.put(bedrockItem.getIdentifier(), bedrockItem);
bedrockBlocks.put(bedrockItem.getIdentifier(), bedrockItem);
bedrockItems.put(bedrockItem.getIdentifier() + ":" + bedrockItem.getData(), bedrockItem);
}
ByteBuf b = Unpooled.buffer();
VarInts.writeUnsignedInt(b, entries.size());
for (Map<String, Object> e : entries) {
@ -88,8 +89,6 @@ public class Toolbox {
javaItems.put(str, new JavaItem(str, (int) javaItemList.get(str).get("protocol_id")));
}
Remapper.addConversions(bedrockItems, javaItems);
JAVA_ITEMS = javaItems;
InputStream javaItemStream2 = Toolbox.class.getClassLoader().getResourceAsStream("java/java_blocks.json");
@ -101,19 +100,22 @@ public class Toolbox {
ex.printStackTrace();
}
Map<String, JavaItem> javaItems2 = new HashMap<String, JavaItem>();
Map<String, JavaItem> javaBlocks = new HashMap<String, JavaItem>();
for (String str : javaItemList2.keySet()) {
javaItems2.put(str, new JavaItem(str, (int) javaItemList2.get(str).get("protocol_id")));
javaBlocks.put(str, new JavaItem(str, (int) javaItemList2.get(str).get("protocol_id")));
}
JAVA_BLOCKS = javaItems2;
JAVA_BLOCKS = javaBlocks;
BEDROCK_BLOCKS = bedrockBlocks;
BEDROCK_BLOCKS = m;
GeyserLogger.DEFAULT.debug("Remapping items...");
Remapper.ITEM_REMAPPER.registerConversions(bedrockItems, javaItems);
GeyserLogger.DEFAULT.debug("Item remap complete!");
Remapper.addConversions(bedrockItems, javaItems);
Remapper.addConversions2(m, javaItems2);
GeyserLogger.DEFAULT.debug("Remapping blocks...");
Remapper.BLOCK_REMAPPER.registerConversions(bedrockBlocks, javaBlocks);
GeyserLogger.DEFAULT.debug("Block remap complete!");
}
public static final Collection<StartGamePacket.ItemEntry> ITEMS;