From 42d62ab0ea91785383b5cd0f021e5426a1f93fe0 Mon Sep 17 00:00:00 2001 From: Jonathing Date: Tue, 24 Dec 2024 01:34:26 -0500 Subject: [PATCH] Add optional fix of use item duration, disabled by default (#10243) --- .../minecraft/world/entity/LivingEntity.java.patch | 2 +- .../java/net/minecraftforge/common/ForgeConfig.java | 11 +++++++++++ .../event/entity/living/LivingEntityUseItemEvent.java | 2 +- src/main/resources/assets/forge/lang/en_us.json | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch b/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch index d443c0da4d..a28c03e57b 100644 --- a/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/LivingEntity.java.patch @@ -469,7 +469,7 @@ ItemStack itemstack = this.m_21120_(p_21159_); if (!itemstack.m_41619_() && !this.m_6117_()) { + int duration = net.minecraftforge.event.ForgeEventFactory.onItemUseStart(this, itemstack, itemstack.m_41779_()); -+ if (duration <= 0) return; ++ if (duration < net.minecraftforge.common.ForgeConfig.SERVER.getUseItemDuration()) return; this.f_20935_ = itemstack; - this.f_20936_ = itemstack.m_41779_(); + this.f_20936_ = duration; diff --git a/src/main/java/net/minecraftforge/common/ForgeConfig.java b/src/main/java/net/minecraftforge/common/ForgeConfig.java index ca37eb50c8..5bf753b423 100644 --- a/src/main/java/net/minecraftforge/common/ForgeConfig.java +++ b/src/main/java/net/minecraftforge/common/ForgeConfig.java @@ -35,6 +35,8 @@ public class ForgeConfig { public final ConfigValue permissionHandler; + public final BooleanValue useItemWithDurationZero; + Server(ForgeConfigSpec.Builder builder) { builder.comment("Server configuration settings") .push("server"); @@ -89,8 +91,17 @@ public class ForgeConfig { .translation("forge.configgui.permissionHandler") .define("permissionHandler", "forge:default_handler"); + useItemWithDurationZero = builder + .comment("Set this to true to enable living entities to use items with durations of 0. Fixes being able to use Eyes of Ender repeatedly by holding down the use button. Disabled by default as it could change interactions with items of existing mods.") + .translation("forge.configgui.useItemWithDurationZero") + .define("useItemWithDurationZero", false); + builder.pop(); } + + public final int getUseItemDuration() { + return useItemWithDurationZero.get() ? 0 : 1; + } } /** diff --git a/src/main/java/net/minecraftforge/event/entity/living/LivingEntityUseItemEvent.java b/src/main/java/net/minecraftforge/event/entity/living/LivingEntityUseItemEvent.java index cb07abeede..980f77d64d 100644 --- a/src/main/java/net/minecraftforge/event/entity/living/LivingEntityUseItemEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/living/LivingEntityUseItemEvent.java @@ -47,7 +47,7 @@ public class LivingEntityUseItemEvent extends LivingEvent * Drinking Potions/Milk * Guarding with a sword * - * Cancel the event, or set the duration or {@literal <=} 0 to prevent it from processing. + * Cancel the event, or set the duration or {@literal <} 0 to prevent it from processing. * */ @Cancelable diff --git a/src/main/resources/assets/forge/lang/en_us.json b/src/main/resources/assets/forge/lang/en_us.json index c943eca847..72da8bfcca 100644 --- a/src/main/resources/assets/forge/lang/en_us.json +++ b/src/main/resources/assets/forge/lang/en_us.json @@ -169,6 +169,8 @@ "forge.configgui.skipEmptyShapelessCheck": "Skip checking for empty ingredients in Shapeless Recipe Deserialization", "forge.configgui.forceSystemNanoTime.tooltip": "Force the use of System.nanoTime instead of glfwGetTime as the main client Time provider.", "forge.configgui.forceSystemNanoTime": "Force System.nanoTime", + "forge.configgui.useItemWithDurationZero": "Allow Use Item with Duration of 0", + "forge.configgui.useItemWithDurationZero.tooltip": "Set this to true to enable living entities to use items with durations of 0. Fixes being able to use Eyes of Ender repeatedly by holding down the use button. Disabled by default as it could change interactions with items of existing mods.", "forge.configgui.zoomInMissingModelTextInGui.tooltip": "Toggle off to make missing model text in the gui fit inside the slot.", "forge.configgui.zoomInMissingModelTextInGui": "Zoom in Missing model text in the GUI",