9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 03:19:21 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0068-Replace-Entity-active-effects-map-with-optimized-col.patch
Dreeam 01fa6ac227 Add Leaf Commands (WIP)
* Added Leaf Commands base
* Added WIP /leaf reload
* Added /leaf version
* Change /gale permission to OP as default
2025-02-22 03:15:42 -05:00

42 lines
2.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Tue, 17 Sep 2024 02:35:13 -0400
Subject: [PATCH] Replace Entity active effects map with optimized collection
Dreeam TODO: check this
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index a307ee08f12cb21d17cfbaf969db7c46f10040fb..4f0da30fa659ecabdfbd1d17e50888c32501b6e7 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -211,6 +211,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
};
private final AttributeMap attributes;
public CombatTracker combatTracker = new CombatTracker(this);
+ // Need to figure out the difference of mem access pattern between hash map and obj2obj hash map (separate chaining vs open addressing)
+ // Benchmark is needed for get calls for this active effects map.
+ // Also need to check whether call from out of main using bukkit api
+ //public final Map<Holder<MobEffect>, MobEffectInstance> activeEffects = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(0); // Leaf - Replace Entity active effects map with optimized collection
public final Map<Holder<MobEffect>, MobEffectInstance> activeEffects = Maps.newHashMap();
private final NonNullList<ItemStack> lastHandItemStacks = NonNullList.withSize(2, ItemStack.EMPTY);
private final NonNullList<ItemStack> lastArmorItemStacks = NonNullList.withSize(4, ItemStack.EMPTY);
@@ -990,15 +994,16 @@ public abstract class LivingEntity extends Entity implements Attackable {
private void updateSynchronizedMobEffectParticles() {
// Leaf start - Remove stream in entity visible effects filter
List<ParticleOptions> list = new ArrayList<>();
+ final Collection<MobEffectInstance> effectsValues = this.activeEffects.values(); // Leaf - Replace Entity active effects map with optimized collection
- for (MobEffectInstance effect : this.activeEffects.values()) {
+ for (MobEffectInstance effect : effectsValues) { // Leaf - Replace Entity active effects map with optimized collection
if (effect.isVisible()) {
list.add(effect.getParticleOptions());
}
}
// Leaf end - Remove stream in entity visible effects filter
this.entityData.set(DATA_EFFECT_PARTICLES, list);
- this.entityData.set(DATA_EFFECT_AMBIENCE_ID, areAllEffectsAmbient(this.activeEffects.values()));
+ this.entityData.set(DATA_EFFECT_AMBIENCE_ID, areAllEffectsAmbient(effectsValues)); // Leaf - Replace Entity active effects map with optimized collection
}
private void updateGlowingStatus() {