Merge branch 'remapper' into master

This commit is contained in:
RednedEpic 2019-10-11 19:24:08 -05:00 committed by RednedEpic
commit 3c9fab9fc4
25 changed files with 48749 additions and 48299 deletions

View file

@ -30,10 +30,6 @@ import org.geysermc.api.logger.Logger;
import org.geysermc.api.plugin.PluginManager; import org.geysermc.api.plugin.PluginManager;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
public class Geyser { public class Geyser {

View file

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

View file

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

View file

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

View file

@ -36,7 +36,7 @@ import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; 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> { public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPacket> {
@Override @Override
@ -78,8 +78,8 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
Position position = new Position((int) packet.getPosition().getX(), Position position = new Position((int) packet.getPosition().getX(),
(int) Math.ceil(javaY * 2) / 2, (int) packet.getPosition().getZ()); (int) Math.ceil(javaY * 2) / 2, (int) packet.getPosition().getZ());
BedrockItem block = session.getChunkCache().getBlockAt(position); BlockEntry block = session.getChunkCache().getBlockAt(position);
if (!block.getIdentifier().contains("air")) if (!block.getJavaIdentifier().contains("air"))
colliding = true; colliding = true;
if (!colliding) if (!colliding)

View file

@ -25,22 +25,23 @@
package org.geysermc.connector.network.translators.block; package org.geysermc.connector.network.translators.block;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.geysermc.connector.network.translators.item.JavaItem;
@Getter @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) { private String javaIdentifier;
super(identifier, id); private int javaId;
this.data = data; private int bedrockId;
} private int bedrockData;
@Override @Override
public boolean equals(Object obj) { 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()));
} }
} }

View file

@ -1,19 +1,16 @@
package org.geysermc.connector.network.translators.block; 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 com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.translators.item.BedrockItem; import org.geysermc.connector.utils.Toolbox;
import org.geysermc.connector.utils.Remapper;
// Class for future expansion
public class BlockTranslator { public class BlockTranslator {
public BedrockItem getBedrockBlock(BlockState state) { public BlockEntry getBedrockBlock(BlockState state) {
BedrockItem bedrockItem = Remapper.BLOCK_REMAPPER.convertToBedrockB(new ItemStack(state.getId())); BlockEntry bedrockItem = Toolbox.BLOCK_ENTRIES.get(state.getId());
if (bedrockItem == null) { if (bedrockItem == null) {
GeyserLogger.DEFAULT.debug("Missing mapping for java block " + state.getId() + "\nPlease report this to Geyser."); 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; return bedrockItem;

View file

@ -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,
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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,
}

View file

@ -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();
}
}

View file

@ -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);
}
}

View file

@ -25,28 +25,23 @@
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
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; private String javaIdentifier;
protected int id; private int javaId;
public JavaItem(String identifier, int id) { private int bedrockId;
this.identifier = identifier; private int bedrockData;
this.id = id;
}
@Override
public int hashCode() {
return id;
}
@Override @Override
public boolean equals(Object obj) { 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()));
} }
} }

View file

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

View file

@ -31,7 +31,7 @@ import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit; 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; import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayerActionAckPacket> { public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayerActionAckPacket> {
@ -41,9 +41,16 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
switch (packet.getAction()) { switch (packet.getAction()) {
case FINISH_DIGGING: case FINISH_DIGGING:
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket(); UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(packet.getNewState()); updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(Vector3i.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ())); updateBlockPacket.setBlockPosition(Vector3i.from(
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode())); packet.getPosition().getX(),
packet.getPosition().getY(),
packet.getPosition().getZ()));
BlockEntry itemEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(packet.getNewState());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(itemEntry.getBedrockId() << 4 | itemEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket); session.getUpstream().sendPacket(updateBlockPacket);
break; break;
} }

View file

@ -7,7 +7,7 @@ import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit; 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; import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChangePacket> { public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChangePacket> {
@ -22,8 +22,9 @@ public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChang
record.getPosition().getZ() record.getPosition().getZ()
)); ));
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock()); BlockEntry itemEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode())); updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(itemEntry.getBedrockId() << 4 | itemEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket); session.getUpstream().sendPacket(updateBlockPacket);
} }

View file

@ -32,7 +32,7 @@ import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit; 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; import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMultiBlockChangePacket> { public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMultiBlockChangePacket> {
@ -48,8 +48,9 @@ public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMulti
record.getPosition().getZ() record.getPosition().getZ()
)); ));
BedrockItem bedrockItem = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock()); BlockEntry blockEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(bedrockItem.hashCode())); updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(blockEntry.getBedrockId() << 4 | blockEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket); session.getUpstream().sendPacket(updateBlockPacket);
} }

