mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-03 22:26:12 +00:00
Leaves config hot modify (#126)
This commit is contained in:
55
patches/server/0030-Reduce-entity-allocations.patch
Normal file
55
patches/server/0030-Reduce-entity-allocations.patch
Normal file
@@ -0,0 +1,55 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
||||
Date: Wed, 17 Aug 2022 10:48:18 +0800
|
||||
Subject: [PATCH] Reduce entity allocations
|
||||
|
||||
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
index b989029d7425cf410698ff477a3622b4c629ada3..79b2831322b8312448c89b5276af40d1efa880d2 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
@@ -439,6 +439,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
||||
return this.originWorld;
|
||||
}
|
||||
// Paper end
|
||||
+ // public final BlockPos.MutableBlockPos cachedBlockPos = new BlockPos.MutableBlockPos(); // Leaves - used where needed ?
|
||||
+
|
||||
public float getBukkitYaw() {
|
||||
return this.yRot;
|
||||
}
|
||||
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 7204b973c3ad9239e82355513f6d538107102e48..4ee998ae0406d20e3106b7e51911d86313a2e2f8 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,9 +23,11 @@ public class AttributeMap {
|
||||
private final Map<Attribute, AttributeInstance> attributes = Maps.newHashMap();
|
||||
private final Set<AttributeInstance> dirtyAttributes = Sets.newHashSet();
|
||||
private final AttributeSupplier supplier;
|
||||
+ private final java.util.function.Function<Attribute, AttributeInstance> createInstance; // Leaves - reduce entity allocations
|
||||
|
||||
public AttributeMap(AttributeSupplier defaultAttributes) {
|
||||
this.supplier = defaultAttributes;
|
||||
+ this.createInstance = attribute -> this.supplier.createInstance(this::onAttributeModified, attribute);
|
||||
}
|
||||
|
||||
private void onAttributeModified(AttributeInstance instance) {
|
||||
@@ -47,9 +49,15 @@ public class AttributeMap {
|
||||
|
||||
@Nullable
|
||||
public AttributeInstance getInstance(Attribute attribute) {
|
||||
- return this.attributes.computeIfAbsent(attribute, (attributex) -> {
|
||||
- return this.supplier.createInstance(this::onAttributeModified, attributex);
|
||||
- });
|
||||
+ // Leaves start - cache lambda, as for some reason java allocates it anyways
|
||||
+ if (top.leavesmc.leaves.LeavesConfig.reduceEntityAllocations) {
|
||||
+ return this.attributes.computeIfAbsent(attribute, this.createInstance);
|
||||
+ } else {
|
||||
+ return this.attributes.computeIfAbsent(attribute, (attributex) -> {
|
||||
+ return this.supplier.createInstance(this::onAttributeModified, attributex);
|
||||
+ });
|
||||
+ }
|
||||
+ // Leaves end - cache lambda, as for some reason java allocates it anyways
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Reference in New Issue
Block a user