mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-22 16:57:40 +01:00
Handle new map colors
Co-authored-by: Gerrygames <gecam59@gmail.com>
This commit is contained in:
parent
bd421fcfab
commit
2194c96883
@ -8,7 +8,7 @@ plugins {
|
||||
|
||||
allprojects {
|
||||
group = "com.viaversion"
|
||||
version = "4.0.0-21w17a"
|
||||
version = "4.0.0-21w18a"
|
||||
description = "Allow older clients to join newer server versions."
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* 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 com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.rewriter.IdRewriteFunction;
|
||||
|
||||
public final class MapColorRewriter {
|
||||
|
||||
/**
|
||||
* Returns a packethandler to rewrite map data color ids. Reading starts from the icon count.
|
||||
*
|
||||
* @param rewriter id rewriter returning mapped colors, or -1 if unmapped
|
||||
* @return packethandler to rewrite map data color ids
|
||||
*/
|
||||
public static PacketHandler getRewriteHandler(IdRewriteFunction rewriter) {
|
||||
return wrapper -> {
|
||||
int iconCount = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
wrapper.passthrough(Type.VAR_INT); // Type
|
||||
wrapper.passthrough(Type.BYTE); // X
|
||||
wrapper.passthrough(Type.BYTE); // Z
|
||||
wrapper.passthrough(Type.BYTE); // Direction
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||
wrapper.passthrough(Type.COMPONENT); // Display Name
|
||||
}
|
||||
}
|
||||
|
||||
short columns = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
if (columns < 1) return;
|
||||
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Rows
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // X
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Z
|
||||
byte[] data = wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE);
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
int color = data[i] & 0xFF;
|
||||
int mappedColor = rewriter.rewrite(color);
|
||||
if (mappedColor != -1) {
|
||||
data[i] = (byte) mappedColor;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ package com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
public class MapColorRewriter {
|
||||
public final class MapColorRewrites {
|
||||
|
||||
private static final Int2IntMap MAPPINGS = new Int2IntOpenHashMap();
|
||||
|
@ -18,9 +18,10 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.MapColorRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewrites;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
@ -224,33 +225,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
map(Type.BYTE); // Scale
|
||||
map(Type.BOOLEAN); // Tracking Position
|
||||
map(Type.BOOLEAN); // Locked
|
||||
handler(wrapper -> {
|
||||
int iconCount = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < iconCount; i++) {
|
||||
wrapper.passthrough(Type.VAR_INT); // Type
|
||||
wrapper.passthrough(Type.BYTE); // X
|
||||
wrapper.passthrough(Type.BYTE); // Z
|
||||
wrapper.passthrough(Type.BYTE); // Direction
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||
wrapper.passthrough(Type.COMPONENT); // Display Name
|
||||
}
|
||||
}
|
||||
|
||||
short columns = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
if (columns < 1) return;
|
||||
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Rows
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // X
|
||||
wrapper.passthrough(Type.UNSIGNED_BYTE); // Z
|
||||
byte[] data = wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE);
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
int color = data[i] & 0xFF;
|
||||
int mappedColor = MapColorRewriter.getMappedColor(color);
|
||||
if (mappedColor != -1) {
|
||||
data[i] = (byte) mappedColor;
|
||||
}
|
||||
}
|
||||
});
|
||||
handler(MapColorRewriter.getRewriteHandler(MapColorRewrites::getMappedColor));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -149,23 +149,6 @@ public class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPackets1_
|
||||
}
|
||||
});
|
||||
|
||||
registerClientbound(ClientboundPackets1_17.MAP_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.passthrough(Type.BYTE);
|
||||
wrapper.write(Type.BOOLEAN, true); // Tracking position
|
||||
wrapper.passthrough(Type.BOOLEAN);
|
||||
|
||||
boolean hasMarkers = wrapper.read(Type.BOOLEAN);
|
||||
if (!hasMarkers) {
|
||||
wrapper.write(Type.VAR_INT, 0); // Array size
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
registerClientbound(ClientboundPackets1_17.EXPLOSION, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||
*
|
||||
* 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 com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.data;
|
||||
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
public final class MapColorRewrites {
|
||||
|
||||
private static final Int2IntMap MAPPINGS = new Int2IntOpenHashMap();
|
||||
|
||||
static {
|
||||
MAPPINGS.put(236, 85); // (70, 70, 70) -> (65, 65, 65)
|
||||
MAPPINGS.put(237, 27); // (86, 86, 86) -> (88, 88, 88)
|
||||
MAPPINGS.put(238, 45); // (100, 100, 100) -> (96, 96, 96)
|
||||
MAPPINGS.put(239, 84); // (52, 52, 52) -> (53, 53, 53)
|
||||
MAPPINGS.put(240, 144); // (152, 123, 103) -> (147, 124, 113)
|
||||
MAPPINGS.put(241, 145); // (186, 150, 126) -> (180, 152, 138)
|
||||
MAPPINGS.put(242, 146); // (216, 175, 147) -> (209, 177, 161)
|
||||
MAPPINGS.put(243, 147); // (114, 92, 77) -> (110, 93, 85)
|
||||
MAPPINGS.put(244, 127); // (89, 117, 105) -> (48, 115, 112)
|
||||
MAPPINGS.put(245, 226); // (109, 144, 129) -> (58, 142, 140)
|
||||
MAPPINGS.put(246, 124); // (127, 167, 150) -> (64, 154, 150)
|
||||
MAPPINGS.put(247, 227); // (67, 88, 79) -> (30, 75, 74)
|
||||
}
|
||||
|
||||
public static int getMappedColor(int color) {
|
||||
return MAPPINGS.getOrDefault(color, -1);
|
||||
}
|
||||
}
|
@ -18,8 +18,10 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets;
|
||||
|
||||
import com.viaversion.viabackwards.api.entities.storage.EntityTracker;
|
||||
import com.viaversion.viabackwards.api.rewriters.MapColorRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.data.MapColorRewrites;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
@ -292,6 +294,23 @@ public class BlockItemPackets1_17 extends com.viaversion.viabackwards.api.rewrit
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_17.MAP_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // Map ID
|
||||
map(Type.BYTE); // Scale
|
||||
create(wrapper -> wrapper.write(Type.BOOLEAN, true)); // Tracking position
|
||||
map(Type.BOOLEAN); // Locked
|
||||
handler(wrapper -> {
|
||||
boolean hasMarkers = wrapper.read(Type.BOOLEAN);
|
||||
if (!hasMarkers) {
|
||||
wrapper.write(Type.VAR_INT, 0); // Array size
|
||||
}
|
||||
});
|
||||
handler(MapColorRewriter.getRewriteHandler(MapColorRewrites::getMappedColor));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int cutLightMask(long[] mask, int startFromSection) {
|
||||
|
@ -3,7 +3,7 @@ metadata.format.version = "1.0"
|
||||
[versions]
|
||||
|
||||
# ViaVersion
|
||||
viaver = "4.0.0-21w17a"
|
||||
viaver = "4.0.0-21w18a"
|
||||
|
||||
# Common provided
|
||||
netty = "4.0.20.Final"
|
||||
|
Loading…
Reference in New Issue
Block a user