Merge pull request #1631 from KennyTV/abstraction

Convert (general) 1.12.2->1.13 statistics
This commit is contained in:
Myles 2020-01-15 21:44:55 +00:00 committed by GitHub
commit ebeb1905b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 111 additions and 3 deletions

View File

@ -23,6 +23,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.provi
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.BlockIdData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.RecipeData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.StatisticMappings;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
@ -190,12 +191,57 @@ public class Protocol1_13To1_12_2 extends Protocol {
registerOutgoing(State.PLAY, 0x07, 0x07, new PacketRemapper() {
@Override
public void registerMap() {
// TODO: This packet has changed
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
String name = wrapper.read(Type.STRING);
String[] split = name.split("\\.");
int categoryId = 0;
int newId = 0;
if (split.length == 2) {
// Custom types
categoryId = 8;
Integer newIdRaw = StatisticMappings.statistics.get(name);
if (newIdRaw != null) {
newId = newIdRaw;
}
} else {
String category = split[1];
//TODO convert string ids (blocks, items, entities)
switch (category) {
case "mineBlock":
categoryId = 0;
break;
case "craftItem":
categoryId = 1;
break;
case "useItem":
categoryId = 2;
break;
case "breakItem":
categoryId = 3;
break;
case "pickup":
categoryId = 4;
break;
case "drop":
categoryId = 5;
break;
case "killEntity":
categoryId = 6;
break;
case "entityKilledBy":
categoryId = 7;
break;
}
}
wrapper.write(Type.VAR_INT, categoryId); // category id
wrapper.write(Type.VAR_INT, newId); // statistics id
wrapper.passthrough(Type.VAR_INT); // value
}
}
});
}

View File

@ -0,0 +1,62 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import java.util.HashMap;
import java.util.Map;
public class StatisticMappings {
public static final Map<String, Integer> statistics = new HashMap<>();
static {
statistics.put("stat.jump", 17);
statistics.put("stat.drop", 18);
statistics.put("stat.deaths", 21);
statistics.put("stat.mobKills", 22);
statistics.put("stat.pigOneCm", 14);
statistics.put("stat.flyOneCm", 10);
statistics.put("stat.leaveGame", 0);
statistics.put("stat.diveOneCm", 11);
statistics.put("stat.swimOneCm", 7);
statistics.put("stat.fallOneCm", 8);
statistics.put("stat.walkOneCm", 4);
statistics.put("stat.boatOneCm", 13);
statistics.put("stat.sneakTime", 3);
statistics.put("stat.horseOneCm", 15);
statistics.put("stat.sleepInBed", 48);
statistics.put("stat.fishCaught", 25);
statistics.put("stat.climbOneCm", 9);
statistics.put("stat.aviateOneCm", 16);
statistics.put("stat.crouchOneCm", 5);
statistics.put("stat.sprintOneCm", 6);
statistics.put("stat.animalsBred", 23);
statistics.put("stat.chestOpened", 47);
statistics.put("stat.damageTaken", 20);
statistics.put("stat.damageDealt", 19);
statistics.put("stat.playerKills", 24);
statistics.put("stat.armorCleaned", 31);
statistics.put("stat.flowerPotted", 40);
statistics.put("stat.recordPlayed", 44);
statistics.put("stat.cauldronUsed", 30);
statistics.put("stat.bannerCleaned", 32);
statistics.put("stat.itemEnchanted", 43);
statistics.put("stat.playOneMinute", 1);
statistics.put("stat.minecartOneCm", 12);
statistics.put("stat.timeSinceDeath", 2);
statistics.put("stat.cauldronFilled", 29);
statistics.put("stat.noteblockTuned", 39);
statistics.put("stat.noteblockPlayed", 38);
statistics.put("stat.cakeSlicesEaten", 28);
statistics.put("stat.hopperInspected", 36);
statistics.put("stat.shulkerBoxOpened", 49);
statistics.put("stat.talkedToVillager", 26);
statistics.put("stat.enderchestOpened", 42);
statistics.put("stat.dropperInspected", 35);
statistics.put("stat.beaconInteraction", 34);
statistics.put("stat.furnaceInteraction", 45);
statistics.put("stat.dispenserInspected", 37);
statistics.put("stat.tradedWithVillager", 27);
statistics.put("stat.trappedChestTriggered", 41);
statistics.put("stat.brewingstandInteraction", 33);
statistics.put("stat.craftingTableInteraction", 46);
}
}