Rewrite statistics category ids

Thanks to RaphiMC for providing the statistic mappings
This commit is contained in:
KennyTV 2020-08-13 13:31:14 +02:00
parent b0fc931ecd
commit 7163d38ddf
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
13 changed files with 377 additions and 23 deletions

View File

@ -11,16 +11,17 @@ public class StatisticsRewriter {
private final IdRewriteFunction blockRewriter;
private final IdRewriteFunction itemRewriter;
private final IdRewriteFunction entityRewriter;
private final IdRewriteFunction categoryIdRewriter;
private final IdRewriteFunction statisticsIdRewriter;
private final int customStatsCategory = 8; // Make this changeable if it differs in a future version
public StatisticsRewriter(Protocol protocol,
@Nullable IdRewriteFunction blockRewriter, @Nullable IdRewriteFunction itemRewriter, @Nullable IdRewriteFunction entityRewriter,
@Nullable IdRewriteFunction categoryIdRewriter) {
@Nullable IdRewriteFunction statisticsIdRewriter) {
this.protocol = protocol;
this.blockRewriter = blockRewriter;
this.itemRewriter = itemRewriter;
this.entityRewriter = entityRewriter;
this.categoryIdRewriter = categoryIdRewriter;
this.statisticsIdRewriter = statisticsIdRewriter;
}
public StatisticsRewriter(Protocol protocol, @Nullable IdRewriteFunction blockRewriter, @Nullable IdRewriteFunction itemRewriter, @Nullable IdRewriteFunction entityRewriter) {
@ -38,27 +39,25 @@ public class StatisticsRewriter {
int categoryId = wrapper.read(Type.VAR_INT);
int statisticId = wrapper.read(Type.VAR_INT);
int value = wrapper.read(Type.VAR_INT);
// Rewrite category id
if (categoryIdRewriter != null) {
categoryId = categoryIdRewriter.rewrite(categoryId);
if (categoryId == -1) {
if (categoryId == customStatsCategory && statisticsIdRewriter != null) {
// Rewrite custom statistics id
statisticId = statisticsIdRewriter.rewrite(statisticId);
if (statisticId == -1) {
// Remove entry
newSize--;
continue;
}
} else {
// Rewrite the block/item/entity id
RegistryType type = getRegistryTypeForStatistic(categoryId);
IdRewriteFunction statisticsRewriter;
if (type != null && (statisticsRewriter = getRewriter(type)) != null) {
statisticId = statisticsRewriter.rewrite(statisticId);
}
}
wrapper.write(Type.VAR_INT, categoryId);
RegistryType type = getRegistryTypeForStatistic(categoryId);
IdRewriteFunction statisticsRewriter;
// Rewrite the block/item/entity id
if (type != null && (statisticsRewriter = getRewriter(type)) != null) {
wrapper.write(Type.VAR_INT, statisticsRewriter.rewrite(statisticId));
} else {
wrapper.write(Type.VAR_INT, statisticId);
}
wrapper.write(Type.VAR_INT, statisticId);
wrapper.write(Type.VAR_INT, value);
}

View File

@ -7,6 +7,7 @@ import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.metadata.MetadataRewriter1_13_1To1_13;
import us.myles.ViaVersion.protocols.protocol1_13_1to1_13.packets.EntityPackets;
@ -144,6 +145,20 @@ public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, Clien
});
}
});
new StatisticsRewriter(this, null, null, null, id -> {
int newId = id;
if (newId > 22) {
newId += 2;
}
if (newId > 25) {
newId += 3;
}
if (newId > 40) {
newId++;
}
return newId;
});
}
@Override

View File

@ -39,7 +39,7 @@ public class Protocol1_14To1_13_2 extends Protocol<ClientboundPackets1_13, Clien
new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id)).registerSound(ClientboundPackets1_13.SOUND);
new StatisticsRewriter(this, Protocol1_14To1_13_2::getNewBlockId,
InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId).register(ClientboundPackets1_13.STATISTICS);
InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId, id -> MappingData.statisticsMappings.getNewId(id)).register(ClientboundPackets1_13.STATISTICS);
ComponentRewriter componentRewriter = new ComponentRewriter1_14(this);
componentRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE);

