Use DefaultedList for equipment tracking

Because on 1.11+ a `null` item stack is not something that should exist.
This then also allows us to compare item stacks by value rather than only by
reference, potentially saving a few redundant entity equipment update
packets (but more importantly, also allows us to store a copy instead of the
original, which will be important for the next commit).
This commit is contained in:
Jonas Herzig
2022-07-31 12:49:46 +02:00
parent 42d04d123c
commit 62b9cd0538
3 changed files with 23 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.text.LiteralText;
@@ -49,6 +50,10 @@ import net.minecraft.client.util.Window;
//$$ import net.minecraft.client.gui.GuiButton;
//#endif
//#if MC>=11100
import net.minecraft.util.collection.DefaultedList;
//#endif
//#if MC>=10904
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.crash.CrashCallable;
@@ -669,4 +674,13 @@ class Patterns {
return manager.getResource(id);
//#endif
}
@Pattern
private static List<ItemStack> DefaultedList_ofSize_ItemStack_Empty(int size) {
//#if MC>=11100
return DefaultedList.ofSize(size, ItemStack.EMPTY);
//#else
//$$ return java.util.Arrays.asList(new ItemStack[size]);
//#endif
}
}