Rewrite map colors added in 1.12

This commit is contained in:
Gerrygames 2018-08-16 15:15:44 +02:00
parent 43ad787bda
commit 69c68bf300
2 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,78 @@
package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data;
import java.util.HashMap;
import java.util.Map;
public class MapColorMapping {
private static Map<Integer, Integer> mapping = new HashMap<>();
static {
mapping.put(144, 59); // (148, 124, 114) -> (148, 124, 114)
mapping.put(145, 56); // (180, 153, 139) -> (180, 153, 139)
mapping.put(146, 56); // (209, 177, 161) -> (209, 177, 161)
mapping.put(147, 45); // (111, 94, 85) -> (111, 94, 85)
mapping.put(148, 63); // (112, 58, 25) -> (112, 58, 25)
mapping.put(149, 60); // (137, 71, 31) -> (137, 71, 31)
mapping.put(150, 60); // (159, 82, 36) -> (159, 82, 36)
mapping.put(151, 136); // (84, 43, 19) -> (84, 43, 19)
mapping.put(152, 83); // (105, 61, 76) -> (105, 61, 76)
mapping.put(153, 83); // (129, 75, 93) -> (129, 75, 93)
mapping.put(154, 80); // (149, 87, 108) -> (149, 87, 108)
mapping.put(155, 115); // (79, 46, 57) -> (79, 46, 57)
mapping.put(156, 39); // (79, 76, 97) -> (79, 76, 97)
mapping.put(157, 39); // (97, 93, 119) -> (97, 93, 119)
mapping.put(158, 36); // (112, 108, 138) -> (112, 108, 138)
mapping.put(159, 47); // (59, 57, 73) -> (59, 57, 73)
mapping.put(160, 60); // (131, 94, 25) -> (131, 94, 25)
mapping.put(161, 61); // (160, 115, 31) -> (160, 115, 31)
mapping.put(162, 62); // (186, 133, 36) -> (186, 133, 36)
mapping.put(163, 137); // (98, 70, 19) -> (98, 70, 19)
mapping.put(164, 108); // (73, 83, 37) -> (73, 83, 37)
mapping.put(165, 108); // (89, 101, 46) -> (89, 101, 46)
mapping.put(166, 109); // (103, 117, 53) -> (103, 117, 53)
mapping.put(167, 111); // (55, 62, 28) -> (55, 62, 28)
mapping.put(168, 112); // (113, 54, 55) -> (113, 54, 55)
mapping.put(169, 113); // (138, 66, 67) -> (138, 66, 67)
mapping.put(170, 114); // (160, 77, 78) -> (160, 77, 78)
mapping.put(171, 115); // (85, 41, 41) -> (85, 41, 41)
mapping.put(172, 118); // (40, 29, 25) -> (40, 29, 25)
mapping.put(173, 107); // (49, 35, 30) -> (49, 35, 30)
mapping.put(174, 107); // (57, 41, 35) -> (57, 41, 35)
mapping.put(175, 118); // (30, 22, 19) -> (30, 22, 19)
mapping.put(176, 91); // (95, 76, 69) -> (95, 76, 69)
mapping.put(177, 45); // (116, 92, 85) -> (116, 92, 85)
mapping.put(178, 46); // (135, 107, 98) -> (135, 107, 98)
mapping.put(179, 47); // (71, 57, 52) -> (71, 57, 52)
mapping.put(180, 85); // (61, 65, 65) -> (61, 65, 65)
mapping.put(181, 44); // (75, 79, 79) -> (75, 79, 79)
mapping.put(182, 27); // (87, 92, 92) -> (87, 92, 92)
mapping.put(183, 84); // (46, 49, 49) -> (46, 49, 49)
mapping.put(184, 83); // (86, 52, 62) -> (86, 52, 62)
mapping.put(185, 83); // (105, 63, 76) -> (105, 63, 76)
mapping.put(186, 83); // (122, 73, 88) -> (122, 73, 88)
mapping.put(187, 84); // (65, 39, 47) -> (65, 39, 47)
mapping.put(188, 84); // (54, 44, 65) -> (54, 44, 65)
mapping.put(189, 71); // (66, 53, 79) -> (66, 53, 79)
mapping.put(190, 71); // (76, 62, 92) -> (76, 62, 92)
mapping.put(191, 87); // (40, 33, 49) -> (40, 33, 49)
mapping.put(192, 107); // (54, 35, 25) -> (54, 35, 25)
mapping.put(193, 139); // (66, 43, 30) -> (66, 43, 30)
mapping.put(194, 43); // (76, 50, 35) -> (76, 50, 35)
mapping.put(195, 107); // (40, 26, 19) -> (40, 26, 19)
mapping.put(196, 111); // (54, 58, 30) -> (54, 58, 30)
mapping.put(197, 111); // (66, 71, 36) -> (66, 71, 36)
mapping.put(198, 111); // (76, 82, 42) -> (76, 82, 42)
mapping.put(199, 107); // (40, 43, 22) -> (40, 43, 22)
mapping.put(200, 112); // (100, 42, 32) -> (100, 42, 32)
mapping.put(201, 113); // (123, 52, 40) -> (123, 52, 40)
mapping.put(202, 113); // (142, 60, 46) -> (142, 60, 46)
mapping.put(203, 115); // (75, 32, 24) -> (75, 32, 24)
mapping.put(204, 116); // (26, 16, 11) -> (26, 16, 11)
mapping.put(205, 117); // (32, 19, 14) -> (32, 19, 14)
mapping.put(206, 107); // (37, 22, 16) -> (37, 22, 16)
mapping.put(207, 119); // (20, 12, 8) -> (20, 12, 8)
}
public static int getNearestOldColor(int color) {
return mapping.getOrDefault(color, color);
}
}

View File

@ -13,6 +13,7 @@ package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.packets;
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.MapColorMapping;
import nl.matsv.viabackwards.utils.Block;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item;
@ -34,6 +35,43 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
protected void registerPackets(Protocol1_11_1To1_12 protocol) {
/* Item packets */
protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.BYTE);
map(Type.BOOLEAN);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int count = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < count * 3; i++) {
wrapper.passthrough(Type.BYTE);
}
}
});
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
short columns = wrapper.passthrough(Type.UNSIGNED_BYTE);
if (columns <= 0) return;
short rows = wrapper.passthrough(Type.UNSIGNED_BYTE);
wrapper.passthrough(Type.BYTE); //X
wrapper.passthrough(Type.BYTE); //Z
Byte[] data = wrapper.read(Type.BYTE_ARRAY);
for (int i = 0; i < data.length; i++) {
short color = (short) (data[i] & 0xFF);
if (color > 143) {
color = (short) MapColorMapping.getNearestOldColor(color);
data[i] = (byte) color;
}
}
wrapper.write(Type.BYTE_ARRAY, data);
}
});
}
});
// Set slot packet
protocol.registerOutgoing(State.PLAY, 0x16, 0x16, new PacketRemapper() {
@Override