forked from GeyserMC/Geyser
Fix block palette
This commit is contained in:
parent
9b7fe5c879
commit
5fee344743
4 changed files with 12 additions and 18 deletions
|
@ -50,7 +50,6 @@ import org.geysermc.connector.plugin.GeyserPluginLoader;
|
||||||
import org.geysermc.connector.plugin.GeyserPluginManager;
|
import org.geysermc.connector.plugin.GeyserPluginManager;
|
||||||
import org.geysermc.connector.thread.PingPassthroughThread;
|
import org.geysermc.connector.thread.PingPassthroughThread;
|
||||||
import org.geysermc.connector.utils.FileUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
import org.geysermc.connector.utils.Toolbox;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -117,7 +116,6 @@ public class GeyserConnector implements Connector {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
||||||
|
|
||||||
config = FileUtils.loadConfig(configFile, GeyserConfiguration.class);
|
config = FileUtils.loadConfig(configFile, GeyserConfiguration.class);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
||||||
|
|
|
@ -29,7 +29,6 @@ import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
||||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
|
||||||
import com.github.steveice10.packetlib.Client;
|
import com.github.steveice10.packetlib.Client;
|
||||||
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
||||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||||
|
@ -296,7 +295,7 @@ public class GeyserSession implements Player {
|
||||||
startGamePacket.setCurrentTick(0);
|
startGamePacket.setCurrentTick(0);
|
||||||
startGamePacket.setEnchantmentSeed(0);
|
startGamePacket.setEnchantmentSeed(0);
|
||||||
startGamePacket.setMultiplayerCorrelationId("");
|
startGamePacket.setMultiplayerCorrelationId("");
|
||||||
startGamePacket.setBlockPalette(Toolbox.CACHED_PALLETE);
|
startGamePacket.setBlockPalette(Toolbox.BLOCKS);
|
||||||
startGamePacket.setItemEntries(Toolbox.ITEMS);
|
startGamePacket.setItemEntries(Toolbox.ITEMS);
|
||||||
startGamePacket.setMovementServerAuthoritative(true);
|
startGamePacket.setMovementServerAuthoritative(true);
|
||||||
upstream.sendPacket(startGamePacket);
|
upstream.sendPacket(startGamePacket);
|
||||||
|
|
|
@ -21,34 +21,31 @@ import java.util.*;
|
||||||
public class Toolbox {
|
public class Toolbox {
|
||||||
|
|
||||||
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
|
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
|
||||||
public static ListTag<CompoundTag> CACHED_PALLETE;
|
public static ListTag<CompoundTag> BLOCKS;
|
||||||
|
|
||||||
public static final TIntObjectMap<ItemEntry> ITEM_ENTRIES;
|
public static final TIntObjectMap<ItemEntry> ITEM_ENTRIES;
|
||||||
public static final TIntObjectMap<BlockEntry> BLOCK_ENTRIES;
|
public static final TIntObjectMap<BlockEntry> BLOCK_ENTRIES;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/cached_palette.dat");
|
InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat");
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
throw new AssertionError("Unable to find cached_palette.dat");
|
throw new AssertionError("Unable to find bedrock/runtime_block_states.dat");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Integer> blockIdToIdentifier = new HashMap<>();
|
Map<String, Integer> blockIdToIdentifier = new HashMap<>();
|
||||||
CompoundTag tag;
|
ListTag<CompoundTag> blocksTag;
|
||||||
|
|
||||||
NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream);
|
NBTInputStream nbtInputStream = NbtUtils.createReader(stream);
|
||||||
try {
|
try {
|
||||||
tag = (CompoundTag) nbtInputStream.readTag();
|
blocksTag = (ListTag<CompoundTag>) nbtInputStream.readTag();
|
||||||
System.out.println(tag.getValue().values());
|
|
||||||
System.out.println(tag.getAsList("Palette", CompoundTag.class));
|
|
||||||
nbtInputStream.close();
|
nbtInputStream.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
GeyserLogger.DEFAULT.warning("Failed to get blocks from cached palette, please report this error!");
|
GeyserLogger.DEFAULT.warning("Failed to get blocks from runtime block states, please report this error!");
|
||||||
throw new AssertionError(ex);
|
throw new AssertionError(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CompoundTag> entries = tag.getAsList("Palette", CompoundTag.class);
|
for (CompoundTag entry : blocksTag.getValue()) {
|
||||||
for (CompoundTag entry : entries) {
|
String name = entry.getAsCompound("block").getAsString("name");
|
||||||
String name = entry.getAsString("name");
|
|
||||||
int id = entry.getAsShort("id");
|
int id = entry.getAsShort("id");
|
||||||
int data = entry.getAsShort("meta");
|
int data = entry.getAsShort("meta");
|
||||||
|
|
||||||
|
@ -56,7 +53,7 @@ public class Toolbox {
|
||||||
GlobalBlockPalette.registerMapping(id << 4 | data);
|
GlobalBlockPalette.registerMapping(id << 4 | data);
|
||||||
}
|
}
|
||||||
|
|
||||||
CACHED_PALLETE = new ListTag<>("Palette", CompoundTag.class, tag.getAsList("Palette", CompoundTag.class));
|
BLOCKS = blocksTag;
|
||||||
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");
|
||||||
|
@ -112,7 +109,7 @@ public class Toolbox {
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
|
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
|
||||||
if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) {
|
if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) {
|
||||||
GeyserLogger.DEFAULT.debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " does not exist on bedrock edition!");
|
GeyserLogger.DEFAULT.debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " was not found for bedrock edition!");
|
||||||
blockEntries.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, 248, 0)); // update block
|
blockEntries.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, 248, 0)); // update block
|
||||||
} else {
|
} else {
|
||||||
blockEntries.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, blockIdToIdentifier.get(itemEntry.getValue().get("bedrock_identifier")), (int) itemEntry.getValue().get("bedrock_data")));
|
blockEntries.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, blockIdToIdentifier.get(itemEntry.getValue().get("bedrock_identifier")), (int) itemEntry.getValue().get("bedrock_data")));
|
||||||
|
|
Loading…
Reference in a new issue