3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-04 23:30:17 +01:00

Implement new remapper

Dieser Commit ist enthalten in:
RednedEpic 2019-10-09 19:11:50 -05:00 committet von RednedEpic
Ursprung d99c285676
Commit a125967ec3
24 geänderte Dateien mit 48733 neuen und 48308 gelöschten Zeilen

Datei anzeigen

@ -129,8 +129,6 @@ public class GeyserConnector implements Connector {
logger.setDebug(config.isDebugMode());
Toolbox.CACHED_PALLETE.array();
TranslatorsInit.start();
commandMap = new GeyserCommandMap(this);

Datei anzeigen

@ -33,7 +33,7 @@ import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
import lombok.Getter;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.chunk.ChunkPosition;
import java.util.HashMap;
@ -69,10 +69,10 @@ public class ChunkCache {
}
}
public BedrockItem getBlockAt(Position position) {
public BlockEntry getBlockAt(Position position) {
ChunkPosition chunkPosition = new ChunkPosition(position.getX() >> 4, position.getZ() >> 4);
if (!chunks.containsKey(chunkPosition))
return BedrockItem.AIR;
return BlockEntry.AIR;
Column column = chunks.get(chunkPosition);
Chunk chunk = column.getChunks()[position.getY() >> 4];
@ -82,14 +82,11 @@ public class ChunkCache {
return TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
}
return BedrockItem.AIR;
return BlockEntry.AIR;
}
public void removeChunk(ChunkPosition position) {
if (chunks.containsKey(position)) {
chunks.remove(position);
}
chunks.remove(position);
sendEmptyChunk(position, true);
}

Datei anzeigen

@ -141,7 +141,6 @@ public class TranslatorsInit {
Registry.registerJava(ServerBlockChangePacket.class, new JavaBlockChangeTranslator());
Registry.registerJava(ServerMultiBlockChangePacket.class, new JavaMultiBlockChangeTranslator());
Registry.registerJava(ServerOpenWindowPacket.class, new OpenWindowPacketTranslator());
Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());

Datei anzeigen

@ -34,7 +34,7 @@ import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.block.BlockEntry;
public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPacket> {
@ -59,8 +59,8 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
Position position = new Position((int) packet.getPosition().getX(),
(int) Math.ceil((packet.getPosition().getY() - EntityType.PLAYER.getOffset()) * 2) / 2, (int) packet.getPosition().getZ());
BedrockItem block = session.getChunkCache().getBlockAt(position);
if (!block.getIdentifier().contains("air"))
BlockEntry block = session.getChunkCache().getBlockAt(position);
if (!block.getJavaIdentifier().contains("air"))
colliding = true;
if (!colliding)

Datei anzeigen

@ -25,22 +25,23 @@
package org.geysermc.connector.network.translators.block;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.geysermc.connector.network.translators.item.JavaItem;
@Getter
public class JavaBlock extends JavaItem {
@AllArgsConstructor
public class BlockEntry {
private String data;
public static BlockEntry AIR = new BlockEntry("minecraft:air", 0, 0, 0);
public JavaBlock(String identifier, String data, int id) {
super(identifier, id);
private String javaIdentifier;
private int javaId;
this.data = data;
}
private int bedrockId;
private int bedrockData;
@Override
public boolean equals(Object obj) {
return obj == this || (obj instanceof JavaBlock && ((JavaBlock) obj).id == this.id && ((JavaBlock) obj).identifier.equals(this.identifier));
return obj == this || (obj instanceof BlockEntry && ((BlockEntry) obj).getBedrockId() == this.getBedrockId() && ((BlockEntry) obj).getJavaIdentifier().equals(this.getJavaIdentifier()));
}
}

Datei anzeigen

@ -1,19 +1,16 @@
package org.geysermc.connector.network.translators.block;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.utils.Remapper;
import org.geysermc.connector.utils.Toolbox;
// Class for future expansion
public class BlockTranslator {
public BedrockItem getBedrockBlock(BlockState state) {
BedrockItem bedrockItem = Remapper.BLOCK_REMAPPER.convertToBedrockB(new ItemStack(state.getId()));
public BlockEntry getBedrockBlock(BlockState state) {
BlockEntry bedrockItem = Toolbox.BLOCK_ENTRIES.get(state.getId());
if (bedrockItem == null) {
GeyserLogger.DEFAULT.debug("Missing mapping for java block " + state.getId() + "/nPlease report this to Geyser.");
return BedrockItem.DIRT; // so we can walk and not getting stuck x)
return Toolbox.BLOCK_ENTRIES.get(10); // so we can walk and not getting stuck x)
}
return bedrockItem;

Datei anzeigen

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

Datei anzeigen

@ -1,55 +0,0 @@
/*
* 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.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();
}
}

Datei anzeigen

@ -1,46 +0,0 @@
/*
* 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.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();
}
}

Datei anzeigen

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

Datei anzeigen

@ -1,45 +0,0 @@
/*
* 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.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();
}
}

Datei anzeigen

@ -1,51 +0,0 @@
/*
* 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;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class BedrockItem {
public static BedrockItem AIR = new BedrockItem("minecraft:air", 0, 0);
public static BedrockItem DIRT = new BedrockItem("minecraft:dirt", 3, 0);
private String identifier;
private int id;
private int data;
@Override
public int hashCode() {
return id << 4 | data;
}
@Override
public boolean equals(Object obj) {
return obj == this || (obj instanceof BedrockItem && ((BedrockItem) obj).id == this.id && ((BedrockItem) obj).identifier.equals(this.identifier) && ((BedrockItem) obj).data == this.data);
}
}

Datei anzeigen

@ -25,28 +25,23 @@
package org.geysermc.connector.network.translators.item;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
public class JavaItem {
@AllArgsConstructor
public class ItemEntry {
public static JavaItem AIR = new JavaItem("minecraft:air", 0);
public static ItemEntry AIR = new ItemEntry("minecraft:air", 0, 0, 0);
protected String identifier;
protected int id;
private String javaIdentifier;
private int javaId;
public JavaItem(String identifier, int id) {
this.identifier = identifier;
this.id = id;
}
@Override
public int hashCode() {
return id;
}
private int bedrockId;
private int bedrockData;
@Override
public boolean equals(Object obj) {
return obj == this || (obj instanceof JavaItem && ((JavaItem) obj).id == this.id && ((JavaItem) obj).identifier.equals(this.identifier));
return obj == this || (obj instanceof ItemEntry && ((ItemEntry) obj).getBedrockId() == this.getBedrockId() && ((ItemEntry) obj).getJavaIdentifier().equals(this.getJavaIdentifier()));
}
}

Datei anzeigen

@ -42,8 +42,8 @@ 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.Remapper;
import org.geysermc.connector.utils.MessageUtils;
import org.geysermc.connector.utils.Toolbox;
import java.util.ArrayList;
import java.util.HashMap;
@ -53,12 +53,12 @@ import java.util.Map;
public class ItemTranslator {
public ItemStack translateToJava(ItemData data) {
JavaItem javaItem = getJavaItem(data);
ItemEntry javaItem = getItem(data);
if (data.getTag() == null) {
return new ItemStack(javaItem.getId(), data.getCount());
return new ItemStack(javaItem.getJavaId(), data.getCount());
}
return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag()));
return new ItemStack(javaItem.getJavaId(), data.getCount(), translateToJavaNBT(data.getTag()));
}
public ItemData translateToBedrock(ItemStack stack) {
@ -67,31 +67,32 @@ public class ItemTranslator {
return ItemData.of(3, (short)0, 0);
}
BedrockItem bedrockItem = getBedrockItem(stack);
ItemEntry bedrockItem = getItem(stack);
if (stack.getNBT() == null) {
return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount());
return ItemData.of(bedrockItem.getBedrockId(), (short) bedrockItem.getBedrockData(), stack.getAmount());
}
return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount(), translateToBedrockNBT(stack.getNBT()));
return ItemData.of(bedrockItem.getBedrockId(), (short) bedrockItem.getBedrockData(), stack.getAmount(), translateToBedrockNBT(stack.getNBT()));
}
public BedrockItem getBedrockItem(ItemStack stack) {
BedrockItem bedrockItem = Remapper.ITEM_REMAPPER.convertToBedrock(stack);
if (bedrockItem == null) {
public ItemEntry getItem(ItemStack stack) {
ItemEntry item = Toolbox.ITEM_ENTRIES.get(stack.getId());
if (item == null) {
GeyserLogger.DEFAULT.debug("Missing mapping for java item " + stack.getId());
return BedrockItem.AIR;
return ItemEntry.AIR;
}
return bedrockItem;
return item;
}
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;
public ItemEntry getItem(ItemData data) {
for (ItemEntry itemEntry : Toolbox.ITEM_ENTRIES.values()) {
if (itemEntry.getBedrockId() == data.getId() && itemEntry.getBedrockData() == data.getDamage()) {
return itemEntry;
}
}
return javaItem;
GeyserLogger.DEFAULT.debug("Missing mapping for bedrock item " + data.getId() + ":" + data.getDamage());
return ItemEntry.AIR;
}
private CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
@ -165,7 +166,7 @@ public class ItemTranslator {
if (tag instanceof com.nukkitx.nbt.tag.ListTag) {
com.nukkitx.nbt.tag.ListTag listTag = (com.nukkitx.nbt.tag.ListTag) tag;
List<Tag> tags = new ArrayList<Tag>();
List<Tag> tags = new ArrayList<>();
for (Object value : listTag.getValue()) {
if (!(value instanceof com.nukkitx.nbt.tag.Tag))
continue;

Datei anzeigen

@ -31,7 +31,7 @@ import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayerActionAckPacket> {
@ -41,7 +41,7 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
switch (packet.getAction()) {
case FINISH_DIGGING:
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(packet.getNewState());
BlockEntry bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(packet.getNewState());
updateBlockPacket.setBlockPosition(Vector3i.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()));
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
session.getUpstream().sendPacket(updateBlockPacket);

Datei anzeigen

@ -7,7 +7,7 @@ import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChangePacket> {
@ -21,7 +21,7 @@ public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChang
record.getPosition().getY(),
record.getPosition().getZ()));
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
BlockEntry bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
session.getUpstream().sendPacket(updateBlockPacket);

Datei anzeigen

@ -32,7 +32,7 @@ import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMultiBlockChangePacket> {
@ -47,7 +47,7 @@ public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMulti
record.getPosition().getY(),
record.getPosition().getZ()));
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
BlockEntry bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode()));
session.getUpstream().sendPacket(updateBlockPacket);

Datei anzeigen

@ -5,9 +5,8 @@ import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.chunk.ChunkSection;
import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion;
public class ChunkUtils {
@ -33,11 +32,16 @@ public class ChunkUtils {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
BlockState block = storage.get(x, y, z);
BedrockItem bedrockBlock = TranslatorsInit.getBlockTranslator().getBedrockBlock(block);
BlockState blockState = storage.get(x, y, z);
BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
bedrockBlock.getId() << 4 | bedrockBlock.getData());
block.getBedrockId() << 4 | block.getBedrockData());
if (block.getJavaIdentifier().contains("waterlogged=true")) {
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z),
9 << 4); // water id
}
}
}
}

Datei anzeigen

@ -1,155 +0,0 @@
package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
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.JavaItem;
import org.geysermc.connector.network.translators.block.type.ColoredBlock;
import org.geysermc.connector.network.translators.block.type.DyeColor;
import org.geysermc.connector.network.translators.block.type.StoneType;
import org.geysermc.connector.network.translators.block.type.WoodBlock;
import org.geysermc.connector.network.translators.block.type.WoodType;
import java.util.HashMap;
import java.util.Map;
public class Remapper {
public static final String MINECRAFT = "minecraft:";
public static final Remapper ITEM_REMAPPER = new Remapper();
public static final Remapper BLOCK_REMAPPER = new Remapper();
private final Map<BedrockItem, JavaItem> bedrockToJava;
private final Map<JavaItem, BedrockItem> javaToBedrock;
public Remapper() {
bedrockToJava = new HashMap<>();
javaToBedrock = new HashMap<>();
}
// Registers the conversions for bedrock <-> java
public void registerConversions(Map<String, BedrockItem> bedrockItems, Map<Integer, ? extends JavaItem> javaItems) {
for (Map.Entry<String, BedrockItem> bedrockItemEntry : bedrockItems.entrySet()) {
BedrockItem bedrockItem = bedrockItemEntry.getValue();
String identifier = bedrockItem.getIdentifier();
// Colorable block remapping
for (ColoredBlock coloredBlock : ColoredBlock.values()) {
if (!getBedrockIdentifier(coloredBlock.name()).equalsIgnoreCase(bedrockItem.getIdentifier().replace(MINECRAFT, "")))
continue;
// 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();
}
}
// Wood remapping
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();
}
}
// Stone remapping
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();
}
}
// Grass remapping
if (bedrockItem.getIdentifier().replace(MINECRAFT, "").equalsIgnoreCase("grass")) {
identifier = MINECRAFT + "grass_block";
}
if (bedrockItem.getIdentifier().replace(MINECRAFT, "").equalsIgnoreCase("tallgrass")) {
identifier = MINECRAFT + "grass";
}
// Dirt remapping
if (bedrockItem.getIdentifier().replace(MINECRAFT, "").equalsIgnoreCase("dirt")) {
if (bedrockItem.getData() == 0)
identifier = MINECRAFT + "dirt";
else
identifier = MINECRAFT + "coarse_dirt";
}
for (Map.Entry<Integer, ? extends JavaItem> javaItemEntry : javaItems.entrySet()) {
if (identifier.equalsIgnoreCase(javaItemEntry.getValue().getIdentifier())) {
bedrockToJava.put(bedrockItemEntry.getValue(), javaItemEntry.getValue());
javaToBedrock.put(javaItemEntry.getValue(), bedrockItemEntry.getValue());
}
}
}
}
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());
}
return null;
}
public BedrockItem convertToBedrock(ItemStack item) {
for (Map.Entry<Integer, JavaItem> javaItem : Toolbox.JAVA_ITEMS.entrySet()) {
if (javaItem.getValue().getId() != item.getId())
continue;
return javaToBedrock.get(javaItem.getValue());
}
return null;
}
public BedrockItem convertToBedrockB(ItemStack block) {
for (Map.Entry<Integer, JavaBlock> javaItem : Toolbox.JAVA_BLOCKS.entrySet()) {
if (javaItem.getValue().getId() != block.getId())
continue;
return javaToBedrock.get(javaItem.getValue());
}
return null;
}
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 isTool(String s) {
return s.contains("shovel") || s.contains("sword") || s.contains("axe") || s.contains("pickaxe") || s.contains("spade") || s.contains("hoe");
}
}

Datei anzeigen

@ -1,6 +1,5 @@
package org.geysermc.connector.utils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
@ -8,9 +7,8 @@ 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.block.JavaBlock;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.item.JavaItem;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
import java.io.InputStream;
@ -18,10 +16,16 @@ import java.util.*;
public class Toolbox {
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
public static final ByteBuf CACHED_PALLETE;
public static final Map<Integer, ItemEntry> ITEM_ENTRIES;
public static final Map<Integer, BlockEntry> BLOCK_ENTRIES;
static {
InputStream stream = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/cached_palette.json");
ObjectMapper mapper = new ObjectMapper();
ArrayList<LinkedHashMap<String, Object>> entries = new ArrayList<>();
List<LinkedHashMap<String, Object>> entries = new ArrayList<>();
try {
entries = mapper.readValue(stream, ArrayList.class);
@ -29,103 +33,86 @@ public class Toolbox {
e.printStackTrace();
}
Map<String, BedrockItem> bedrockBlocks = new HashMap<>();
Map<String, BedrockItem> bedrockItems = new HashMap<>();
ByteBuf cachedPalette = Unpooled.buffer();
VarInts.writeUnsignedInt(cachedPalette, entries.size());
ByteBuf b = Unpooled.buffer();
VarInts.writeUnsignedInt(b, entries.size());
for (Map<String, Object> e : entries) {
BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), (int) e.get("id"), (int) e.get("data"));
bedrockItems.put(bedrockItem.getId() + ":" + bedrockItem.getData(), bedrockItem);
bedrockBlocks.put(bedrockItem.getId() + ":" + bedrockItem.getData(), bedrockItem);
Map<String, Integer> blockIdToIdentifier = new HashMap<>();
GlobalBlockPalette.registerMapping((int) e.get("id") << 4 | (int) e.get("data"));
BedrockUtils.writeString(b, (String) e.get("name"));
b.writeShortLE((int) e.get("data"));
b.writeShortLE((int) e.get("id"));
for (Map<String, Object> entry : entries) {
blockIdToIdentifier.put((String) entry.get("name"), (int) entry.get("id"));
GlobalBlockPalette.registerMapping((int) entry.get("id") << 4 | (int) entry.get("data"));
BedrockUtils.writeString(cachedPalette, (String) entry.get("name"));
cachedPalette.writeShortLE((int) entry.get("data"));
cachedPalette.writeShortLE((int) entry.get("id"));
}
CACHED_PALLETE = b;
CACHED_PALLETE = cachedPalette;
InputStream stream2 = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/items.json");
if (stream2 == null) {
throw new AssertionError("Items Table not found");
}
ObjectMapper mapper2 = new ObjectMapper();
ArrayList<HashMap> s = new ArrayList<>();
ObjectMapper startGameItemMapper = new ObjectMapper();
List<Map> startGameItems = new ArrayList<>();
try {
s = mapper2.readValue(stream2, ArrayList.class);
startGameItems = startGameItemMapper.readValue(stream2, ArrayList.class);
} catch (Exception e) {
e.printStackTrace();
}
List<StartGamePacket.ItemEntry> l = new ArrayList<>();
for (HashMap e : s) {
l.add(new StartGamePacket.ItemEntry((String) e.get("name"), (short) ((int) e.get("id"))));
if (!bedrockItems.containsKey(e.get("id"))) {
BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), ((int) e.get("id")), 0);
bedrockItems.put(String.valueOf(bedrockItem.getId()), bedrockItem);
List<StartGamePacket.ItemEntry> startGameEntries = new ArrayList<>();
for (Map entry : startGameItems) {
startGameEntries.add(new StartGamePacket.ItemEntry((String) entry.get("name"), (short) ((int) entry.get("id"))));
}
ITEMS = startGameEntries;
InputStream itemStream = Toolbox.class.getClassLoader().getResourceAsStream("items.json");
ObjectMapper itemMapper = new ObjectMapper();
Map<String, Map<String, Object>> items = new HashMap<>();
try {
items = itemMapper.readValue(itemStream, LinkedHashMap.class);
} catch (Exception ex) {
ex.printStackTrace();
}
Map<Integer, ItemEntry> itemEntries = new HashMap<>();
int itemIndex = 0;
for (Map.Entry<String, Map<String, Object>> itemEntry : items.entrySet()) {
itemEntries.put(itemIndex, new ItemEntry(itemEntry.getKey(), itemIndex, (int) itemEntry.getValue().get("bedrock_id"), (int) itemEntry.getValue().get("bedrock_data")));
itemIndex++;
}
ITEM_ENTRIES = Collections.unmodifiableMap(itemEntries);
InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json");
ObjectMapper blockMapper = new ObjectMapper();
Map<String, Map<String, Object>> blocks = new HashMap<>();
try {
blocks = blockMapper.readValue(blockStream, LinkedHashMap.class);
} catch (Exception ex) {
ex.printStackTrace();
}
Map<Integer, BlockEntry> blockEntries = new HashMap<>();
int blockIndex = 0;
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) {
GeyserLogger.DEFAULT.debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " does not exist on bedrock edition!");
blockEntries.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, 248, 0)); // update block
} else {
blockEntries.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, blockIdToIdentifier.get(itemEntry.getValue().get("bedrock_identifier")), (int) itemEntry.getValue().get("bedrock_data")));
}
blockIndex++;
}
ITEMS = l;
BEDROCK_ITEMS = bedrockItems;
InputStream javaItemStream = Toolbox.class.getClassLoader().getResourceAsStream("java/java_items.json");
ObjectMapper javaItemMapper = new ObjectMapper();
Map<String, HashMap> javaItemList = new HashMap<>();
try {
javaItemList = javaItemMapper.readValue(javaItemStream, new TypeReference<Map<String, HashMap>>(){});
} catch (Exception ex) {
ex.printStackTrace();
}
Map<Integer, JavaItem> javaItems = new HashMap<>();
for (String str : javaItemList.keySet()) {
javaItems.put(Integer.parseInt(str), new JavaItem((String) javaItemList.get(str).get("identifier"), Integer.parseInt(str)));
}
JAVA_ITEMS = javaItems;
InputStream javaItemStream2 = Toolbox.class.getClassLoader().getResourceAsStream("java/java_blocks.json");
ObjectMapper javaItemMapper2 = new ObjectMapper();
Map<String, HashMap> javaItemList2 = new HashMap<>();
try {
javaItemList2 = javaItemMapper2.readValue(javaItemStream2, new TypeReference<Map<String, HashMap>>(){});
} catch (Exception ex) {
ex.printStackTrace();
}
Map<Integer, JavaBlock> javaBlocks = new HashMap<>();
for (String str : javaItemList2.keySet()) {
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;
BEDROCK_BLOCKS = bedrockBlocks;
GeyserLogger.DEFAULT.info("Remapping items...");
Remapper.ITEM_REMAPPER.registerConversions(bedrockItems, javaItems);
GeyserLogger.DEFAULT.info("Item remap complete!");
// TODO: Implement support for block data
GeyserLogger.DEFAULT.info("Remapping blocks...");
Remapper.BLOCK_REMAPPER.registerConversions(bedrockBlocks, javaBlocks);
GeyserLogger.DEFAULT.info("Block remap complete!");
BLOCK_ENTRIES = Collections.unmodifiableMap(blockEntries);
}
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
public static final ByteBuf CACHED_PALLETE;
public static final Map<String, BedrockItem> BEDROCK_ITEMS;
public static final Map<Integer, JavaItem> JAVA_ITEMS;
public static final Map<String, BedrockItem> BEDROCK_BLOCKS;
public static final Map<Integer, JavaBlock> JAVA_BLOCKS;
}

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei-Diff unterdrückt, da er zu groß ist Diff laden