-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start work on geyser palette ordering
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ava/au/com/grieve/geyser/reversion/editions/bedrock/handlers/FromGeyserPacketHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |