Skip to content

Commit

Permalink
minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaKR93 committed Oct 26, 2024
1 parent 90d412b commit 393e079
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions patches/server/0042-Optimize-advancement-criteria-triggering.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: AlphaKR93 <[email protected]>
Date: Sun, 27 Oct 2024 00:16:25 +0900
Subject: [PATCH] Optimize advancement criteria triggering

Based on Achievements Optimizer
Copyright (C) 2024 bigenergy, Licensed under MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


diff --git a/src/main/java/net/minecraft/advancements/critereon/InventoryChangeTrigger.java b/src/main/java/net/minecraft/advancements/critereon/InventoryChangeTrigger.java
index ebbad97920df3d1645637e646a98e16cb04d361e..a149c949a042e1d1e504d9f5ce0bfa6df92db2fc 100644
--- a/src/main/java/net/minecraft/advancements/critereon/InventoryChangeTrigger.java
+++ b/src/main/java/net/minecraft/advancements/critereon/InventoryChangeTrigger.java
@@ -22,7 +22,21 @@ public class InventoryChangeTrigger extends SimpleCriterionTrigger<InventoryChan
return InventoryChangeTrigger.TriggerInstance.CODEC;
}

+ // Plazma start - Optimize advancement criteria triggering
+ public static int idleTick;
+ private int ticksSkipped;
+
+ private boolean shouldTick() {
+ if (++this.ticksSkipped <= idleTick) return false;
+
+ this.ticksSkipped = 0;
+ return true;
+ }
+ // Plazma end - Optimize advancement criteria triggering
+
public void trigger(ServerPlayer player, Inventory inventory, ItemStack stack) {
+ if (idleTick > 0 && !this.shouldTick()) return; // Plazma - Optimize advancement criteria triggering
+
int i = 0;
int j = 0;
int k = 0;
diff --git a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
index 9de9b3f2148216df41258d503fa1de896cca4771..e6352488b0fcb0f0332d3d82614930e9c94eb594 100644
--- a/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
+++ b/src/main/java/org/plazmamc/plazma/configurations/GlobalConfiguration.java
@@ -134,4 +134,17 @@ public class GlobalConfiguration extends ConfigurationPart {

}

+ public Advancements advancements;
+ public class Advancements extends ConfigurationPart {
+
+ int criteriaTriggerIdleTick = OPTIMIZE ? 5 : 0;
+ public boolean optimizeItemPredicate = OPTIMIZE;
+
+ @PostProcess
+ void post() {
+ net.minecraft.advancements.critereon.InventoryChangeTrigger.idleTick = this.criteriaTriggerIdleTick;
+ }
+
+ }
+
}

0 comments on commit 393e079

Please sign in to comment.