9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00

[ci skip] Remove some unapplied patches

The implementations of these patches are not appropriated or useless
This commit is contained in:
Dreeam
2024-10-19 02:43:54 -04:00
parent 97323064a9
commit de8900295f
2 changed files with 0 additions and 243 deletions

View File

@@ -1,150 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: rafaelflromao <12960698+rafaelflromao@users.noreply.github.com>
Date: Sat, 24 Jun 2023 13:46:45 +0100
Subject: [PATCH] Distribute workload for villager's AI
diff --git a/src/main/java/dev/etil/mirai/ai/WorkloadDistribution.java b/src/main/java/dev/etil/mirai/ai/WorkloadDistribution.java
new file mode 100644
index 0000000000000000000000000000000000000000..8cc57b5ce8f8f8e6e73880e992794e2bbca5f193
--- /dev/null
+++ b/src/main/java/dev/etil/mirai/ai/WorkloadDistribution.java
@@ -0,0 +1,39 @@
+package dev.etil.mirai.ai;
+
+import java.util.ArrayDeque;
+import java.util.Objects;
+
+public class WorkloadDistribution {
+
+ private final long taskTime;
+ private final long maxTasks;
+
+ private final long tickDelay;
+
+ private long desiredStart = System.nanoTime();
+ public WorkloadDistribution(long taskTime, long maxTasks, long tickDelay) {
+ this.taskTime = taskTime;
+ this.maxTasks = maxTasks;
+ this.tickDelay = tickDelay;
+ }
+ ArrayDeque<Runnable> tasks = new ArrayDeque<>();
+
+ public void addTask(Runnable task) {
+ tasks.offer(task);
+ if(tasks.size() > maxTasks) tasks.poll();
+ }
+
+ public void tick() {
+ if(tasks.isEmpty()) return;
+ if(System.nanoTime() < desiredStart) return;
+ long initialSize = tasks.size();
+ long start = System.nanoTime();
+ while(!tasks.isEmpty() && System.nanoTime() - start < taskTime) {
+ Objects.requireNonNull(tasks.poll()).run();
+ }
+ desiredStart = System.nanoTime() + tickDelay;
+ // System.out.println("Took " + (System.nanoTime() - start) + "ns to run " + (initialSize - tasks.size()) + " tasks");
+ }
+
+
+}
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
index 9cdfe4c9d4487082c9b3577ff572675d9b8fc9b9..a2f7cdf08cfaf46204eca47fb39e08bd47049462 100644
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
@@ -14,6 +14,7 @@ import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.MapLike;
import com.mojang.serialization.RecordBuilder;
+import dev.etil.mirai.ai.WorkloadDistribution;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.Collection;
import java.util.List;
@@ -43,6 +44,7 @@ public class Brain<E extends LivingEntity> {
static final Logger LOGGER = LogUtils.getLogger();
private final Supplier<Codec<Brain<E>>> codec;
private static final int SCHEDULE_UPDATE_DELAY = 20;
+ private final WorkloadDistribution workloadDistribution = new WorkloadDistribution(20000L, 500L, 10000L);
private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newHashMap();
private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
@@ -384,29 +386,34 @@ public class Brain<E extends LivingEntity> {
}
public void tick(ServerLevel world, E entity) {
- this.forgetOutdatedMemories();
- this.tickSensors(world, entity);
- this.startEachNonRunningBehavior(world, entity);
- this.tickEachRunningBehavior(world, entity);
+ // Mirai Start - Distribute workload
+ this.forgetOutdatedMemories();
+ this.tickSensors(world, entity);
+ this.startEachNonRunningBehavior(world, entity);
+ this.tickEachRunningBehavior(world, entity);
+ workloadDistribution.tick();
+ // Mirai End
}
private void tickSensors(ServerLevel world, E entity) {
for(Sensor<? super E> sensor : this.sensors.values()) {
- sensor.tick(world, entity);
+ workloadDistribution.addTask(() -> sensor.tick(world, entity));
}
}
private void forgetOutdatedMemories() {
for(Map.Entry<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> entry : this.memories.entrySet()) {
- if (entry.getValue().isPresent()) {
- ExpirableValue<?> expirableValue = entry.getValue().get();
- if (expirableValue.hasExpired()) {
- this.eraseMemory(entry.getKey());
- }
+ workloadDistribution.addTask(() -> {
+ if (entry.getValue().isPresent()) {
+ ExpirableValue<?> expirableValue = entry.getValue().get();
+ if (expirableValue.hasExpired()) {
+ this.eraseMemory(entry.getKey());
+ }
- expirableValue.tick();
- }
+ expirableValue.tick();
+ }
+ });
}
}
@@ -425,14 +432,16 @@ public class Brain<E extends LivingEntity> {
for(Map<Activity, Set<BehaviorControl<? super E>>> map : this.availableBehaviorsByPriority.values()) {
for(Map.Entry<Activity, Set<BehaviorControl<? super E>>> entry : map.entrySet()) {
- Activity activity = entry.getKey();
- if (this.activeActivities.contains(activity)) {
- for(BehaviorControl<? super E> behaviorControl : entry.getValue()) {
- if (behaviorControl.getStatus() == Behavior.Status.STOPPED) {
- behaviorControl.tryStart(world, entity, l);
+ workloadDistribution.addTask(() -> {
+ Activity activity = entry.getKey();
+ if (this.activeActivities.contains(activity)) {
+ for(BehaviorControl<? super E> behaviorControl : entry.getValue()) {
+ if (behaviorControl.getStatus() == Behavior.Status.STOPPED) {
+ behaviorControl.tryStart(world, entity, l);
+ }
}
}
- }
+ });
}
}
@@ -442,7 +451,7 @@ public class Brain<E extends LivingEntity> {
long l = world.getGameTime();
for(BehaviorControl<? super E> behaviorControl : this.getRunningBehaviors()) {
- behaviorControl.tickOrStop(world, entity, l);
+ workloadDistribution.addTask(() -> behaviorControl.tickOrStop(world, entity, l));
}
}

View File

@@ -1,93 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Mon, 15 Jan 2024 23:02:33 -0500
Subject: [PATCH] Optimize item updates in fluid check
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..3aa0ad4fad1b44817f484cce13642ed7d3f3a4c6 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -864,9 +864,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
this.wasInPowderSnow = this.isInPowderSnow;
this.isInPowderSnow = false;
- this.updateInWaterStateAndDoFluidPushing();
- this.updateFluidOnEyes();
- this.updateSwimming();
+ // Leaf start - Optimize item updates in fluid check
+ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled && this instanceof ItemEntity) {
+ ItemEntity.checkInLiquid(this);
+ if (ItemEntity.isInLiquid) {
+ this.updateInWaterStateAndDoFluidPushing();
+ this.updateFluidOnEyes();
+ this.updateSwimming();
+ }
+ } else {
+ this.updateInWaterStateAndDoFluidPushing();
+ this.updateFluidOnEyes();
+ this.updateSwimming();
+ }
+ // Leaf end
if (this.level().isClientSide) {
this.clearFire();
} else if (this.remainingFireTicks > 0) {
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index 7fce419490b39409f876914ce306f77d11e659b7..2e15896df321c076cf1c3ef78e67cea9188e9ddb 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -130,6 +130,15 @@ public class ItemEntity extends Entity implements TraceableEntity {
this.getEntityData().define(ItemEntity.DATA_ITEM, ItemStack.EMPTY);
}
+ // Leaf start - Optimize item updates in fluid check
+ public static boolean isInLiquid = false;
+ public static void checkInLiquid(Entity e) {
+ if (e.tickCount % org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateInterval == 0) {
+ isInLiquid = e.isInLiquid();
+ }
+ }
+ // Leaf end
+
@Override
public void tick() {
if (this.getItem().isEmpty()) {
@@ -202,7 +211,14 @@ public class ItemEntity extends Entity implements TraceableEntity {
}
// CraftBukkit end */
- this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
+ // Leaf - Optimize item updates in fluid check
+ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled) {
+ checkInLiquid(this);
+ if (isInLiquid) this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
+ } else {
+ this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
+ }
+ // Leaf end
if (!this.level().isClientSide) {
double d0 = this.getDeltaMovement().subtract(vec3d).lengthSqr();
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
index 53bde816ca9bf8b704fb2e9794de260a9eba402f..82e51da38a66826feb58fd28b39858ef91ddf7ab 100644
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
@@ -202,6 +202,8 @@ public class LeafConfig {
public static int asyncPathfindingMaxThreads = 0;
public static int asyncPathfindingKeepalive = 60;
public static boolean cacheMinecartCollision = false;
+ public static boolean optimizeItemsInFluidUpdateEnabled = false;
+ public static int optimizeItemsInFluidUpdateInterval = 20;
private static void performance() {
boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning,
"Whether or not asynchronous mob spawning should be enabled.",
@@ -265,6 +267,9 @@ public class LeafConfig {
cacheMinecartCollision = getBoolean("performance.cache-minecart-collision", cacheMinecartCollision,
"Cache the minecart collision result to prevent massive stacked minecart lag the server.",
"The known issue: entity can't enter the minecart after enabling this!");
+ optimizeItemsInFluidUpdateEnabled = getBoolean("performance.optimize-items-in-fluid-update.enabled", optimizeItemsInFluidUpdateEnabled);
+ optimizeItemsInFluidUpdateInterval = getInt("performance.optimize-items-in-fluid-update.interval", optimizeItemsInFluidUpdateInterval);
+
}
public static boolean jadeProtocol = false;