Skip to content

Commit

Permalink
Avoid anvil too expensive (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 22, 2023
1 parent aff95ee commit 6a67554
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
9 changes: 7 additions & 2 deletions patches/server/0004-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ index 35d2da9d91dcdd89de7c0f4af028fd182376ea8d..d73482fb1e71fe2951e96ae0593de268
.withRequiredArg()
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..63bbea2329202aef8f0d08c74d950276ccb4344c
index 0000000000000000000000000000000000000000..dd6c1d304914b9387da4b741707878ee1fe38935
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -0,0 +1,941 @@
@@ -0,0 +1,946 @@
+package top.leavesmc.leaves;
+
+import com.destroystokyo.paper.util.SneakyThrow;
Expand Down Expand Up @@ -898,6 +898,11 @@ index 0000000000000000000000000000000000000000..63bbea2329202aef8f0d08c74d950276
+ villagersDontReleaseMemoryFix = getBoolean("settings.performance.fix-villagers-dont-release-memory", villagersDontReleaseMemoryFix);
+ }
+
+ public static boolean avoidAnvilTooExpensive = false;
+ private static void avoidAnvilTooExpensive() {
+ avoidAnvilTooExpensive = getBoolean("settings.modify.avoid-anvil-too-expensive", avoidAnvilTooExpensive);
+ }
+
+ public static final class WorldConfig {
+
+ public final String worldName;
Expand Down
19 changes: 15 additions & 4 deletions patches/server/0070-Leaves-carpet-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ index 6c19d9b64830efe4b9d6f17d8ca92f88ad3475d5..fb6810289ac855e622d3970101f27b21
final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();

diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
index 5db4a3687f05bdc1ab3da0e74536dc8f72c7c1b5..41ecc020ee1277dc6af126a3531901567ce8217b 100644
index 51dd0f1a994ab25f1b6b6709ef0520d2a54749e8..fe9d97eedada84817f6341358ecd8cf69ab7cc01 100644
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -15,6 +15,8 @@ import top.leavesmc.leaves.bot.agent.Actions;
Expand All @@ -45,10 +45,10 @@ index 5db4a3687f05bdc1ab3da0e74536dc8f72c7c1b5..41ecc020ee1277dc6af126a353190156
import java.lang.reflect.InvocationTargetException;
diff --git a/src/main/java/top/leavesmc/leaves/protocol/CarpetServerProtocol.java b/src/main/java/top/leavesmc/leaves/protocol/CarpetServerProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..afcbb7b8c9a6e933665500b068fe7c9111658df7
index 0000000000000000000000000000000000000000..9c13a3b7d2321dc59beec6e220790d1df0728c16
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/protocol/CarpetServerProtocol.java
@@ -0,0 +1,85 @@
@@ -0,0 +1,96 @@
+package top.leavesmc.leaves.protocol;
+
+import io.netty.buffer.Unpooled;
Expand Down Expand Up @@ -106,7 +106,7 @@ index 0000000000000000000000000000000000000000..afcbb7b8c9a6e933665500b068fe7c91
+
+ public static class CarpetRules {
+
+ public static Map<String, CarpetRule> rules = new HashMap<>();
+ private static final Map<String, CarpetRule> rules = new HashMap<>();
+
+ @NotNull
+ public static FriendlyByteBuf buildBuf() {
Expand All @@ -122,9 +122,20 @@ index 0000000000000000000000000000000000000000..afcbb7b8c9a6e933665500b068fe7c91
+
+ return buf;
+ }
+
+ public static void register(CarpetRule rule) {
+ rules.put(rule.name, rule);
+ }
+ }
+
+ public record CarpetRule(String identifier, String name, String value) {
+
+ @NotNull
+ @Contract("_, _, _ -> new")
+ public static CarpetRule of(String identifier, String name, boolean value) {
+ return new CarpetRule(identifier, name, Boolean.toString(value));
+ }
+
+ public void writeNBT(@NotNull CompoundTag rules) {
+ CompoundTag rule = new CompoundTag();
+ rule.putString("Value", value);
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0071-Creative-fly-no-clip.patch
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ index d9baa85962236c42219cf09d4f3129be93ff069c..c1bd06fbc2c5683888f7264c35c25feb

public boolean isSpawning() {
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
index 41ecc020ee1277dc6af126a3531901567ce8217b..6c425c2aa1c722bf66aed452aefa4bf5dc96c027 100644
index fe9d97eedada84817f6341358ecd8cf69ab7cc01..bda0bb1eac3dadf532c4a5daa500762ef9e00d72 100644
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -596,6 +596,7 @@ public final class LeavesConfig {
}

public static void registerCarpetRules() {
+ CarpetRules.rules.put("creativeNoClip", new CarpetRule("carpet", "creativeNoClip", Boolean.toString(creativeNoClip)));
+ CarpetRules.register(CarpetRule.of("carpet", "creativeNoClip", creativeNoClip));
}

public static boolean creativeNoClip = false;
31 changes: 31 additions & 0 deletions patches/server/0112-Avoid-anvil-too-expensive.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Sat, 22 Jul 2023 14:16:25 +0800
Subject: [PATCH] Avoid anvil too expensive


diff --git a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
index e0c3a4ba27e21c3692e601acd0af60873bcbb84c..b9fcf49ed88c62265d9aa8926c1228b96bf314b6 100644
--- a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
@@ -293,7 +293,7 @@ public class AnvilMenu extends ItemCombinerMenu {
this.cost.set(this.maximumRepairCost - 1); // CraftBukkit
}

- if (this.cost.get() >= this.maximumRepairCost && !this.player.getAbilities().instabuild) { // CraftBukkit
+ if (this.cost.get() >= this.maximumRepairCost && (!top.leavesmc.leaves.LeavesConfig.avoidAnvilTooExpensive || this.cost.get() == DEFAULT_DENIED_COST) && !this.player.getAbilities().instabuild) { // CraftBukkit // Leaves - avoid anvil too expensive
itemstack1 = ItemStack.EMPTY;
}

diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
index 071360899dc841f386ba536503e8b95c2b2a5214..ad0c06c1daba983dfd2660c6538dba0073f813d4 100644
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -602,6 +602,7 @@ public final class LeavesConfig {

public static void registerCarpetRules() {
CarpetRules.register(CarpetRule.of("carpet", "creativeNoClip", creativeNoClip));
+ CarpetRules.register(CarpetRule.of("pca", "avoidAnvilTooExpensive", avoidAnvilTooExpensive));
}

public static boolean creativeNoClip = false;

0 comments on commit 6a67554

Please sign in to comment.