View File

@ -18,6 +18,7 @@ public class MappingData {
public static Mappings blockStateMappings;
public static Mappings blockMappings;
public static Mappings soundMappings;
public static Mappings statisticsMappings;
public static IntSet motionBlocking;
public static IntSet nonFullBlocks;
@ -31,6 +32,7 @@ public class MappingData {
blockMappings = new Mappings(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
soundMappings = new Mappings(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
statisticsMappings = new Mappings(mapping1_13_2.getAsJsonArray("statistics"), mapping1_14.getAsJsonArray("statistics"));
JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
Map<String, Integer> blockStateMap = new HashMap<>(blockStates.entrySet().size());

View File

@ -40,8 +40,8 @@ public class Protocol1_15To1_14_4 extends Protocol<ClientboundPackets1_14, Clien
soundRewriter.registerSound(ClientboundPackets1_14.ENTITY_SOUND); // Entity Sound Effect (added somewhere in 1.14)
soundRewriter.registerSound(ClientboundPackets1_14.SOUND);
new StatisticsRewriter(this, Protocol1_15To1_14_4::getNewBlockId,
InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId).register(ClientboundPackets1_14.STATISTICS);
new StatisticsRewriter(this, Protocol1_15To1_14_4::getNewBlockId, InventoryPackets::getNewItemId,
metadataRewriter::getNewEntityId, id -> MappingData.statisticsMappings.getNewId(id)).register(ClientboundPackets1_14.STATISTICS);
registerIncoming(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override

View File

@ -11,6 +11,7 @@ public class MappingData {
public static Mappings blockMappings;
public static Mappings blockStateMappings;
public static Mappings soundMappings;
public static Mappings statisticsMappings;
public static void init() {
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 mappings...");
@ -23,5 +24,6 @@ public class MappingData {
blockMappings = new Mappings(mapping1_14.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"));
soundMappings = new Mappings(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), false);
statisticsMappings = new Mappings(mapping1_14.getAsJsonArray("statistics"), mapping1_15.getAsJsonArray("statistics"));
}
}

View File

@ -52,7 +52,7 @@ public class Protocol1_16To1_15_2 extends Protocol<ClientboundPackets1_15, Clien
tagRewriter.register(ClientboundPackets1_15.TAGS);
new StatisticsRewriter(this, Protocol1_16To1_15_2::getNewBlockId, InventoryPackets::getNewItemId,
metadataRewriter::getNewEntityId).register(ClientboundPackets1_15.STATISTICS);
metadataRewriter::getNewEntityId, id -> MappingData.statisticsMappings.getNewId(id)).register(ClientboundPackets1_15.STATISTICS);
// Login Success
registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() {

View File

@ -14,6 +14,7 @@ public class MappingData {
public static Mappings blockMappings;
public static Mappings blockStateMappings;
public static Mappings soundMappings;
public static Mappings statisticsMappings;
public static void init() {
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 mappings...");
@ -26,6 +27,7 @@ public class MappingData {
blockMappings = new Mappings(mapping1_15.getAsJsonObject("blocks"), mapping1_16.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_15.getAsJsonObject("items"), mapping1_16.getAsJsonObject("items"), diffmapping.getAsJsonObject("items"));
soundMappings = new Mappings(mapping1_15.getAsJsonArray("sounds"), mapping1_16.getAsJsonArray("sounds"), diffmapping.getAsJsonObject("sounds"));
statisticsMappings = new Mappings(mapping1_15.getAsJsonArray("statistics"), mapping1_16.getAsJsonArray("statistics"));
attributeMappings.put("generic.maxHealth", "minecraft:generic.max_health");
attributeMappings.put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements");

View File

@ -10655,5 +10655,65 @@
"595": "cave_air",
"596": "bubble_column",
"597": "structure_block"
}
},
"statistics": [
"minecraft.leave_game",
"minecraft.play_one_minute",
"minecraft.time_since_death",
"minecraft.time_since_rest",
"minecraft.sneak_time",
"minecraft.walk_one_cm",
"minecraft.crouch_one_cm",
"minecraft.sprint_one_cm",
"minecraft.walk_on_water_one_cm",
"minecraft.fall_one_cm",
"minecraft.climb_one_cm",
"minecraft.fly_one_cm",
"minecraft.walk_under_water_one_cm",
"minecraft.minecart_one_cm",
"minecraft.boat_one_cm",
"minecraft.pig_one_cm",
"minecraft.horse_one_cm",
"minecraft.aviate_one_cm",
"minecraft.swim_one_cm",
"minecraft.jump",
"minecraft.drop",
"minecraft.damage_dealt",
"minecraft.damage_dealt_absorbed",
"minecraft.damage_dealt_resisted",
"minecraft.damage_taken",
"minecraft.damage_blocked_by_shield",
"minecraft.damage_absorbed",
"minecraft.damage_resisted",
"minecraft.deaths",
"minecraft.mob_kills",
"minecraft.animals_bred",
"minecraft.player_kills",
"minecraft.fish_caught",
"minecraft.talked_to_villager",
"minecraft.traded_with_villager",
"minecraft.eat_cake_slice",
"minecraft.fill_cauldron",
"minecraft.use_cauldron",
"minecraft.clean_armor",
"minecraft.clean_banner",
"minecraft.clean_shulker_box",
"minecraft.interact_with_brewingstand",
"minecraft.interact_with_beacon",
"minecraft.inspect_dropper",
"minecraft.inspect_hopper",
"minecraft.inspect_dispenser",
"minecraft.play_noteblock",
"minecraft.tune_noteblock",
"minecraft.pot_flower",
"minecraft.trigger_trapped_chest",
"minecraft.open_enderchest",
"minecraft.enchant_item",
"minecraft.play_record",
"minecraft.interact_with_furnace",
"minecraft.interact_with_crafting_table",
"minecraft.open_chest",
"minecraft.sleep_in_bed",
"minecraft.open_shulker_box"
]
}

View File

@ -10741,5 +10741,59 @@
"31": "minecraft:channeling",
"32": "minecraft:mending",
"33": "minecraft:vanishing_curse"
}
},
"statistics": [
"minecraft.leave_game",
"minecraft.play_one_minute",
"minecraft.time_since_death",
"minecraft.time_since_rest",
"minecraft.sneak_time",
"minecraft.walk_one_cm",
"minecraft.crouch_one_cm",
"minecraft.sprint_one_cm",
"minecraft.walk_on_water_one_cm",
"minecraft.fall_one_cm",
"minecraft.climb_one_cm",
"minecraft.fly_one_cm",
"minecraft.walk_under_water_one_cm",
"minecraft.minecart_one_cm",
"minecraft.boat_one_cm",
"minecraft.pig_one_cm",
"minecraft.horse_one_cm",
"minecraft.aviate_one_cm",
"minecraft.swim_one_cm",
"minecraft.jump",
"minecraft.drop",
"minecraft.damage_dealt",
"minecraft.damage_taken",
"minecraft.deaths",
"minecraft.mob_kills",
"minecraft.animals_bred",
"minecraft.player_kills",
"minecraft.fish_caught",
"minecraft.talked_to_villager",
"minecraft.traded_with_villager",
"minecraft.eat_cake_slice",
"minecraft.fill_cauldron",
"minecraft.use_cauldron",
"minecraft.clean_armor",
"minecraft.clean_banner",
"minecraft.interact_with_brewingstand",
"minecraft.interact_with_beacon",
"minecraft.inspect_dropper",
"minecraft.inspect_hopper",
"minecraft.inspect_dispenser",
"minecraft.play_noteblock",
"minecraft.tune_noteblock",
"minecraft.pot_flower",
"minecraft.trigger_trapped_chest",
"minecraft.open_enderchest",
"minecraft.enchant_item",
"minecraft.play_record",
"minecraft.interact_with_furnace",
"minecraft.interact_with_crafting_table",
"minecraft.open_chest",
"minecraft.sleep_in_bed",
"minecraft.open_shulker_box"
]
}

View File

@ -13625,5 +13625,76 @@
"entity.zombie_villager.death",
"entity.zombie_villager.hurt",
"entity.zombie_villager.step"
],
"statistics": [
"minecraft.leave_game",
"minecraft.play_one_minute",
"minecraft.time_since_death",
"minecraft.time_since_rest",
"minecraft.sneak_time",
"minecraft.walk_one_cm",
"minecraft.crouch_one_cm",
"minecraft.sprint_one_cm",
"minecraft.walk_on_water_one_cm",
"minecraft.fall_one_cm",
"minecraft.climb_one_cm",
"minecraft.fly_one_cm",
"minecraft.walk_under_water_one_cm",
"minecraft.minecart_one_cm",
"minecraft.boat_one_cm",
"minecraft.pig_one_cm",
"minecraft.horse_one_cm",
"minecraft.aviate_one_cm",
"minecraft.swim_one_cm",
"minecraft.jump",
"minecraft.drop",
"minecraft.damage_dealt",
"minecraft.damage_dealt_absorbed",
"minecraft.damage_dealt_resisted",
"minecraft.damage_taken",
"minecraft.damage_blocked_by_shield",
"minecraft.damage_absorbed",
"minecraft.damage_resisted",
"minecraft.deaths",
"minecraft.mob_kills",
"minecraft.animals_bred",
"minecraft.player_kills",
"minecraft.fish_caught",
"minecraft.talked_to_villager",
"minecraft.traded_with_villager",
"minecraft.eat_cake_slice",
"minecraft.fill_cauldron",
"minecraft.use_cauldron",
"minecraft.clean_armor",
"minecraft.clean_banner",
"minecraft.clean_shulker_box",
"minecraft.interact_with_brewingstand",
"minecraft.interact_with_beacon",
"minecraft.inspect_dropper",
"minecraft.inspect_hopper",
"minecraft.inspect_dispenser",
"minecraft.play_noteblock",
"minecraft.tune_noteblock",
"minecraft.pot_flower",
"minecraft.trigger_trapped_chest",
"minecraft.open_enderchest",
"minecraft.enchant_item",
"minecraft.play_record",
"minecraft.interact_with_furnace",
"minecraft.interact_with_crafting_table",
"minecraft.open_chest",
"minecraft.sleep_in_bed",
"minecraft.open_shulker_box",
"minecraft.open_barrel",
"minecraft.interact_with_blast_furnace",
"minecraft.interact_with_smoker",
"minecraft.interact_with_lectern",
"minecraft.interact_with_campfire",
"minecraft.interact_with_cartography_table",
"minecraft.interact_with_loom",
"minecraft.interact_with_stonecutter",
"minecraft.bell_ring",
"minecraft.raid_trigger",
"minecraft.raid_win"
]
}

View File

@ -13717,5 +13717,78 @@
"entity.zombie_villager.death",
"entity.zombie_villager.hurt",
"entity.zombie_villager.step"
],
"statistics": [
"minecraft.leave_game",
"minecraft.play_one_minute",
"minecraft.time_since_death",
"minecraft.time_since_rest",
"minecraft.sneak_time",
"minecraft.walk_one_cm",
"minecraft.crouch_one_cm",
"minecraft.sprint_one_cm",
"minecraft.walk_on_water_one_cm",
"minecraft.fall_one_cm",
"minecraft.climb_one_cm",
"minecraft.fly_one_cm",
"minecraft.walk_under_water_one_cm",
"minecraft.minecart_one_cm",
"minecraft.boat_one_cm",
"minecraft.pig_one_cm",
"minecraft.horse_one_cm",
"minecraft.aviate_one_cm",
"minecraft.swim_one_cm",
"minecraft.jump",
"minecraft.drop",
"minecraft.damage_dealt",
"minecraft.damage_dealt_absorbed",
"minecraft.damage_dealt_resisted",
"minecraft.damage_taken",
"minecraft.damage_blocked_by_shield",
"minecraft.damage_absorbed",
"minecraft.damage_resisted",
"minecraft.deaths",
"minecraft.mob_kills",
"minecraft.animals_bred",
"minecraft.player_kills",
"minecraft.fish_caught",
"minecraft.talked_to_villager",
"minecraft.traded_with_villager",
"minecraft.eat_cake_slice",
"minecraft.fill_cauldron",
"minecraft.use_cauldron",
"minecraft.clean_armor",
"minecraft.clean_banner",
"minecraft.clean_shulker_box",
"minecraft.interact_with_brewingstand",
"minecraft.interact_with_beacon",
"minecraft.inspect_dropper",
"minecraft.inspect_hopper",
"minecraft.inspect_dispenser",
"minecraft.play_noteblock",
"minecraft.tune_noteblock",
"minecraft.pot_flower",
"minecraft.trigger_trapped_chest",
"minecraft.open_enderchest",
"minecraft.enchant_item",
"minecraft.play_record",
"minecraft.interact_with_furnace",
"minecraft.interact_with_crafting_table",
"minecraft.open_chest",
"minecraft.sleep_in_bed",
"minecraft.open_shulker_box",
"minecraft.open_barrel",
"minecraft.interact_with_blast_furnace",
"minecraft.interact_with_smoker",
"minecraft.interact_with_lectern",
"minecraft.interact_with_campfire",
"minecraft.interact_with_cartography_table",
"minecraft.interact_with_loom",
"minecraft.interact_with_stonecutter",
"minecraft.bell_ring",
"minecraft.raid_trigger",
"minecraft.raid_win",
"minecraft.interact_with_anvil",
"minecraft.interact_with_grindstone"
]
}

