Skip to content

Commit 3b5d6d2

Browse files
committed
Incomplete recipe filling functionality.
1 parent 937107f commit 3b5d6d2

8 files changed

Lines changed: 55 additions & 3 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ mod_menu_version=3.0.0
1515
halplibe_version=5.2.4
1616

1717
# Mod
18-
mod_version=2.0.0
18+
mod_version=2.1.0
1919
mod_group=turing
2020
mod_name=tmb

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static void onClientStart() {
6565
category.withComponent(new KeyBindingComponent(((IKeybinds) settings).toomanyblocks$getKeyAddFavourite()));
6666
category.withComponent(new KeyBindingComponent(((IKeybinds) settings).toomanyblocks$getKeySetDefaultRecipe()));
6767
category.withComponent(new KeyBindingComponent(((IKeybinds) settings).toomanyblocks$getKeyShowRecipeTree()));
68+
category.withComponent(new KeyBindingComponent(((IKeybinds) settings).toomanyblocks$getKeyFillRecipe()));
6869
OptionsPages.CONTROLS.withComponent(category);
6970
OptionsCategory category1 = new OptionsCategory("gui.options.page.general.category.tmb");
7071
category1.withComponent(new BooleanOptionComponent(((IKeybinds) settings).toomanyblocks$getIsRecipeViewEnabled()));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package turing.tmb.api;
2+
3+
import turing.tmb.api.recipe.IRecipeTranslator;
4+
5+
public interface ISupportsRecipeFilling {
6+
void fillRecipe(IRecipeTranslator<?> recipe);
7+
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import turing.tmb.RecipeIngredient;
1919
import turing.tmb.TMB;
2020
import turing.tmb.TooltipBuilder;
21+
import turing.tmb.api.ISupportsRecipeFilling;
2122
import turing.tmb.api.drawable.IIngredientList;
2223
import turing.tmb.api.drawable.builder.ITooltipBuilder;
2324
import turing.tmb.api.ingredient.IIngredientRenderer;
@@ -53,6 +54,7 @@ public class ScreenTMBRecipe extends Screen {
5354
private final ButtonElement tabLeftButton = new ButtonElement(2, 0, 0, "<");
5455
private final ButtonElement tabRightButton = new ButtonElement(3, 0, 0, ">");
5556
private String tooltip = "";
57+
private int debounce = 10;
5658

5759
public ScreenTMBRecipe(Screen parent) {
5860
super(parent);
@@ -220,6 +222,9 @@ private void scroll(int direction) {
220222
@Override
221223
@SuppressWarnings("unchecked")
222224
public void render(int mx, int my, float partialTick) {
225+
if(debounce > 0){
226+
debounce--;
227+
}
223228
renderBackground();
224229
GL11.glEnable(3042);
225230
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
@@ -440,6 +445,7 @@ private void renderTab(int x, int mx, int my, boolean selected, IRecipeCategory<
440445

441446
@Override
442447
public void keyPressed(char eventCharacter, int eventKey, int mx, int my) {
448+
if(debounce > 0) return;
443449
if (eventKey == Keyboard.KEY_BACK) {
444450
mc.displayScreen(getParentScreen());
445451
} else if (eventKey == Keyboard.KEY_ESCAPE || eventKey == mc.gameSettings.keyInventory.getKeyCode()) {
@@ -450,6 +456,26 @@ public void keyPressed(char eventCharacter, int eventKey, int mx, int my) {
450456
mc.displayScreen(s);
451457
}
452458

459+
if(eventKey == ((IKeybinds) mc.gameSettings).toomanyblocks$getKeyFillRecipe().getKeyCode()){
460+
Screen s = getParentScreen();
461+
while (s instanceof ScreenTMBRecipe) {
462+
s = s.getParentScreen();
463+
}
464+
if(s instanceof ISupportsRecipeFilling){
465+
for (int i = 0; i < drawnIngredients.size(); i++) {
466+
Pair<ITypedIngredient<?>, Pair<Integer, Integer>> drawn = drawnIngredients.get(i);
467+
RecipeIngredient recipeIngredient = recipeIngredients.get(i);
468+
if (mx >= drawn.getRight().getLeft() && my >= drawn.getRight().getRight() && mx < drawn.getRight().getLeft() + 16 && my < drawn.getRight().getRight() + 16) {
469+
if (recipeIngredient.recipe != null) {
470+
mc.displayScreen(s);
471+
((ISupportsRecipeFilling) s).fillRecipe(recipeIngredient.recipe);
472+
break;
473+
}
474+
}
475+
}
476+
}
477+
}
478+
453479
if (eventKey == ((IKeybinds)mc.gameSettings).toomanyblocks$getKeyShowRecipeTree().getKeyCode()){
454480
for (int i = 0; i < drawnIngredients.size(); i++) {
455481
Pair<ITypedIngredient<?>, Pair<Integer, Integer>> drawn = drawnIngredients.get(i);
@@ -511,8 +537,10 @@ public void keyPressed(char eventCharacter, int eventKey, int mx, int my) {
511537
Pair<ITypedIngredient<?>, Pair<Integer, Integer>> drawn = drawnIngredients.get(i);
512538
if (mx >= drawn.getRight().getLeft() && my >= drawn.getRight().getRight() && mx < drawn.getRight().getLeft() + 16 && my < drawn.getRight().getRight() + 16) {
513539
if (eventKey == mc.gameSettings.keyShowUsage.getKeyCode()) {
540+
debounce = 10;
514541
TMB.getRuntime().showRecipe(drawn.getLeft(), RecipeIngredientRole.INPUT);
515542
} else {
543+
debounce = 10;
516544
TMB.getRuntime().showRecipe(drawn.getLeft(), RecipeIngredientRole.OUTPUT);
517545
}
518546
break;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ public static void renderItems(int mouseX, int mouseY, int width, int height, Mi
233233
GL11.glPopMatrix();
234234
}
235235

236-
if (enabledRecipes) {
236+
if (enabledRecipes && debounce <= 0) {
237237
if (mc.gameSettings.keyShowRecipe.isPressed()) {
238+
debounce = 20;
238239
runtime.showRecipe(hoveredItem, RecipeIngredientRole.OUTPUT);
239240
} else if (mc.gameSettings.keyShowUsage.isPressed()) {
241+
debounce = 20;
240242
runtime.showRecipe(hoveredItem, RecipeIngredientRole.INPUT);
241243
}
242244
}
@@ -325,10 +327,12 @@ public static void renderItems2(int mouseX, int mouseY, int width, int height, M
325327
GL11.glPopMatrix();
326328
}
327329

328-
if (enabledRecipes) {
330+
if (enabledRecipes && debounce <= 0) {
329331
if (mc.gameSettings.keyShowRecipe.isPressed()) {
332+
debounce = 20;
330333
runtime.showRecipe(hoveredItem, RecipeIngredientRole.OUTPUT);
331334
} else if (mc.gameSettings.keyShowUsage.isPressed()) {
335+
debounce = 20;
332336
runtime.showRecipe(hoveredItem, RecipeIngredientRole.INPUT);
333337
}
334338
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class GameSettingsMixin implements IKeybinds {
2828
@Unique
2929
public KeyBinding keyAddFavourite = new KeyBinding("key.tmb.keyAddFavourite").bind(InputDevice.keyboard, Keyboard.KEY_A);
3030

31+
@Unique
32+
public KeyBinding keyFillRecipe = new KeyBinding("key.tmb.keyFillRecipe").bind(InputDevice.keyboard, Keyboard.KEY_F);
33+
34+
3135
@Unique
3236
public OptionBoolean isTMBHidden = new OptionBoolean((GameSettings) ((Object) this), "isTMBHidden", false);
3337

@@ -72,6 +76,11 @@ public class GameSettingsMixin implements IKeybinds {
7276
return keyAddFavourite;
7377
}
7478

79+
@Override
80+
public KeyBinding toomanyblocks$getKeyFillRecipe() {
81+
return keyFillRecipe;
82+
}
83+
7584
@Inject(method = "saveOptions", at = @At("HEAD"))
7685
public void saveTMBState(CallbackInfo ci) {
7786
if (TMBRenderer.search != null) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public interface IKeybinds {
1919
KeyBinding toomanyblocks$getKeySetDefaultRecipe();
2020

2121
KeyBinding toomanyblocks$getKeyAddFavourite();
22+
23+
KeyBinding toomanyblocks$getKeyFillRecipe();
2224
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ key.tmb.hide=Hide TMB
1212
key.tmb.keyAddFavourite=Add/Remove Favourite
1313
key.tmb.setDefaultRecipe=Set/Remove Default Recipe
1414
key.tmb.showRecipeTree=Show Recipe Tree
15+
key.tmb.keyFillRecipe=Fill Recipe
1516
options.isRecipeViewEnabled=Enable Recipe Viewing
1617
options.isTMBHidden=Hide TMB
1718

0 commit comments

Comments
 (0)