Skip to content

Commit

Permalink
Start work on geyser palette ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
bundabrg committed Sep 9, 2020
1 parent 170a9b3 commit 23d74ab
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package au.com.grieve.geyser.reversion.editions.bedrock.handlers;

import au.com.grieve.reversion.api.ReversionSession;
import au.com.grieve.reversion.editions.bedrock.BedrockReversionSession;
import com.nukkitx.protocol.bedrock.BedrockServerSession;
import lombok.Getter;
import org.geysermc.connector.GeyserConnector;
Expand All @@ -38,5 +39,8 @@ public BedrockServerEventHandler(GeyserConnector connector) {
public void onSessionCreation(BedrockServerSession bedrockServerSession) {
bedrockServerSession.setLogging(true);
bedrockServerSession.setPacketHandler(new BedrockUpstreamPacketHandler((ReversionSession) bedrockServerSession, this.connector, new GeyserSession(this.connector, bedrockServerSession)));

// Add a Geyser specific handler
((BedrockReversionSession) bedrockServerSession).getFromServerHandlers().add(new FromGeyserPacketHandler());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* EduSupport - Minecraft Protocol Support for MultiVersion in Geyser
* Copyright (C) 2020 GeyserReversion Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package au.com.grieve.geyser.reversion.editions.bedrock.handlers;

import com.nukkitx.nbt.NBTInputStream;
import com.nukkitx.nbt.NbtList;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import org.geysermc.connector.utils.FileUtils;

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

public class FromGeyserPacketHandler implements BedrockPacketHandler {

public static Map<Integer, Integer> blockRuntimeIdMap;

/*
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
*/
@Override
public boolean handle(StartGamePacket packet) {
// Only do this once
if (blockRuntimeIdMap == null) {
blockRuntimeIdMap = new HashMap<>();

/* Load block palette */
InputStream stream = FileUtils.getResource("bedrock/runtime_block_states.dat");

NbtList<NbtMap> originalTags;
try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream)) {
//noinspection unchecked
originalTags = (NbtList<NbtMap>) nbtInputStream.readTag();
} catch (Exception e) {
throw new AssertionError("Unable to get blocks from runtime block states", e);
}

NbtList<NbtMap> geyserTags = packet.getBlockPalette();

for (int geyserId = 0; geyserId < geyserTags.size(); geyserId++) {
NbtMap geyserTag = geyserTags.get(geyserId);
for (int originalId = 0; originalId < originalTags.size(); originalId++) {
NbtMap originalTag = originalTags.get(originalId);
if (geyserTag.equals(originalTag)) {
blockRuntimeIdMap.put(geyserId, originalId);
break;
}
}
}


packet.getBlockPalette();

return false;
}
}

0 comments on commit 23d74ab

Please sign in to comment.