View File

@ -19833,5 +19833,81 @@
"entity.zombie_villager.death",
"entity.zombie_villager.hurt",
"entity.zombie_villager.step"
],
"statistics": [
"minecraft.leave_game",
"minecraft.play_one_minute",
"minecraft.time_since_death",
"minecraft.time_since_rest",
"minecraft.sneak_time",
"minecraft.walk_one_cm",
"minecraft.crouch_one_cm",
"minecraft.sprint_one_cm",
"minecraft.walk_on_water_one_cm",
"minecraft.fall_one_cm",
"minecraft.climb_one_cm",
"minecraft.fly_one_cm",
"minecraft.walk_under_water_one_cm",
"minecraft.minecart_one_cm",
"minecraft.boat_one_cm",
"minecraft.pig_one_cm",
"minecraft.horse_one_cm",
"minecraft.aviate_one_cm",
"minecraft.swim_one_cm",
"minecraft.strider_one_cm",
"minecraft.jump",
"minecraft.drop",
"minecraft.damage_dealt",
"minecraft.damage_dealt_absorbed",
"minecraft.damage_dealt_resisted",
"minecraft.damage_taken",
"minecraft.damage_blocked_by_shield",
"minecraft.damage_absorbed",
"minecraft.damage_resisted",
"minecraft.deaths",
"minecraft.mob_kills",
"minecraft.animals_bred",
"minecraft.player_kills",
"minecraft.fish_caught",
"minecraft.talked_to_villager",
"minecraft.traded_with_villager",
"minecraft.eat_cake_slice",
"minecraft.fill_cauldron",
"minecraft.use_cauldron",
"minecraft.clean_armor",
"minecraft.clean_banner",
"minecraft.clean_shulker_box",
"minecraft.interact_with_brewingstand",
"minecraft.interact_with_beacon",
"minecraft.inspect_dropper",
"minecraft.inspect_hopper",
"minecraft.inspect_dispenser",
"minecraft.play_noteblock",
"minecraft.tune_noteblock",
"minecraft.pot_flower",
"minecraft.trigger_trapped_chest",
"minecraft.open_enderchest",
"minecraft.enchant_item",
"minecraft.play_record",
"minecraft.interact_with_furnace",
"minecraft.interact_with_crafting_table",
"minecraft.open_chest",
"minecraft.sleep_in_bed",
"minecraft.open_shulker_box",
"minecraft.open_barrel",
"minecraft.interact_with_blast_furnace",
"minecraft.interact_with_smoker",
"minecraft.interact_with_lectern",
"minecraft.interact_with_campfire",
"minecraft.interact_with_cartography_table",
"minecraft.interact_with_loom",
"minecraft.interact_with_stonecutter",
"minecraft.bell_ring",
"minecraft.raid_trigger",
"minecraft.raid_win",
"minecraft.interact_with_anvil",
"minecraft.interact_with_grindstone",
"minecraft.target_hit",
"minecraft.interact_with_smithing_table"
]
}