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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ import java.util.Collections;
|
||||
//$$ import net.minecraft.network.play.server.SPacketUseBed;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11100
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10904
|
||||
import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.WorldEventS2CPacket;
|
||||
@@ -53,6 +57,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
//$$ import net.minecraft.util.MathHelper;
|
||||
//#endif
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
@@ -63,7 +68,7 @@ public class RecordingEventHandler extends EventRegistrations {
|
||||
private final PacketListener packetListener;
|
||||
|
||||
private Double lastX, lastY, lastZ;
|
||||
private ItemStack[] playerItems = new ItemStack[6];
|
||||
private final List<ItemStack> playerItems = DefaultedList.ofSize(6, ItemStack.EMPTY);
|
||||
private int ticksSinceLastCorrection;
|
||||
private boolean wasSleeping;
|
||||
private int lastRiding = -1;
|
||||
@@ -260,8 +265,8 @@ public class RecordingEventHandler extends EventRegistrations {
|
||||
//$$ ItemStack stack = player.getEquipmentInSlot(slot);
|
||||
//$$ int index = slot;
|
||||
//#endif
|
||||
if (playerItems[index] != stack) {
|
||||
playerItems[index] = stack;
|
||||
if (!ItemStack.areEqual(playerItems.get(index), stack)) {
|
||||
playerItems.set(index, stack);
|
||||
//#if MC>=11600
|
||||
packetListener.save(new EntityEquipmentUpdateS2CPacket(player.getEntityId(), Collections.singletonList(Pair.of(slot, stack))));
|
||||
//#else
|
||||
|
||||
Reference in New Issue
Block a user