View file

@ -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.chunk.Column;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import org.geysermc.connector.network.translators.TranslatorsInit; 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.ChunkSection;
import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion;
public class ChunkUtils { public class ChunkUtils {
@ -33,11 +32,16 @@ public class ChunkUtils {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
BlockState block = storage.get(x, y, z); BlockState blockState = storage.get(x, y, z);
BedrockItem bedrockBlock = TranslatorsInit.getBlockTranslator().getBedrockBlock(block); BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), 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
}
} }
} }
} }

View file

@ -1,137 +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.block.type.*;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.item.JavaItem;
import java.util.HashMap;
import java.util.Map;
public class Remapper {
public static final String MINECRAFT_PREFIX = "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_PREFIX, "")))
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_PREFIX + color.name().toLowerCase() + "_" + coloredBlock.name().toLowerCase();
}
}
// Wood remapping
for (WoodBlock woodBlock : WoodBlock.values()) {
if (!getBedrockIdentifier(woodBlock.name()).equalsIgnoreCase(bedrockItem.getIdentifier().replace(MINECRAFT_PREFIX, "")))
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_PREFIX + woodType.name().toLowerCase() + "_" + woodBlock.name().toLowerCase();
}
}
// Stone remapping
if (bedrockItem.getIdentifier().replace(MINECRAFT_PREFIX, "").equalsIgnoreCase("stone") && !isTool(bedrockItem.getIdentifier())) {
for (StoneType stoneType : StoneType.values()) {
if (stoneType.getId() != bedrockItem.getData())
continue;
// Set the identifier to stone
identifier = MINECRAFT_PREFIX + stoneType.name().toLowerCase();
}
}
// Grass remapping
if (bedrockItem.getIdentifier().replace(MINECRAFT_PREFIX, "").equalsIgnoreCase("grass")) {
identifier = MINECRAFT_PREFIX + "grass_block";
}
if (bedrockItem.getIdentifier().replace(MINECRAFT_PREFIX, "").equalsIgnoreCase("tallgrass")) {
identifier = MINECRAFT_PREFIX + "grass";
}
// Dirt remapping
if (bedrockItem.getIdentifier().replace(MINECRAFT_PREFIX, "").equalsIgnoreCase("dirt")) {
if (bedrockItem.getData() == 0)
identifier = MINECRAFT_PREFIX + "dirt";
else
identifier = MINECRAFT_PREFIX + "coarse_dirt";
}
for (Map.Entry<Integer, ? extends JavaItem> javaItemEntry : javaItems.entrySet()) {
if (identifier.equalsIgnoreCase(javaItemEntry.getValue().getIdentifier())) {
if(!(javaToBedrock.containsKey(javaItemEntry.getValue()) && javaToBedrock.containsKey(javaItemEntry.getValue()))) {
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) {
JavaItem javaItem = Toolbox.JAVA_ITEMS.get(item.getId());
return javaItem != null ? javaToBedrock.get(javaItem) : null;
}
public BedrockItem convertToBedrockB(ItemStack block) {
JavaBlock javaBlock = Toolbox.JAVA_BLOCKS.get(block.getId());
return javaBlock != null ? javaToBedrock.get(javaBlock) : 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");
}
}

View file

@ -1,16 +1,16 @@
package org.geysermc.connector.utils; package org.geysermc.connector.utils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.nukkitx.network.VarInts; import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import com.nukkitx.protocol.bedrock.v361.BedrockUtils; import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
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.block.BlockEntry;
import org.geysermc.connector.network.translators.item.BedrockItem; import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.JavaItem;
import org.geysermc.connector.world.GlobalBlockPalette; import org.geysermc.connector.world.GlobalBlockPalette;
import java.io.InputStream; import java.io.InputStream;
@ -18,10 +18,16 @@ import java.util.*;
public class Toolbox { public class Toolbox {
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
public static final ByteBuf CACHED_PALLETE;
public static final TIntObjectMap<ItemEntry> ITEM_ENTRIES;
public static final TIntObjectMap<BlockEntry> BLOCK_ENTRIES;
static { static {
InputStream stream = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/cached_palette.json"); InputStream stream = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/cached_palette.json");
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
ArrayList<LinkedHashMap<String, Object>> entries = new ArrayList<>(); List<LinkedHashMap<String, Object>> entries = new ArrayList<>();
try { try {
entries = mapper.readValue(stream, ArrayList.class); entries = mapper.readValue(stream, ArrayList.class);
@ -29,103 +35,86 @@ public class Toolbox {
e.printStackTrace(); e.printStackTrace();
} }
Map<String, BedrockItem> bedrockBlocks = new HashMap<>(); ByteBuf cachedPalette = Unpooled.buffer();
Map<String, BedrockItem> bedrockItems = new HashMap<>(); VarInts.writeUnsignedInt(cachedPalette, entries.size());
ByteBuf b = Unpooled.buffer(); Map<String, Integer> blockIdToIdentifier = new HashMap<>();
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);
GlobalBlockPalette.registerMapping((int) e.get("id") << 4 | (int) e.get("data")); for (Map<String, Object> entry : entries) {
BedrockUtils.writeString(b, (String) e.get("name")); blockIdToIdentifier.put((String) entry.get("name"), (int) entry.get("id"));
b.writeShortLE((int) e.get("data"));
b.writeShortLE((int) e.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"); InputStream stream2 = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/items.json");
if (stream2 == null) { if (stream2 == null) {
throw new AssertionError("Items Table not found"); throw new AssertionError("Items Table not found");
} }
ObjectMapper mapper2 = new ObjectMapper(); ObjectMapper startGameItemMapper = new ObjectMapper();
ArrayList<HashMap> s = new ArrayList<>(); List<Map> startGameItems = new ArrayList<>();
try { try {
s = mapper2.readValue(stream2, ArrayList.class); startGameItems = startGameItemMapper.readValue(stream2, ArrayList.class);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
List<StartGamePacket.ItemEntry> l = new ArrayList<>(); List<StartGamePacket.ItemEntry> startGameEntries = new ArrayList<>();
for (HashMap e : s) { for (Map entry : startGameItems) {
l.add(new StartGamePacket.ItemEntry((String) e.get("name"), (short) ((int) e.get("id")))); startGameEntries.add(new StartGamePacket.ItemEntry((String) entry.get("name"), (short) ((int) entry.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);
}
} }
ITEMS = l; ITEMS = startGameEntries;
BEDROCK_ITEMS = bedrockItems; InputStream itemStream = Toolbox.class.getClassLoader().getResourceAsStream("items.json");
ObjectMapper itemMapper = new ObjectMapper();
Map<String, Map<String, Object>> items = new HashMap<>();
InputStream javaItemStream = Toolbox.class.getClassLoader().getResourceAsStream("java/java_items.json");
ObjectMapper javaItemMapper = new ObjectMapper();
Map<String, HashMap> javaItemList = new HashMap<>();
try { try {
javaItemList = javaItemMapper.readValue(javaItemStream, new TypeReference<Map<String, HashMap>>(){}); items = itemMapper.readValue(itemStream, LinkedHashMap.class);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
Map<Integer, JavaItem> javaItems = new HashMap<>(); TIntObjectMap<ItemEntry> itemEntries = new TIntObjectHashMap<>();
int itemIndex = 0;
for (String str : javaItemList.keySet()) { for (Map.Entry<String, Map<String, Object>> itemEntry : items.entrySet()) {
javaItems.put(Integer.parseInt(str), new JavaItem((String) javaItemList.get(str).get("identifier"), Integer.parseInt(str))); itemEntries.put(itemIndex, new ItemEntry(itemEntry.getKey(), itemIndex, (int) itemEntry.getValue().get("bedrock_id"), (int) itemEntry.getValue().get("bedrock_data")));
itemIndex++;
} }
JAVA_ITEMS = javaItems; ITEM_ENTRIES = itemEntries;
InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json");
ObjectMapper blockMapper = new ObjectMapper();
Map<String, Map<String, Object>> blocks = new HashMap<>();
InputStream javaItemStream2 = Toolbox.class.getClassLoader().getResourceAsStream("java/java_blocks.json");
ObjectMapper javaItemMapper2 = new ObjectMapper();
Map<String, HashMap> javaItemList2 = new HashMap<>();
try { try {
javaItemList2 = javaItemMapper2.readValue(javaItemStream2, new TypeReference<Map<String, HashMap>>(){}); blocks = blockMapper.readValue(blockStream, LinkedHashMap.class);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
Map<Integer, JavaBlock> javaBlocks = new HashMap<>(); TIntObjectMap<BlockEntry> blockEntries = new TIntObjectHashMap<>();
int blockIndex = 0;
for (String str : javaItemList2.keySet()) { for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
javaBlocks.put(Integer.parseInt(str), new JavaBlock((String) javaItemList2.get(str).get("identifier"), if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) {
(String) javaItemList2.get(str).get("data"), Integer.parseInt(str))); 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")));
} }
JAVA_BLOCKS = javaBlocks; blockIndex++;
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!");
} }
public static final Collection<StartGamePacket.ItemEntry> ITEMS; BLOCK_ENTRIES = blockEntries;
}
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;
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff