Rewrite custom stats ids

This commit is contained in:
KennyTV 2020-08-13 13:59:23 +02:00
parent 249a720cee
commit ce49daa300
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
7 changed files with 30 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
@ -72,5 +73,22 @@ public class Protocol1_13_1To1_13_2 extends BackwardsProtocol<ClientboundPackets
}); });
} }
}); });
new StatisticsRewriter(this, null, null, null, id -> {
int newId = id;
if (newId > 40) {
if (id == 41) return -1;
newId--;
}
if (newId > 25) {
if (id <= 28) return -1;
newId -= 3;
}
if (newId > 22) {
if (id <= 24) return -1;
newId -= 2;
}
return newId;
}).register(ClientboundPackets1_13.STATISTICS);
} }
} }

View File

@ -53,8 +53,8 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
new PlayerPackets1_14(this).register(); new PlayerPackets1_14(this).register();
new SoundPackets1_14(this).register(); new SoundPackets1_14(this).register();
new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> MappingData.oldToNewItems.inverse().get(id),
MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId).register(ClientboundPackets1_14.STATISTICS); entityPackets::getOldEntityId, id -> BackwardsMappings.statisticsMappings.getNewId(id)).register(ClientboundPackets1_14.STATISTICS);
cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_POSITION); cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_POSITION);
cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE); cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE);

View File

@ -12,6 +12,7 @@ import us.myles.viaversion.libs.gson.JsonObject;
public class BackwardsMappings { public class BackwardsMappings {
public static Mappings blockStateMappings; public static Mappings blockStateMappings;
public static Mappings blockMappings; public static Mappings blockMappings;
public static Mappings statisticsMappings;
public static VBSoundMappings soundMappings; public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings; public static VBItemMappings itemMappings;
@ -25,5 +26,6 @@ public class BackwardsMappings {
blockMappings = new VBMappings(mapping1_14.getAsJsonObject("blocks"), mapping1_13_2.getAsJsonObject("blocks"), mapping1_13_2to1_14.getAsJsonObject("blocks"), false); blockMappings = new VBMappings(mapping1_14.getAsJsonObject("blocks"), mapping1_13_2.getAsJsonObject("blocks"), mapping1_13_2to1_14.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_14.getAsJsonObject("items"), mapping1_13_2.getAsJsonObject("items"), mapping1_13_2to1_14.getAsJsonObject("items")); itemMappings = new VBItemMappings(mapping1_14.getAsJsonObject("items"), mapping1_13_2.getAsJsonObject("items"), mapping1_13_2to1_14.getAsJsonObject("items"));
soundMappings = new VBSoundMappings(mapping1_14.getAsJsonArray("sounds"), mapping1_13_2.getAsJsonArray("sounds"), mapping1_13_2to1_14.getAsJsonObject("sounds")); soundMappings = new VBSoundMappings(mapping1_14.getAsJsonArray("sounds"), mapping1_13_2.getAsJsonArray("sounds"), mapping1_13_2to1_14.getAsJsonObject("sounds"));
statisticsMappings = new Mappings(mapping1_14.getAsJsonArray("statistics"), mapping1_13_2.getAsJsonArray("statistics"), false);
} }
} }

View File

@ -82,8 +82,8 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id),
id -> MappingData.oldToNewItems.inverse().get(id), EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.TAGS); id -> MappingData.oldToNewItems.inverse().get(id), EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.TAGS);
new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> MappingData.oldToNewItems.inverse().get(id),
MappingData.oldToNewItems.inverse().get(id), EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.STATISTICS); EntityTypeMapping::getOldEntityId, id -> BackwardsMappings.statisticsMappings.getNewId(id)).register(ClientboundPackets1_15.STATISTICS);
} }
public static int getNewBlockStateId(int id) { public static int getNewBlockStateId(int id) {

View File

@ -12,6 +12,7 @@ import us.myles.viaversion.libs.gson.JsonObject;
public class BackwardsMappings { public class BackwardsMappings {
public static Mappings blockStateMappings; public static Mappings blockStateMappings;
public static Mappings blockMappings; public static Mappings blockMappings;
public static Mappings statisticsMappings;
public static VBSoundMappings soundMappings; public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings; public static VBItemMappings itemMappings;
@ -25,5 +26,6 @@ public class BackwardsMappings {
blockMappings = new VBMappings(mapping1_15.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"), mapping1_14to1_15.getAsJsonObject("blocks"), false); blockMappings = new VBMappings(mapping1_15.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"), mapping1_14to1_15.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_15.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"), mapping1_14to1_15.getAsJsonObject("items")); itemMappings = new VBItemMappings(mapping1_15.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"), mapping1_14to1_15.getAsJsonObject("items"));
soundMappings = new VBSoundMappings(mapping1_15.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"), mapping1_14to1_15.getAsJsonObject("sounds")); soundMappings = new VBSoundMappings(mapping1_15.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"), mapping1_14to1_15.getAsJsonObject("sounds"));
statisticsMappings = new Mappings(mapping1_15.getAsJsonArray("statistics"), mapping1_14.getAsJsonArray("statistics"), false);
} }
} }

View File

@ -99,9 +99,8 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id ->
MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS); MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId).register(ClientboundPackets1_16.TAGS);
new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> new StatisticsRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id), id -> MappingData.oldToNewItems.inverse().get(id),
MappingData.oldToNewItems.inverse().get(id), entityPackets::getOldEntityId, entityPackets::getOldEntityId, id -> BackwardsMappings.statisticsMappings.getNewId(id)).register(ClientboundPackets1_16.STATISTICS);
categoryId -> categoryId > 49 ? -1 : categoryId).register(ClientboundPackets1_16.STATISTICS);
registerIncoming(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() { registerIncoming(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() {
@Override @Override

View File

@ -16,6 +16,7 @@ import java.util.Map;
public class BackwardsMappings { public class BackwardsMappings {
public static Mappings blockStateMappings; public static Mappings blockStateMappings;
public static Mappings blockMappings; public static Mappings blockMappings;
public static Mappings statisticsMappings;
public static VBSoundMappings soundMappings; public static VBSoundMappings soundMappings;
public static VBItemMappings itemMappings; public static VBItemMappings itemMappings;
public static Map<String, String> attributeMappings = new HashMap<>(); public static Map<String, String> attributeMappings = new HashMap<>();
@ -30,6 +31,7 @@ public class BackwardsMappings {
blockMappings = new VBMappings(mapping1_16.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"), mapping1_15to1_16.getAsJsonObject("blocks"), false); blockMappings = new VBMappings(mapping1_16.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"), mapping1_15to1_16.getAsJsonObject("blocks"), false);
itemMappings = new VBItemMappings(mapping1_16.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"), mapping1_15to1_16.getAsJsonObject("items")); itemMappings = new VBItemMappings(mapping1_16.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"), mapping1_15to1_16.getAsJsonObject("items"));
soundMappings = new VBSoundMappings(mapping1_16.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), mapping1_15to1_16.getAsJsonObject("sounds")); soundMappings = new VBSoundMappings(mapping1_16.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), mapping1_15to1_16.getAsJsonObject("sounds"));
statisticsMappings = new Mappings(mapping1_16.getAsJsonArray("statistics"), mapping1_15.getAsJsonArray("statistics"), false);
for (Map.Entry<String, String> entry : MappingData.attributeMappings.entrySet()) { for (Map.Entry<String, String> entry : MappingData.attributeMappings.entrySet()) {
attributeMappings.put(entry.getValue(), entry.getKey()); attributeMappings.put(entry.getValue(), entry.getKey());