mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 10:29:13 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@6bb9dc6b Normalize and trim spaces in Player#performCommand (#12892) PaperMC/Paper@840dd9e1 Fix dialog preconditions (#12895) PaperMC/Paper@9ccc51df Fix legacy pearls forgetting owner on disconnect (#12884) PaperMC/Paper@57c13137 Allow to change despawnInPeaceful (#12880) PaperMC/Paper@a5763618 Add WorldDifficultyChangeEvent (#12471) PaperMC/Paper@dbc367ba Keep non-container slots synced when in container view (#12881)
535 lines
34 KiB
Diff
535 lines
34 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Sat, 26 Nov 2022 11:25:45 +0100
|
|
Subject: [PATCH] Reduce array allocations
|
|
|
|
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
Enum's values returns anew array copy of the enums, this behavior is defined in
|
|
`src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java#visitEnumDef`
|
|
|
|
This is a defensive programming strategy to prevent enums from being modified. However,
|
|
copying is unnecessary if we only have read calls.
|
|
So we can cache the values result to avoid useless allocations.
|
|
|
|
Cached as the array since it does not create iterator on the enhanced for loop,
|
|
But the list does, and may spend more time than iterating using the array.
|
|
|
|
The JMH benchmark of this patch can be found in SunBox's `CachedEnumValuesForLoop`
|
|
|
|
This patch is based on the following patch:
|
|
"reduce allocs"
|
|
By: Simon Gardling <titaniumtown@gmail.com>
|
|
As part of: JettPack (https://gitlab.com/Titaniumtown/JettPack)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
index b2bcfb3557a0326fd7ec1059f95d6da4568dfd80..fee4a7452178c274eb835d758b718d8e874d79d0 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
@@ -400,7 +400,6 @@ public final class ChunkEntitySlices {
|
|
|
|
private static final class BasicEntityList<E extends Entity> {
|
|
|
|
- private static final Entity[] EMPTY = new Entity[0];
|
|
private static final int DEFAULT_CAPACITY = 4;
|
|
|
|
private E[] storage;
|
|
@@ -411,7 +410,7 @@ public final class ChunkEntitySlices {
|
|
}
|
|
|
|
public BasicEntityList(final int cap) {
|
|
- this.storage = (E[])(cap <= 0 ? EMPTY : new Entity[cap]);
|
|
+ this.storage = (E[])(cap <= 0 ? me.titaniumtown.ArrayConstants.emptyEntityArray : new Entity[cap]);// Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
@@ -423,7 +422,7 @@ public final class ChunkEntitySlices {
|
|
}
|
|
|
|
private void resize() {
|
|
- if (this.storage == EMPTY) {
|
|
+ if (this.storage == me.titaniumtown.ArrayConstants.emptyEntityArray) { // Gale - JettPack - reduce array allocations
|
|
this.storage = (E[])new Entity[DEFAULT_CAPACITY];
|
|
} else {
|
|
this.storage = Arrays.copyOf(this.storage, this.storage.length * 2);
|
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/server/ServerEntityLookup.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/server/ServerEntityLookup.java
|
|
index 82824ae7ffbced513a8bcace684af94916135e84..47a600204ae1a1e7f166284dc26a1a7afc1dbecc 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/server/ServerEntityLookup.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/server/ServerEntityLookup.java
|
|
@@ -19,10 +19,8 @@ import net.minecraft.world.level.entity.LevelCallback;
|
|
|
|
public final class ServerEntityLookup extends EntityLookup {
|
|
|
|
- private static final Entity[] EMPTY_ENTITY_ARRAY = new Entity[0];
|
|
-
|
|
private final ServerLevel serverWorld;
|
|
- public final ReferenceList<Entity> trackerEntities = new ReferenceList<>(EMPTY_ENTITY_ARRAY); // Moonrise - entity tracker
|
|
+ public final ReferenceList<Entity> trackerEntities = new ReferenceList<>(me.titaniumtown.ArrayConstants.emptyEntityArray); // Moonrise - entity tracker // Gale - JettPack - reduce array allocations
|
|
|
|
// Vanilla does not increment ticket timeouts if the chunk is progressing in generation. They made this change in 1.21.6 so that the ender pearl
|
|
// ticket does not expire if the chunk fails to generate before the timeout expires. Rather than blindly adjusting the entire system behavior
|
|
diff --git a/net/minecraft/nbt/ByteArrayTag.java b/net/minecraft/nbt/ByteArrayTag.java
|
|
index 6fbb131b472a3093b137d8ced9889777a133bd5b..cecfd48f57bc11b84c18b4e5a723228fd3c18e23 100644
|
|
--- a/net/minecraft/nbt/ByteArrayTag.java
|
|
+++ b/net/minecraft/nbt/ByteArrayTag.java
|
|
@@ -144,7 +144,7 @@ public final class ByteArrayTag implements CollectionTag {
|
|
|
|
@Override
|
|
public void clear() {
|
|
- this.data = new byte[0];
|
|
+ this.data = me.titaniumtown.ArrayConstants.emptyByteArray; // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/nbt/IntArrayTag.java b/net/minecraft/nbt/IntArrayTag.java
|
|
index a8ea2aeb5a02903a37376fb78b49c10745147411..e50bbf1318e9f16f83723eab1389c189baf840a2 100644
|
|
--- a/net/minecraft/nbt/IntArrayTag.java
|
|
+++ b/net/minecraft/nbt/IntArrayTag.java
|
|
@@ -151,7 +151,7 @@ public final class IntArrayTag implements CollectionTag {
|
|
|
|
@Override
|
|
public void clear() {
|
|
- this.data = new int[0];
|
|
+ this.data = me.titaniumtown.ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/nbt/LongArrayTag.java b/net/minecraft/nbt/LongArrayTag.java
|
|
index c90024aecb4b2424b3ef37194b0686734ab43db9..fd8a4bfe065698ea320800bc2b22474b1c5c4ca9 100644
|
|
--- a/net/minecraft/nbt/LongArrayTag.java
|
|
+++ b/net/minecraft/nbt/LongArrayTag.java
|
|
@@ -150,7 +150,7 @@ public final class LongArrayTag implements CollectionTag {
|
|
|
|
@Override
|
|
public void clear() {
|
|
- this.data = new long[0];
|
|
+ this.data = me.titaniumtown.ArrayConstants.emptyLongArray; // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/network/CipherBase.java b/net/minecraft/network/CipherBase.java
|
|
index 121685cacef111fbec0057d386f748497bc3a36d..b4a4fafec1a8e279ec1e31e58fee2d5d34fb8289 100644
|
|
--- a/net/minecraft/network/CipherBase.java
|
|
+++ b/net/minecraft/network/CipherBase.java
|
|
@@ -7,8 +7,8 @@ import javax.crypto.ShortBufferException;
|
|
|
|
public class CipherBase {
|
|
private final Cipher cipher;
|
|
- private byte[] heapIn = new byte[0];
|
|
- private byte[] heapOut = new byte[0];
|
|
+ private byte[] heapIn = me.titaniumtown.ArrayConstants.emptyByteArray; // Gale - JettPack - reduce array allocations
|
|
+ private byte[] heapOut = me.titaniumtown.ArrayConstants.emptyByteArray; // Gale - JettPack - reduce array allocations
|
|
|
|
protected CipherBase(Cipher cipher) {
|
|
this.cipher = cipher;
|
|
diff --git a/net/minecraft/network/chat/contents/TranslatableContents.java b/net/minecraft/network/chat/contents/TranslatableContents.java
|
|
index 8ef16f98996b1ec0c9c3f158248ac95f1b07328f..6780b2493d625603b74e635c4996bb8303ce5b9a 100644
|
|
--- a/net/minecraft/network/chat/contents/TranslatableContents.java
|
|
+++ b/net/minecraft/network/chat/contents/TranslatableContents.java
|
|
@@ -29,7 +29,7 @@ import net.minecraft.util.ExtraCodecs;
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
public class TranslatableContents implements ComponentContents {
|
|
- public static final Object[] NO_ARGS = new Object[0];
|
|
+ public static final Object[] NO_ARGS = me.titaniumtown.ArrayConstants.emptyObjectArray; // Gale - JettPack - reduce array allocations
|
|
private static final Codec<Object> PRIMITIVE_ARG_CODEC = ExtraCodecs.JAVA.validate(TranslatableContents::filterAllowedArguments);
|
|
private static final Codec<Object> ARG_CODEC = Codec.either(PRIMITIVE_ARG_CODEC, ComponentSerialization.CODEC)
|
|
.xmap(
|
|
diff --git a/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java
|
|
index 5df8ee3955593e70f0e67e91431e464d177bdeeb..b7581796dda77bca66c03e421f2a83a920f44ef1 100644
|
|
--- a/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/net/minecraft/server/level/ServerEntity.java
|
|
@@ -366,7 +366,7 @@ public class ServerEntity {
|
|
if (this.entity instanceof LivingEntity livingEntityx) {
|
|
List<Pair<EquipmentSlot, ItemStack>> list = Lists.newArrayList();
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemBySlot = livingEntityx.getItemBySlot(equipmentSlot);
|
|
if (!itemBySlot.isEmpty()) {
|
|
list.add(Pair.of(equipmentSlot, itemBySlot.copy()));
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index a9c2f419200483673f6743ed94af110a8e875e71..617eb1b9d30d499124576c5d7cb5152571cc6b84 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1228,7 +1228,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
|
|
public static List<Entity> getCurrentlyTickingEntities() {
|
|
Entity ticking = currentlyTickingEntity.get();
|
|
- List<Entity> ret = java.util.Arrays.asList(ticking == null ? new Entity[0] : new Entity[] { ticking });
|
|
+ List<Entity> ret = java.util.Arrays.asList(ticking == null ? me.titaniumtown.ArrayConstants.emptyEntityArray : new Entity[] { ticking }); // Gale - JettPack - reduce array allocations
|
|
|
|
return ret;
|
|
}
|
|
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
index 917908e69154c5c5c9f847ae47548ee3d9221bc2..e4976eff4d18a1a1a752956c7e214122ddb05401 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1104,7 +1104,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
this.getInventory().getNonEquipmentItems().set(i, net.minecraft.world.item.ItemStack.EMPTY);
|
|
}
|
|
}
|
|
- for (final EquipmentSlot value : EquipmentSlot.VALUES) {
|
|
+ for (final EquipmentSlot value : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
if (this.getInventory().equipment.has(value) && !shouldKeepDeathEventItem(event, this.getInventory().equipment.get(value))) {
|
|
this.getInventory().equipment.set(value, net.minecraft.world.item.ItemStack.EMPTY);
|
|
}
|
|
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 7b4eb3773bc88cc5b5287b55388a4dab2a2f562b..a2e43621a9ad2eb7eef0b4a5d7c9bf0f627b9bc9 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2795,7 +2795,7 @@ public class ServerGamePacketListenerImpl
|
|
// SPIGOT-7136 - Allays
|
|
if (target instanceof net.minecraft.world.entity.animal.allay.Allay || target instanceof net.minecraft.world.entity.animal.horse.AbstractHorse) { // Paper - Fix horse armor desync
|
|
ServerGamePacketListenerImpl.this.send(new net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket(
|
|
- target.getId(), java.util.Arrays.stream(net.minecraft.world.entity.EquipmentSlot.values())
|
|
+ target.getId(), java.util.Arrays.stream(net.minecraft.world.entity.EquipmentSlot.VALUES_ARRAY) // Gale - JettPack - reduce array allocations
|
|
.map((slot) -> com.mojang.datafixers.util.Pair.of(slot, ((LivingEntity) target).getItemBySlot(slot).copy()))
|
|
.collect(Collectors.toList()), true)); // Paper - sanitize
|
|
player.containerMenu.sendAllDataToRemote();
|
|
diff --git a/net/minecraft/server/players/StoredUserList.java b/net/minecraft/server/players/StoredUserList.java
|
|
index d445e8f126f077d8419c52fa5436ea963a1a42a4..39483f7b453d6faedeccc1ab1eda76669395ea5a 100644
|
|
--- a/net/minecraft/server/players/StoredUserList.java
|
|
+++ b/net/minecraft/server/players/StoredUserList.java
|
|
@@ -70,7 +70,7 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
}
|
|
|
|
public String[] getUserList() {
|
|
- return this.map.keySet().toArray(new String[0]);
|
|
+ return this.map.keySet().toArray(me.titaniumtown.ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
diff --git a/net/minecraft/util/ZeroBitStorage.java b/net/minecraft/util/ZeroBitStorage.java
|
|
index 09fd99c9cbd23b5f3c899bfb00c9b89651948ed8..5c1103ef028e5ffe6ce0eadc861dd3b2c8f3ed9f 100644
|
|
--- a/net/minecraft/util/ZeroBitStorage.java
|
|
+++ b/net/minecraft/util/ZeroBitStorage.java
|
|
@@ -5,7 +5,7 @@ import java.util.function.IntConsumer;
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
public class ZeroBitStorage implements BitStorage {
|
|
- public static final long[] RAW = new long[0];
|
|
+ public static final long[] RAW = me.titaniumtown.ArrayConstants.emptyLongArray; // Gale - JettPack - reduce array allocations
|
|
private final int size;
|
|
|
|
public ZeroBitStorage(int size) {
|
|
diff --git a/net/minecraft/world/entity/ConversionType.java b/net/minecraft/world/entity/ConversionType.java
|
|
index 3eea236bd1fd401fefdf7c5cc553a3db335029c7..3739272cbc73b7c4f15a2fbe874905cf06175f64 100644
|
|
--- a/net/minecraft/world/entity/ConversionType.java
|
|
+++ b/net/minecraft/world/entity/ConversionType.java
|
|
@@ -37,7 +37,7 @@ public enum ConversionType {
|
|
}
|
|
|
|
if (conversionParams.keepEquipment()) {
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemBySlot = oldMob.getItemBySlot(equipmentSlot);
|
|
if (!itemBySlot.isEmpty()) {
|
|
newMob.setItemSlot(equipmentSlot, itemBySlot.copyAndClear());
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index c941e144667f04e8710da9dacc3f5e02731303bd..977198e485053847b051b9e9ae60c6d8be6600cc 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -3076,7 +3076,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
|
|
private boolean attemptToShearEquipment(Player player, InteractionHand hand, ItemStack stack, Mob mob) {
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemBySlot = mob.getItemBySlot(equipmentSlot);
|
|
Equippable equippable = itemBySlot.get(DataComponents.EQUIPPABLE);
|
|
if (equippable != null
|
|
diff --git a/net/minecraft/world/entity/EquipmentSlot.java b/net/minecraft/world/entity/EquipmentSlot.java
|
|
index 0e44397c9d53ff30a96c9e8e392a363fa9ae0c55..dbf31389f0e9796c80afbffddf6a20cbaf184e6e 100644
|
|
--- a/net/minecraft/world/entity/EquipmentSlot.java
|
|
+++ b/net/minecraft/world/entity/EquipmentSlot.java
|
|
@@ -20,9 +20,12 @@ public enum EquipmentSlot implements StringRepresentable {
|
|
SADDLE(EquipmentSlot.Type.SADDLE, 0, 1, 7, "saddle");
|
|
|
|
public static final int NO_COUNT_LIMIT = 0;
|
|
- public static final List<EquipmentSlot> VALUES = List.of(values());
|
|
- public static final IntFunction<EquipmentSlot> BY_ID = ByIdMap.continuous(equipmentSlot -> equipmentSlot.id, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
|
|
- public static final StringRepresentable.EnumCodec<EquipmentSlot> CODEC = StringRepresentable.fromEnum(EquipmentSlot::values);
|
|
+ // Gale start - JettPack - reduce array allocations
|
|
+ public static final EquipmentSlot[] VALUES_ARRAY = values();
|
|
+ public static final List<EquipmentSlot> VALUES = List.of(VALUES_ARRAY);
|
|
+ public static final IntFunction<EquipmentSlot> BY_ID = ByIdMap.continuous(equipmentSlot -> equipmentSlot.id, VALUES_ARRAY, ByIdMap.OutOfBoundsStrategy.ZERO);
|
|
+ public static final StringRepresentable.EnumCodec<EquipmentSlot> CODEC = StringRepresentable.fromEnum(() -> VALUES_ARRAY);
|
|
+ // Gale end - JettPack - reduce array allocations
|
|
public static final StreamCodec<ByteBuf, EquipmentSlot> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, equipmentSlot -> equipmentSlot.id);
|
|
private final EquipmentSlot.Type type;
|
|
private final int index;
|
|
diff --git a/net/minecraft/world/entity/EquipmentSlotGroup.java b/net/minecraft/world/entity/EquipmentSlotGroup.java
|
|
index 381e0a1c0af7e339713ed1df1c2f21121c1bbd0f..4e847c3f9d761da5dda11dec60582d9d9e630b37 100644
|
|
--- a/net/minecraft/world/entity/EquipmentSlotGroup.java
|
|
+++ b/net/minecraft/world/entity/EquipmentSlotGroup.java
|
|
@@ -24,6 +24,7 @@ public enum EquipmentSlotGroup implements StringRepresentable, Iterable<Equipmen
|
|
BODY(9, "body", EquipmentSlot.BODY),
|
|
SADDLE(10, "saddle", EquipmentSlot.SADDLE);
|
|
|
|
+ public static final EquipmentSlotGroup[] VALUES_ARRAY = EquipmentSlotGroup.values(); // Gale - JettPack - reduce array allocations
|
|
public static final IntFunction<EquipmentSlotGroup> BY_ID = ByIdMap.continuous(
|
|
equipmentSlotGroup -> equipmentSlotGroup.id, values(), ByIdMap.OutOfBoundsStrategy.ZERO
|
|
);
|
|
diff --git a/net/minecraft/world/entity/EquipmentTable.java b/net/minecraft/world/entity/EquipmentTable.java
|
|
index b383836c200ca9f7bd84639367aa81b57868fb25..3af4a6dcc81afaf2860325fe5852c9a941f216d4 100644
|
|
--- a/net/minecraft/world/entity/EquipmentTable.java
|
|
+++ b/net/minecraft/world/entity/EquipmentTable.java
|
|
@@ -30,7 +30,7 @@ public record EquipmentTable(ResourceKey<LootTable> lootTable, Map<EquipmentSlot
|
|
}
|
|
|
|
private static Map<EquipmentSlot, Float> createForAllSlots(float dropChance) {
|
|
- return createForAllSlots(List.of(EquipmentSlot.values()), dropChance);
|
|
+ return createForAllSlots(List.of(EquipmentSlot.VALUES_ARRAY), dropChance); // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
private static Map<EquipmentSlot, Float> createForAllSlots(List<EquipmentSlot> equipmentSlots, float dropChance) {
|
|
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
|
index 395ebf0a5fa14d9ff43b2d2e8e63aeaaf4612443..c6f87ee9b7c2b0bfc2d459a86b60ad2eaa23b594 100644
|
|
--- a/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -3358,7 +3358,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
Map<org.bukkit.inventory.EquipmentSlot, io.papermc.paper.event.entity.EntityEquipmentChangedEvent.EquipmentChange> equipmentChanges = null;
|
|
// Paper end - EntityEquipmentChangedEvent
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemStack = this.lastEquipmentItems.get(equipmentSlot);
|
|
ItemStack itemBySlot = this.getItemBySlot(equipmentSlot);
|
|
if (this.equipmentHasChanged(itemStack, itemBySlot)) {
|
|
@@ -3630,7 +3630,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
|
|
public boolean canGlide() {
|
|
if (!this.onGround() && !this.isPassenger() && !this.hasEffect(MobEffects.LEVITATION)) {
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
if (canGlideUsing(this.getItemBySlot(equipmentSlot), equipmentSlot)) {
|
|
return true;
|
|
}
|
|
diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
|
|
index c620341e33dc1805f1c033a969d0a15e1484c176..4aec1fd4efbb3dd139542c55d06503716723f326 100644
|
|
--- a/net/minecraft/world/entity/Mob.java
|
|
+++ b/net/minecraft/world/entity/Mob.java
|
|
@@ -339,7 +339,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
if (this.xpReward > 0) {
|
|
int i = this.xpReward;
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
if (equipmentSlot.canIncreaseExperience()) {
|
|
ItemStack itemBySlot = this.getItemBySlot(equipmentSlot);
|
|
if (!itemBySlot.isEmpty() && this.dropChances.byEquipment(equipmentSlot) <= 1.0F) {
|
|
@@ -963,7 +963,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
protected void dropCustomDeathLoot(ServerLevel level, DamageSource damageSource, boolean recentlyHit) {
|
|
super.dropCustomDeathLoot(level, damageSource, recentlyHit);
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
if (this.shouldSkipLoot(equipmentSlot)) continue; // Paper
|
|
ItemStack itemBySlot = this.getItemBySlot(equipmentSlot);
|
|
float f = this.dropChances.byEquipment(equipmentSlot);
|
|
@@ -1007,7 +1007,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
public Set<EquipmentSlot> dropPreservedEquipment(ServerLevel level, Predicate<ItemStack> filter) {
|
|
Set<EquipmentSlot> set = new HashSet<>();
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemBySlot = this.getItemBySlot(equipmentSlot);
|
|
if (!itemBySlot.isEmpty()) {
|
|
if (!filter.test(itemBySlot)) {
|
|
@@ -1135,7 +1135,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
protected void populateDefaultEquipmentEnchantments(ServerLevelAccessor level, RandomSource random, DifficultyInstance difficulty) {
|
|
this.enchantSpawnedWeapon(level, random, difficulty);
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
if (equipmentSlot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR) {
|
|
this.enchantSpawnedArmor(level, random, equipmentSlot, difficulty);
|
|
}
|
|
@@ -1552,7 +1552,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
protected void removeAfterChangingDimensions() {
|
|
super.removeAfterChangingDimensions();
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemBySlot = this.getItemBySlot(equipmentSlot);
|
|
if (!itemBySlot.isEmpty()) {
|
|
itemBySlot.setCount(0);
|
|
diff --git a/net/minecraft/world/entity/decoration/ArmorStand.java b/net/minecraft/world/entity/decoration/ArmorStand.java
|
|
index 5ee368580d878a3845349c3d50cc0dc549c42cab..9952e84dd94b8773c5ba8fcc4526e7714ebc2136 100644
|
|
--- a/net/minecraft/world/entity/decoration/ArmorStand.java
|
|
+++ b/net/minecraft/world/entity/decoration/ArmorStand.java
|
|
@@ -456,7 +456,7 @@ public class ArmorStand extends LivingEntity {
|
|
this.playBrokenSound();
|
|
// this.dropAllDeathLoot(level, damageSource); // CraftBukkit - moved down
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemStack = this.equipment.get(equipmentSlot); // Paper - move equipment removal past event call
|
|
if (!itemStack.isEmpty()) {
|
|
this.drops.add(new DefaultDrop(itemStack, stack -> Block.popResource(this.level(), this.blockPosition().above(), stack))); // CraftBukkit - add to drops // Paper - Restore vanilla drops behavior; mirror so we can destroy it later - though this call site was safe & spawn drops correctly}
|
|
@@ -465,7 +465,7 @@ public class ArmorStand extends LivingEntity {
|
|
// Paper start - move equipment removal past event call
|
|
org.bukkit.event.entity.EntityDeathEvent event = this.dropAllDeathLoot(level, damageSource);
|
|
if (!event.isCancelled()) {
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
this.equipment.set(equipmentSlot, ItemStack.EMPTY);
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
|
|
index e5e08dbefead90e9fe2bb05e4f0257f7aa4c0686..5160c349f1ace36d6de11f23e0f957f37fc19165 100644
|
|
--- a/net/minecraft/world/entity/player/Player.java
|
|
+++ b/net/minecraft/world/entity/player/Player.java
|
|
@@ -413,7 +413,7 @@ public abstract class Player extends LivingEntity {
|
|
}
|
|
|
|
private boolean isEquipped(Item item) {
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemBySlot = this.getItemBySlot(equipmentSlot);
|
|
Equippable equippable = itemBySlot.get(DataComponents.EQUIPPABLE);
|
|
if (itemBySlot.is(item) && equippable != null && equippable.slot() == equipmentSlot) {
|
|
diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java
|
|
index da16f4831c875e07c25d7ed041bed493db614658..951c86278e8cb5cd801a5db2ebfabef8c6d813ef 100644
|
|
--- a/net/minecraft/world/item/ItemStack.java
|
|
+++ b/net/minecraft/world/item/ItemStack.java
|
|
@@ -1149,7 +1149,7 @@ public final class ItemStack implements DataComponentHolder {
|
|
|
|
private void addAttributeTooltips(Consumer<Component> tooltipAdder, TooltipDisplay tooltipDisplay, @Nullable Player player) {
|
|
if (tooltipDisplay.shows(DataComponents.ATTRIBUTE_MODIFIERS)) {
|
|
- for (EquipmentSlotGroup equipmentSlotGroup : EquipmentSlotGroup.values()) {
|
|
+ for (EquipmentSlotGroup equipmentSlotGroup : EquipmentSlotGroup.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
MutableBoolean mutableBoolean = new MutableBoolean(true);
|
|
this.forEachModifier(
|
|
equipmentSlotGroup,
|
|
diff --git a/net/minecraft/world/item/crafting/ShapedRecipePattern.java b/net/minecraft/world/item/crafting/ShapedRecipePattern.java
|
|
index bfda76974ea8d4397e2c2ebf5bdcb5d7e5f0bab5..cabbc93409ca99180d115e2f23419ee1824d5801 100644
|
|
--- a/net/minecraft/world/item/crafting/ShapedRecipePattern.java
|
|
+++ b/net/minecraft/world/item/crafting/ShapedRecipePattern.java
|
|
@@ -121,7 +121,7 @@ public final class ShapedRecipePattern {
|
|
}
|
|
|
|
if (pattern.size() == i3) {
|
|
- return new String[0];
|
|
+ return me.titaniumtown.ArrayConstants.emptyStringArray; // Gale - JettPack - reduce array allocations
|
|
} else {
|
|
String[] strings = new String[pattern.size() - i3 - i2];
|
|
|
|
diff --git a/net/minecraft/world/item/enchantment/Enchantment.java b/net/minecraft/world/item/enchantment/Enchantment.java
|
|
index 7a620eb92b1e672cedd72ec4d986c01eba337686..0460da0124d2c48b7fed45fa182537fd8059135d 100644
|
|
--- a/net/minecraft/world/item/enchantment/Enchantment.java
|
|
+++ b/net/minecraft/world/item/enchantment/Enchantment.java
|
|
@@ -109,7 +109,7 @@ public record Enchantment(Component description, Enchantment.EnchantmentDefiniti
|
|
public Map<EquipmentSlot, ItemStack> getSlotItems(LivingEntity entity) {
|
|
Map<EquipmentSlot, ItemStack> map = Maps.newEnumMap(EquipmentSlot.class);
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
if (this.matchingSlot(equipmentSlot)) {
|
|
ItemStack itemBySlot = entity.getItemBySlot(equipmentSlot);
|
|
if (!itemBySlot.isEmpty()) {
|
|
diff --git a/net/minecraft/world/item/enchantment/EnchantmentHelper.java b/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
|
index 66234431b265e0596275ca468cd40f8da98c22e2..b20415b47e209aedbc60ff17238e575dfe33849a 100644
|
|
--- a/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
|
+++ b/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
|
@@ -153,7 +153,7 @@ public class EnchantmentHelper {
|
|
}
|
|
|
|
private static void runIterationOnEquipment(LivingEntity entity, EnchantmentHelper.EnchantmentInSlotVisitor visitor) {
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
runIterationOnItem(entity.getItemBySlot(equipmentSlot), equipmentSlot, entity, visitor);
|
|
}
|
|
}
|
|
@@ -467,7 +467,7 @@ public class EnchantmentHelper {
|
|
public static Optional<EnchantedItemInUse> getRandomItemWith(DataComponentType<?> componentType, LivingEntity entity, Predicate<ItemStack> filter) {
|
|
List<EnchantedItemInUse> list = new ArrayList<>();
|
|
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
ItemStack itemBySlot = entity.getItemBySlot(equipmentSlot);
|
|
if (filter.test(itemBySlot)) {
|
|
ItemEnchantments itemEnchantments = itemBySlot.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY);
|
|
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
|
index a0254e85fccebb66ce02bd58f9d461addd8ad73d..1f7b3db02e59c4cbc93bc0e4e42bd20e0031c4bd 100644
|
|
--- a/net/minecraft/world/level/Level.java
|
|
+++ b/net/minecraft/world/level/Level.java
|
|
@@ -1825,7 +1825,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
public org.bukkit.entity.Entity[] getChunkEntities(int chunkX, int chunkZ) {
|
|
ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices slices = ((ServerLevel)this).moonrise$getEntityLookup().getChunk(chunkX, chunkZ);
|
|
if (slices == null) {
|
|
- return new org.bukkit.entity.Entity[0];
|
|
+ return me.titaniumtown.ArrayConstants.emptyBukkitEntityArray; // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
List<org.bukkit.entity.Entity> ret = new java.util.ArrayList<>();
|
|
@@ -1836,7 +1836,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
}
|
|
}
|
|
|
|
- return ret.toArray(new org.bukkit.entity.Entity[0]);
|
|
+ return ret.toArray(me.titaniumtown.ArrayConstants.emptyBukkitEntityArray); // Gale - JettPack - reduce array allocations
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
|
|
diff --git a/net/minecraft/world/level/block/ComposterBlock.java b/net/minecraft/world/level/block/ComposterBlock.java
|
|
index a647d76d365a60b95a3eb7927ac426bf70d417f3..7977ecd013c55359f179b4b7f895099b7eb02294 100644
|
|
--- a/net/minecraft/world/level/block/ComposterBlock.java
|
|
+++ b/net/minecraft/world/level/block/ComposterBlock.java
|
|
@@ -419,7 +419,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
|
|
@Override
|
|
public int[] getSlotsForFace(Direction side) {
|
|
- return new int[0];
|
|
+ return me.titaniumtown.ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
@@ -454,7 +454,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
|
|
@Override
|
|
public int[] getSlotsForFace(Direction side) {
|
|
- return side == Direction.UP ? new int[]{0} : new int[0];
|
|
+ return side == Direction.UP ? me.titaniumtown.ArrayConstants.zeroSingletonIntArray : me.titaniumtown.ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
@@ -505,7 +505,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
|
|
@Override
|
|
public int[] getSlotsForFace(Direction side) {
|
|
- return side == Direction.DOWN ? new int[]{0} : new int[0];
|
|
+ return side == Direction.DOWN ? me.titaniumtown.ArrayConstants.zeroSingletonIntArray : me.titaniumtown.ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
index 36a72a11d28f99bfe85868461925b778cc01478e..ca2cab797fc16f0961ce994fcb45029589b3c370 100644
|
|
--- a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
@@ -44,7 +44,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
|
|
protected static final int SLOT_FUEL = 1;
|
|
protected static final int SLOT_RESULT = 2;
|
|
public static final int DATA_LIT_TIME = 0;
|
|
- private static final int[] SLOTS_FOR_UP = new int[]{0};
|
|
+ private static final int[] SLOTS_FOR_UP = me.titaniumtown.ArrayConstants.zeroSingletonIntArray; // Gale - JettPack - reduce array allocations
|
|
private static final int[] SLOTS_FOR_DOWN = new int[]{2, 1};
|
|
private static final int[] SLOTS_FOR_SIDES = new int[]{1};
|
|
public static final int DATA_LIT_DURATION = 1;
|
|
diff --git a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
index c8f23011a8942a5be970c606f67142cbd202b97e..98971a07757d29d6926a0aa05f229b8020af42b6 100644
|
|
--- a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
+++ b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
@@ -258,7 +258,7 @@ public class MapItemSavedData extends SavedData {
|
|
}
|
|
|
|
private static boolean hasMapInvisibilityItemEquipped(Player player) {
|
|
- for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
|
|
+ for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES_ARRAY) { // Gale - JettPack - reduce array allocations
|
|
if (equipmentSlot != EquipmentSlot.MAINHAND
|
|
&& equipmentSlot != EquipmentSlot.OFFHAND
|
|
&& player.getItemBySlot(equipmentSlot).is(ItemTags.MAP_INVISIBILITY_EQUIPMENT)) {
|