|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> |
| 3 | +Date: Fri, 24 Apr 2026 02:41:08 -0400 |
| 4 | +Subject: [PATCH] Replace entity equipment items to array |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/net/minecraft/world/entity/EntityEquipment.java b/net/minecraft/world/entity/EntityEquipment.java |
| 8 | +index 2e7c404e3808c39c0835e1e39fd238af4cf41022..2a45165a23c62d7df097a3358f7e8c4b1500945c 100644 |
| 9 | +--- a/net/minecraft/world/entity/EntityEquipment.java |
| 10 | ++++ b/net/minecraft/world/entity/EntityEquipment.java |
| 11 | +@@ -13,11 +13,19 @@ public class EntityEquipment implements net.caffeinemc.mods.lithium.common.entit |
| 12 | + map1.putAll((Map<? extends EquipmentSlot, ? extends ItemStack>)map); |
| 13 | + return new EntityEquipment(map1); |
| 14 | + }, entityEquipment -> { |
| 15 | +- Map<EquipmentSlot, ItemStack> map = new EnumMap<>(entityEquipment.items); |
| 16 | +- map.values().removeIf(ItemStack::isEmpty); |
| 17 | ++ // Leaf start - Replace entity equipment items to array |
| 18 | ++ Map<EquipmentSlot, ItemStack> map = new EnumMap<>(EquipmentSlot.class); |
| 19 | ++ final ItemStack[] stacks = entityEquipment.items; |
| 20 | ++ for (int i = 0; i < stacks.length; i++) { |
| 21 | ++ ItemStack stack = stacks[i]; |
| 22 | ++ if (!stack.isEmpty()) { |
| 23 | ++ map.put(EquipmentSlot.VALUES_ARRAY[i], stack); |
| 24 | ++ } |
| 25 | ++ } |
| 26 | ++ // Leaf end - Replace entity equipment items to array |
| 27 | + return map; |
| 28 | + }); |
| 29 | +- private final EnumMap<EquipmentSlot, ItemStack> items; |
| 30 | ++ private final ItemStack[] items; // Leaf - Replace entity equipment items to array |
| 31 | + // Leaf start - Lithium - equipment tracking |
| 32 | + boolean shouldTickEnchantments = false; |
| 33 | + ItemStack recheckEnchantmentForStack = null; |
| 34 | +@@ -26,7 +34,15 @@ public class EntityEquipment implements net.caffeinemc.mods.lithium.common.entit |
| 35 | + // Leaf end - Lithium - equipment tracking |
| 36 | + |
| 37 | + private EntityEquipment(EnumMap<EquipmentSlot, ItemStack> items) { |
| 38 | +- this.items = items; |
| 39 | ++ // Leaf start - Replace entity equipment items to array |
| 40 | ++ ItemStack[] self = new ItemStack[EquipmentSlot.VALUES_ARRAY.length]; |
| 41 | ++ if (!items.isEmpty()) { |
| 42 | ++ for (Entry<EquipmentSlot, ItemStack> e : items.entrySet()) { |
| 43 | ++ self[e.getKey().ordinal()] = e.getValue(); |
| 44 | ++ } |
| 45 | ++ } |
| 46 | ++ this.items = self; |
| 47 | ++ // Leaf end - Replace entity equipment items to array |
| 48 | + } |
| 49 | + |
| 50 | + public EntityEquipment() { |
| 51 | +@@ -35,21 +51,25 @@ public class EntityEquipment implements net.caffeinemc.mods.lithium.common.entit |
| 52 | + |
| 53 | + public ItemStack set(EquipmentSlot slot, ItemStack stack) { |
| 54 | + // Leaf start - Lithium - equipment tracking |
| 55 | +- ItemStack oldStack = Objects.requireNonNullElse(this.items.put(slot, stack), ItemStack.EMPTY); |
| 56 | ++ // Leaf start - Replace entity equipment items to array |
| 57 | ++ final ItemStack[] items = this.items; |
| 58 | ++ final int slotIndex = slot.ordinal(); |
| 59 | ++ ItemStack oldStack = items[slotIndex]; |
| 60 | ++ items[slotIndex] = stack == null ? ItemStack.EMPTY : stack; |
| 61 | ++ // Leaf end - Replace entity equipment items to array |
| 62 | + if (inLevel) this.onEquipmentReplaced(oldStack, stack); |
| 63 | + return oldStack; |
| 64 | + // Leaf end - Lithium - equipment tracking |
| 65 | + } |
| 66 | + |
| 67 | + public ItemStack get(EquipmentSlot slot) { |
| 68 | +- return this.items.getOrDefault(slot, ItemStack.EMPTY); |
| 69 | ++ return this.items[slot.ordinal()]; // Leaf - Replace entity equipment items to array |
| 70 | + } |
| 71 | + |
| 72 | + public boolean isEmpty() { |
| 73 | + // Leaf start - Multithreaded tracker |
| 74 | +- for (int i = 0; i < EquipmentSlot.VALUES_ARRAY.length; i++) { |
| 75 | +- ItemStack itemStack = this.items.get(EquipmentSlot.VALUES_ARRAY[i]); |
| 76 | +- if (itemStack != null && !itemStack.isEmpty()) { |
| 77 | ++ for (ItemStack itemStack : this.items) { // Leaf - Replace entity equipment items to array |
| 78 | ++ if (!itemStack.isEmpty()) { // Leaf - Replace entity equipment items to array |
| 79 | + return false; |
| 80 | + } |
| 81 | + } |
| 82 | +@@ -59,23 +79,25 @@ public class EntityEquipment implements net.caffeinemc.mods.lithium.common.entit |
| 83 | + } |
| 84 | + |
| 85 | + public void tick(Entity entity) { |
| 86 | +- for (Entry<EquipmentSlot, ItemStack> entry : this.items.entrySet()) { |
| 87 | +- ItemStack itemStack = entry.getValue(); |
| 88 | ++ // Leaf start - Replace entity equipment items to array |
| 89 | ++ final ItemStack[] items = this.items; |
| 90 | ++ for (int i = 0; i < items.length; i++) { |
| 91 | ++ ItemStack itemStack = items[i]; |
| 92 | + if (!itemStack.isEmpty()) { |
| 93 | +- itemStack.inventoryTick(entity.level(), entity, entry.getKey()); |
| 94 | ++ itemStack.inventoryTick(entity.level(), entity, EquipmentSlot.VALUES_ARRAY[i]); |
| 95 | + } |
| 96 | + } |
| 97 | ++ // Leaf end - Replace entity equipment items to array |
| 98 | + } |
| 99 | + |
| 100 | + public void setAll(EntityEquipment equipment) { |
| 101 | + if (this.inLevel) this.invalidateData(); // Leaf - Lithium - equipment tracking |
| 102 | +- this.items.clear(); |
| 103 | +- this.items.putAll(equipment.items); |
| 104 | ++ System.arraycopy(equipment.items, 0, this.items, 0, this.items.length); // Leaf - Replace entity equipment items to array |
| 105 | + if (this.inLevel) this.initializeData(); // Leaf - Lithium - equipment tracking |
| 106 | + } |
| 107 | + |
| 108 | + public void dropAll(LivingEntity entity) { |
| 109 | +- for (ItemStack itemStack : this.items.values()) { |
| 110 | ++ for (ItemStack itemStack : this.items) { // Leaf - Replace entity equipment items to array |
| 111 | + entity.drop(itemStack, true, false); |
| 112 | + } |
| 113 | + |
| 114 | +@@ -83,14 +105,14 @@ public class EntityEquipment implements net.caffeinemc.mods.lithium.common.entit |
| 115 | + } |
| 116 | + |
| 117 | + public void clear() { |
| 118 | +- this.items.replaceAll((equipmentSlot, itemStack) -> ItemStack.EMPTY); |
| 119 | ++ java.util.Arrays.fill(this.items, ItemStack.EMPTY); // Leaf - Replace entity equipment items to array |
| 120 | + if (inLevel) this.invalidateData(); // Leaf - Lithium - equipment tracking |
| 121 | + } |
| 122 | + |
| 123 | + // Paper start - EntityDeathEvent |
| 124 | + // Needed to not set ItemStack.EMPTY to not existent slot. |
| 125 | + public boolean has(final EquipmentSlot slot) { |
| 126 | +- return this.items.containsKey(slot); |
| 127 | ++ return this.items[slot.ordinal()] != ItemStack.EMPTY; // Leaf - Replace entity equipment items to array |
| 128 | + } |
| 129 | + // Paper end - EntityDeathEvent |
| 130 | + |
| 131 | +@@ -213,7 +235,7 @@ public class EntityEquipment implements net.caffeinemc.mods.lithium.common.entit |
| 132 | + this.recheckEnchantmentForStack = null; |
| 133 | + this.hasUnsentEquipmentChanges = true; |
| 134 | + |
| 135 | +- for (ItemStack oldStack : this.items.values()) { |
| 136 | ++ for (ItemStack oldStack : this.items) { // Leaf - Replace entity equipment items to array |
| 137 | + if (!oldStack.isEmpty()) { |
| 138 | + //noinspection unchecked |
| 139 | + oldStack.lithium$unsubscribeWithData(this, 0); |
| 140 | +@@ -226,7 +248,7 @@ public class EntityEquipment implements net.caffeinemc.mods.lithium.common.entit |
| 141 | + this.recheckEnchantmentForStack = null; |
| 142 | + this.hasUnsentEquipmentChanges = true; |
| 143 | + |
| 144 | +- for (ItemStack newStack : this.items.values()) { |
| 145 | ++ for (ItemStack newStack : this.items) { // Leaf - Replace entity equipment items to array |
| 146 | + if (!newStack.isEmpty()) { |
| 147 | + if (!this.shouldTickEnchantments) { |
| 148 | + this.shouldTickEnchantments = stackHasTickableEnchantment(newStack); |
0 commit comments