Skip to content

Instantly share code, notes, and snippets.

@tr7zw

tr7zw/test.java Secret

Created September 8, 2023 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tr7zw/bc94dd2e6d4b86819a262bb0ff4f201b to your computer and use it in GitHub Desktop.
Save tr7zw/bc94dd2e6d4b86819a262bb0ff4f201b to your computer and use it in GitHub Desktop.
Itemstack tests
public class LegacyGet implements Benchmark {
public String getName() {
return "LegacyGet";
}
public int run(ItemStack stack) {
NBTItem nbti = new NBTItem(stack);
nbti.hasTag("demokey");
nbti.getType("demokey");
return nbti.getCompound("test").getInteger("subkey");
}
}
public class ModernGet implements Benchmark {
public String getName() {
return "NBT.get";
}
public int run(ItemStack stack) {
return NBT.get(stack, nbti -> {
nbti.hasTag("demokey");
nbti.getType("demokey");
return nbti.getCompound("test").getInteger("subkey");
});
}
}
public class LegacySet implements Benchmark {
public String getName() {
return "LegacySet";
}
public int run(ItemStack stack) {
NBTItem nbti = new NBTItem(stack);
NBTCompound comp = nbti.getCompound("test");
int count = comp.getInteger("subkey");
comp.setInteger("subkey", count + 1);
return comp.getInteger("subkey");
}
}
public class ModernSet implements Benchmark {
public String getName() {
return "NBT.modify";
}
public int run(ItemStack stack) {
return NBT.modify(stack, nbti -> {
ReadWriteNBT comp = nbti.getCompound("test");
int count = comp.getInteger("subkey");
comp.setInteger("subkey", count + 1);
return comp.getInteger("subkey");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment