/
0038-Reduce-entity-allocations.patch
52 lines (45 loc) · 2.68 KB
/
0038-Reduce-entity-allocations.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Paul <paul@technove.co>
Date: Fri, 2 Jul 2021 18:25:18 -0500
Subject: [PATCH] Reduce entity allocations
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 35f283889d29c2799714f03ad090a8b8746c32ef..69e0e0cef3c695e056ac1656fc55ebf6e5fc175b 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -345,6 +345,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
// Paper end
// Pufferfish start
public int activatedPriority = gg.pufferfish.pufferfish.PufferfishConfig.maximumActivationPrio; // golf score
+ public final BlockPos.MutableBlockPos cachedBlockPos = new BlockPos.MutableBlockPos(); // used where needed
// Pufferfish end
public float getBukkitYaw() {
diff --git a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
index 718b3fbf5b92d9979de7775e1d40420bb7cf439b..0f680904431e9e37fab17782e9a6e83e5c8faf6a 100644
--- a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
+++ b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
@@ -23,6 +23,7 @@ public class AttributeMap {
private final Set<AttributeInstance> dirtyAttributes = Sets.newHashSet();
private final AttributeSupplier supplier;
private final net.minecraft.world.entity.LivingEntity entity; // Purpur
+ private final java.util.function.Function<Attribute, AttributeInstance> createInstance; // Pufferfish
public AttributeMap(AttributeSupplier defaultAttributes) {
// Purpur start
@@ -32,6 +33,7 @@ public class AttributeMap {
this.entity = entity;
// Purpur end
this.supplier = defaultAttributes;
+ this.createInstance = attribute -> this.supplier.createInstance(this::onAttributeModified, attribute); // Pufferfish
}
private void onAttributeModified(AttributeInstance instance) {
@@ -51,11 +53,10 @@ public class AttributeMap {
}).collect(Collectors.toList());
}
+
@Nullable
public AttributeInstance getInstance(Attribute attribute) {
- return this.attributes.computeIfAbsent(attribute, (attributex) -> {
- return this.supplier.createInstance(this::onAttributeModified, attributex);
- });
+ return this.attributes.computeIfAbsent(attribute, this.createInstance); // Pufferfish - cache lambda, as for some reason java allocates it anyways
}
public boolean hasAttribute(Attribute attribute) {