From 8e639e1ebe575db5f3cf735911b31d66e4c17d3f Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Sat, 6 Jul 2024 20:56:39 +0200 Subject: [PATCH] Hide recipe books from various screens in pre 1.13 versions --- .../fixes/minecraft/screen/MixinScreen.java | 20 +++++++++++++++++++ .../screen/settings/SettingsScreen.java | 1 - .../settings/impl/VisualSettings.java | 2 ++ .../assets/viafabricplus/lang/en_us.json | 2 ++ .../resources/viafabricplus.accesswidener | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/screen/MixinScreen.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/screen/MixinScreen.java index 42b5af10..e53b9bfb 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/screen/MixinScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/screen/MixinScreen.java @@ -21,8 +21,15 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; +import de.florianmichael.viafabricplus.settings.impl.VisualSettings; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.FurnaceScreen; +import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; +import net.minecraft.client.gui.widget.TexturedButtonWidget; import net.minecraft.text.Style; import net.minecraft.util.StringHelper; import org.jetbrains.annotations.Nullable; @@ -47,4 +54,17 @@ public abstract class MixinScreen { } } + @Inject(method = "addDrawableChild", at = @At("HEAD"), cancellable = true) + public void removeRecipeBook(T drawableElement, CallbackInfoReturnable cir) { + if (drawableElement instanceof TexturedButtonWidget button && button.textures == RecipeBookWidget.BUTTON_TEXTURES) { + final boolean furnace = ((Screen) (Object) this) instanceof FurnaceScreen; + + if (VisualSettings.global().hideFurnaceRecipeBook.isEnabled() && furnace) { + cir.setReturnValue(drawableElement); + } else if (VisualSettings.global().hideCraftingRecipeBook.isEnabled() && !furnace) { + cir.setReturnValue(drawableElement); + } + } + } + } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java index 0f0842b4..3b745459 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java @@ -46,7 +46,6 @@ public class SettingsScreen extends VFPScreen { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - this.renderBackground(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); this.renderTitle(context); diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java index 8f0ff6d4..9521b1fe 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java @@ -42,9 +42,11 @@ public class VisualSettings extends SettingGroup { // 1.13 -> 1.12.2 public final VersionedBooleanSetting replacePetrifiedOakSlab = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.replace_petrified_oak_slab"), VersionRange.of(LegacyProtocolVersion.r1_3_1tor1_3_2, ProtocolVersion.v1_12_2)); public final VersionedBooleanSetting changeFontRendererBehaviour = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.change_font_renderer_behaviour"), VersionRange.andOlder(ProtocolVersion.v1_12_2)); + public final VersionedBooleanSetting hideFurnaceRecipeBook = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.hide_furnace_recipe_book"), VersionRange.andOlder(ProtocolVersion.v1_12_2)); // 1.12 -> 1.11.1 public final VersionedBooleanSetting sidewaysBackwardsRunning = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.sideways_backwards_walking"), VersionRange.andOlder(ProtocolVersion.v1_11_1)); + public final VersionedBooleanSetting hideCraftingRecipeBook = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.hide_crafting_recipe_book"), VersionRange.andOlder(ProtocolVersion.v1_11_1)); // 1.9 -> 1.8.x public final VersionedBooleanSetting emulateArmorHud = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.emulate_armor_hud"), VersionRange.andOlder(ProtocolVersion.v1_8)); diff --git a/src/main/resources/assets/viafabricplus/lang/en_us.json b/src/main/resources/assets/viafabricplus/lang/en_us.json index 43abd9a0..5bc259eb 100644 --- a/src/main/resources/assets/viafabricplus/lang/en_us.json +++ b/src/main/resources/assets/viafabricplus/lang/en_us.json @@ -87,6 +87,8 @@ "visual_settings.viafabricplus.disable_server_pinging": "Disable server pinging", "visual_settings.viafabricplus.sideways_backwards_walking": "Sideways backwards walking", "visual_settings.viafabricplus.enable_legacy_tablist": "Enable legacy tablist", + "visual_settings.viafabricplus.hide_furnace_recipe_book": "Hide furnace recipe book", + "visual_settings.viafabricplus.hide_crafting_recipe_book": "Hide crafting recipe book", "bedrock.viafabricplus.login": "Your browser should have opened.\nClosing this screen will cancel the process!", "authentication.viafabricplus.failed_to_verify_session": "ViaFabricPlus couldn't verify your session! Please log in to an account or disable the BetaCraft authentication in the ViaFabricPlus Settings", diff --git a/src/main/resources/viafabricplus.accesswidener b/src/main/resources/viafabricplus.accesswidener index 8f94aa37..9878f778 100644 --- a/src/main/resources/viafabricplus.accesswidener +++ b/src/main/resources/viafabricplus.accesswidener @@ -16,6 +16,7 @@ accessible field net/minecraft/client/font/FontStorage glyphCache Lnet/minecraft accessible field net/minecraft/entity/EntityType dimensions Lnet/minecraft/entity/EntityDimensions; accessible field net/minecraft/block/AbstractBlock velocityMultiplier F accessible field net/minecraft/client/gui/screen/world/WorldIcon UNKNOWN_SERVER_ID Lnet/minecraft/util/Identifier; +accessible field net/minecraft/client/gui/widget/TexturedButtonWidget textures Lnet/minecraft/client/gui/screen/ButtonTextures; accessible method net/minecraft/screen/GenericContainerScreenHandler (Lnet/minecraft/screen/ScreenHandlerType;ILnet/minecraft/entity/player/PlayerInventory;I)V accessible method net/minecraft/client/font/FontStorage$GlyphPair (Lnet/minecraft/client/font/Glyph;Lnet/minecraft/client/font/Glyph;)V