Skip to content

Commit

Permalink
Work
Browse files Browse the repository at this point in the history
  • Loading branch information
bundabrg committed Sep 11, 2020
1 parent ff9c719 commit 409406c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void loadConfig() {
*/
@GeyserEventHandler(priority = EventHandler.PRIORITY.HIGH)
public void onGeyserStart(GeyserStartEvent event) {
Edition edition = registeredEditions.get("geyser-" + config.getEdition());
Edition edition = registeredEditions.get(config.getEdition());

if (edition == null) {
getLogger().error(String.format("Invalid Edition '%s'. Extension disabled.", config.getEdition()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

import au.com.grieve.geyser.reversion.translators.geyser.v408.handlers.StartGameHandler_Geyser_v408;
import au.com.grieve.reversion.editions.bedrock.BedrockRegisteredTranslator;
import au.com.grieve.reversion.editions.bedrock.BedrockTranslator;
import au.com.grieve.reversion.editions.bedrock.handlers.LevelChunkHandler_Bedrock;
import au.com.grieve.reversion.editions.bedrock.mappers.BlockMapper;
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import com.nukkitx.protocol.bedrock.v408.Bedrock_v408;

Expand All @@ -30,7 +34,9 @@ public class Register_Geyser_v408 {
.toEdition("geyser-bedrock")
.toProtocolVersion(408)
.codec(Bedrock_v408.V408_CODEC)
.translator(Translator_Geyser_v408.class)
.translator(BedrockTranslator.class)
.blockMapper(BlockMapper.DEFAULT)
.registerPacketHandler(LevelChunkPacket.class, LevelChunkHandler_Bedrock.class)
.registerPacketHandler(StartGamePacket.class, StartGameHandler_Geyser_v408.class)
.build();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,34 @@
package au.com.grieve.geyser.reversion.translators.geyser.v408.handlers;

import au.com.grieve.geyser.reversion.GeyserReversionExtension;
import au.com.grieve.geyser.reversion.translators.geyser.v408.Translator_Geyser_v408;
import au.com.grieve.reversion.api.PacketHandler;
import au.com.grieve.reversion.editions.bedrock.BedrockTranslator;
import au.com.grieve.reversion.editions.bedrock.handlers.StartGameHandler_Bedrock;
import com.nukkitx.nbt.NBTInputStream;
import com.nukkitx.nbt.NbtList;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import org.geysermc.connector.utils.FileUtils;

import java.io.InputStream;
import java.util.Map;

/*
Geyser re-arranged the block palette which will cause issues with the new baked in palette format.
What we do here is to re-arrange it back based upon the supported bedrock palette in Geyser and keep a record
of the mapping so we translate it in other packets
*/
public class StartGameHandler_Geyser_v408 extends PacketHandler<Translator_Geyser_v408, StartGamePacket> {
public class StartGameHandler_Geyser_v408 extends StartGameHandler_Bedrock {

public StartGameHandler_Geyser_v408(Translator_Geyser_v408 translator) {
public StartGameHandler_Geyser_v408(BedrockTranslator translator) {
super(translator);
}

@Override
public boolean fromServer(StartGamePacket packet) {
// Only grab runtime ID's for the first player
if (Translator_Geyser_v408.getBlockRuntimeIdMap().size() == 0) {
Map<Integer, Integer> runtimeIdMap = getTranslator().getRegisteredTranslator().getBlockMapper().getRuntimeIdDownstreamToUpstreamMap();
if (runtimeIdMap.size() == 0) {

/* Load block palette */
InputStream stream = FileUtils.getResource("bedrock/runtime_block_states.dat");
Expand All @@ -66,26 +67,20 @@ public boolean fromServer(StartGamePacket packet) {
for (int originalId = 0; originalId < originalTags.size(); originalId++) {
NbtMap originalTag = originalTags.get(originalId);
if (geyserTag.equals(originalTag)) {
Translator_Geyser_v408.getBlockRuntimeIdMap().put(geyserId, originalId);
runtimeIdMap.put(geyserId, originalId);
found = true;
break;
}
}
if (!found) {
GeyserReversionExtension.getInstance().getLogger().error("Unable to find palette entry: " + geyserTag);
Translator_Geyser_v408.getBlockRuntimeIdMap().put(geyserId, 0); // Set to 0 for now
runtimeIdMap.put(geyserId, 0); // Set to 0 for now
}
}
}

// Reorder the BlockPalette
NbtList<NbtMap> originalTags = packet.getBlockPalette();
NbtList<NbtMap> translatedTags = new NbtList<>(NbtType.COMPOUND);
for (int id : Translator_Geyser_v408.getBlockRuntimeIdMap().keySet()) {
translatedTags.add(originalTags.get(Translator_Geyser_v408.getBlockRuntimeIdMap().get(id)));
}
packet.setBlockPalette(translatedTags);
getTranslator().getRegisteredTranslator().getBlockMapper().debugDump("gr408");

return false;
return super.fromServer(packet);
}
}

0 comments on commit 409406c

Please sign in to comment.