Skip to content

Commit 5f3575a

Browse files
committed
add recipe viewer toggle
1 parent e85734e commit 5f3575a

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

src/main/java/turing/tmb/TMB.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.fabricmc.api.ModInitializer;
44
import net.fabricmc.loader.api.FabricLoader;
55
import net.minecraft.client.Minecraft;
6+
import net.minecraft.client.gui.options.components.BooleanOptionComponent;
67
import net.minecraft.client.gui.options.components.KeyBindingComponent;
78
import net.minecraft.client.gui.options.components.OptionsCategory;
89
import net.minecraft.client.gui.options.data.OptionsPages;
@@ -45,12 +46,16 @@ public void onGatherPlugins(boolean isReload) {
4546
}
4647

4748
public static void onClientStart() {
49+
GameSettings settings = Minecraft.getMinecraft().gameSettings;
4850
OptionsCategory category = new OptionsCategory("gui.options.page.controls.category.tmb");
49-
category.withComponent(new KeyBindingComponent(((IKeybinds) Minecraft.getMinecraft().gameSettings).toomanyblocks$getKeyHideTMB()));
51+
category.withComponent(new KeyBindingComponent(((IKeybinds) settings).toomanyblocks$getKeyHideTMB()));
5052
OptionsPages.CONTROLS.withComponent(category);
51-
GameSettings settings = Minecraft.getMinecraft().gameSettings;
53+
OptionsCategory category1 = new OptionsCategory("gui.options.page.general.category.tmb");
54+
category1.withComponent(new BooleanOptionComponent(((IKeybinds) settings).toomanyblocks$getIsRecipeViewEnabled()));
55+
OptionsPages.GENERAL.withComponent(category1);
5256
settings.getAllOptions().add(((IKeybinds) settings).toomanyblocks$getIsTMBHidden());
5357
settings.getAllOptions().add(((IKeybinds) settings).toomanyblocks$getLastTMBSearch());
58+
settings.getAllOptions().add(((IKeybinds) settings).toomanyblocks$getIsRecipeViewEnabled());
5459
loadTMB();
5560
runtime.index.gatherIngredients();
5661
}

src/main/java/turing/tmb/client/TMBRenderer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class TMBRenderer {
3535
public static int currentPage = 0;
3636
public static int pages = 0;
3737
public static boolean show = true;
38+
public static boolean enabledRecipes = true;
3839
protected static boolean initialized;
3940
protected static final ButtonElement leftButton = new ButtonElement(0, 0, 0, 16, 16, "<");
4041
protected static final ButtonElement rightButton = new ButtonElement(1, 0, 0, 16, 16, ">");
@@ -47,6 +48,7 @@ public static void init(Minecraft mc) {
4748
tooltip = new TooltipElement(mc);
4849
search = new TextFieldElement(null, Minecraft.getMinecraft().font, 0, 0, 120, 20, ((IKeybinds) Minecraft.getMinecraft().gameSettings).toomanyblocks$getLastTMBSearch().value, "Search...");
4950
show = !((IKeybinds) Minecraft.getMinecraft().gameSettings).toomanyblocks$getIsTMBHidden().value;
51+
enabledRecipes = ((IKeybinds) Minecraft.getMinecraft().gameSettings).toomanyblocks$getIsRecipeViewEnabled().value;
5052
}
5153

5254
public static void renderHeader(int mouseX, int mouseY, int width, int height, Minecraft mc, float pt, @Nullable IGuiProperties properties) {
@@ -188,10 +190,12 @@ public static void renderItems(int mouseX, int mouseY, int width, int height, Mi
188190
GL11.glPopMatrix();
189191
}
190192

191-
if (mc.gameSettings.keyShowRecipe.isPressed()) {
192-
runtime.showRecipe(hoveredItem, RecipeIngredientRole.OUTPUT);
193-
} else if (mc.gameSettings.keyShowUsage.isPressed()) {
194-
runtime.showRecipe(hoveredItem, RecipeIngredientRole.INPUT);
193+
if (enabledRecipes) {
194+
if (mc.gameSettings.keyShowRecipe.isPressed()) {
195+
runtime.showRecipe(hoveredItem, RecipeIngredientRole.OUTPUT);
196+
} else if (mc.gameSettings.keyShowUsage.isPressed()) {
197+
runtime.showRecipe(hoveredItem, RecipeIngredientRole.INPUT);
198+
}
195199
}
196200
}
197201
}

src/main/java/turing/tmb/mixin/client/GameSettingsMixin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class GameSettingsMixin implements IKeybinds {
2222
@Unique
2323
public OptionBoolean isTMBHidden = new OptionBoolean((GameSettings) ((Object) this), "isTMBHidden", false);
2424

25+
@Unique
26+
public OptionBoolean isRecipeViewEnabled = new OptionBoolean((GameSettings) ((Object) this), "isRecipeViewEnabled", true);
27+
2528
@Unique
2629
public OptionString lastTMBSearch = new OptionString((GameSettings) ((Object) this), "lastTMBSearch", "");
2730

@@ -35,6 +38,11 @@ public class GameSettingsMixin implements IKeybinds {
3538
return isTMBHidden;
3639
}
3740

41+
@Override
42+
public OptionBoolean toomanyblocks$getIsRecipeViewEnabled() {
43+
return isRecipeViewEnabled;
44+
}
45+
3846
@Override
3947
public OptionString toomanyblocks$getLastTMBSearch() {
4048
return lastTMBSearch;

src/main/java/turing/tmb/mixin/client/ScreenContainerAbstractMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void keyPressed(char eventCharacter, int eventKey, int mx, int my, Callba
4848
if (TMBRenderer.search.isFocused) {
4949
ci.cancel();
5050
}
51-
if (TMB.shouldReplaceGuidebook) {
51+
if (TMB.shouldReplaceGuidebook && TMBRenderer.enabledRecipes) {
5252
if (eventKey == mc.gameSettings.keyShowUsage.getKeyCode()) {
5353
ci.cancel();
5454
int slotId = getSlotId(mx, my);

src/main/java/turing/tmb/util/IKeybinds.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ public interface IKeybinds {
99

1010
OptionBoolean toomanyblocks$getIsTMBHidden();
1111

12+
OptionBoolean toomanyblocks$getIsRecipeViewEnabled();
13+
1214
OptionString toomanyblocks$getLastTMBSearch();
1315
}

src/main/resources/lang/tmb/en_US.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ tmb.tooltip.itemGroup=Accepts Any %s
66
tmb.tooltip.allCategories=Click to see all categories
77

88
gui.options.page.controls.category.tmb=Too Many Blocks
9+
gui.options.page.general.category.tmb=Too Many Blocks
910
key.tmb.hide=Hide TMB
11+
options.isRecipeViewEnabled=Enable Recipe Viewing
12+
options.isTMBHidden=Hide TMB

0 commit comments

Comments
 (0)