This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
forked from Alpha-s-Stuff/TinkersConstruct
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ModifierWorktable to rei compat from jei
- Loading branch information
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/slimeknights/tconstruct/plugin/rei/modifiers/ModifierWorktableCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package slimeknights.tconstruct.plugin.rei.modifiers; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import lombok.Getter; | ||
import me.shedaniel.math.Point; | ||
import me.shedaniel.math.Rectangle; | ||
import me.shedaniel.rei.api.client.gui.Renderer; | ||
import me.shedaniel.rei.api.client.gui.widgets.Slot; | ||
import me.shedaniel.rei.api.client.gui.widgets.Widget; | ||
import me.shedaniel.rei.api.common.category.CategoryIdentifier; | ||
import me.shedaniel.rei.api.common.util.EntryIngredients; | ||
import me.shedaniel.rei.api.common.util.EntryStacks; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import slimeknights.tconstruct.TConstruct; | ||
import slimeknights.tconstruct.library.recipe.worktable.IModifierWorktableRecipe; | ||
import slimeknights.tconstruct.plugin.rei.TConstructREIConstants; | ||
import slimeknights.tconstruct.plugin.rei.TinkersCategory; | ||
import slimeknights.tconstruct.plugin.rei.widgets.WidgetHolder; | ||
import slimeknights.tconstruct.tables.TinkerTables; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ModifierWorktableCategory implements TinkersCategory<ModifierWorktableDisplay> { | ||
private static final ResourceLocation BACKGROUND_LOC = TConstruct.getResource("textures/gui/jei/tinker_station.png"); | ||
private static final Component TITLE = TConstruct.makeTranslation("jei", "modifier_worktable.title"); | ||
|
||
@Getter | ||
private final WidgetHolder background; | ||
@Getter | ||
private final Renderer icon; | ||
private final WidgetHolder toolIcon; | ||
private final WidgetHolder[] slotIcons; | ||
public ModifierWorktableCategory() { | ||
this.background = new WidgetHolder(BACKGROUND_LOC, 0, 166, 121, 35); | ||
this.icon = EntryStacks.of(TinkerTables.modifierWorktable); | ||
this.toolIcon = new WidgetHolder(BACKGROUND_LOC, 128, 0, 16, 16); | ||
this.slotIcons = new WidgetHolder[] { | ||
new WidgetHolder(BACKGROUND_LOC, 176, 0, 16, 16), | ||
new WidgetHolder(BACKGROUND_LOC, 208, 0, 16, 16) | ||
}; | ||
} | ||
|
||
@Override | ||
public WidgetHolder getBackground() { | ||
return this.background; | ||
} | ||
|
||
@Override | ||
public CategoryIdentifier<? extends ModifierWorktableDisplay> getCategoryIdentifier() { | ||
return TConstructREIConstants.MODIFIER_WORKTABLE; | ||
} | ||
|
||
@Override | ||
public Component getTitle() { | ||
return TITLE; | ||
} | ||
|
||
@Override | ||
public Renderer getIcon() { | ||
return this.icon; | ||
} | ||
|
||
@Override | ||
public void draw(ModifierWorktableDisplay display, PoseStack matrixStack, double mouseX, double mouseY) { | ||
Minecraft.getInstance().font.draw(matrixStack, display.getRecipe().getTitle(), 3, 2, 0x404040); | ||
} | ||
|
||
@Override | ||
public List<Component> getTooltipStrings(ModifierWorktableDisplay recipe, List<Widget> widgets, double mouseX, double mouseY) { | ||
if (mouseY >= 2 && mouseY <= 12) { | ||
return List.of(recipe.getRecipe().getDescription(null)); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public void addWidgets(ModifierWorktableDisplay display, List<Widget> ingredients, Point origin, Rectangle bounds) { | ||
IModifierWorktableRecipe recipe = display.getRecipe(); | ||
// items | ||
ingredients.add(slot(23, 16, origin).markInput().entries(EntryIngredients.ofItemStacks(recipe.getInputTools()))); | ||
int max = Math.min(2, recipe.getInputCount()); | ||
for (int i = 0; i < max; i++) { | ||
ingredients.add(slot(43 + i*18, 16, origin).markInput().entries(EntryIngredients.ofItemStacks(recipe.getDisplayItems(i)))); | ||
} | ||
// modifier input | ||
Slot slot = slot(82, 16, origin).entries(EntryIngredients.of(TConstructREIConstants.MODIFIER_TYPE, recipe.getModifierOptions(null))); | ||
if (recipe.isModifierOutput()) | ||
slot.markOutput(); | ||
else | ||
slot.markInput(); | ||
ingredients.add(slot); | ||
|
||
if (recipe.getInputTools().isEmpty()) { | ||
ingredients.add(toolIcon.build(23, 16, origin)); | ||
} | ||
for (int i = 0; i < 2; i++) { | ||
List<ItemStack> stacks = recipe.getDisplayItems(i); | ||
if (stacks.isEmpty()) { | ||
ingredients.add(slotIcons[i].build(43 + i * 18, 16, origin)); | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/slimeknights/tconstruct/plugin/rei/modifiers/ModifierWorktableDisplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package slimeknights.tconstruct.plugin.rei.modifiers; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import lombok.Getter; | ||
import me.shedaniel.rei.api.common.category.CategoryIdentifier; | ||
import me.shedaniel.rei.api.common.display.Display; | ||
import me.shedaniel.rei.api.common.entry.EntryIngredient; | ||
import me.shedaniel.rei.api.common.util.EntryIngredients; | ||
import slimeknights.tconstruct.library.recipe.worktable.IModifierWorktableRecipe; | ||
import slimeknights.tconstruct.plugin.rei.TConstructREIConstants; | ||
|
||
import java.util.List; | ||
|
||
public class ModifierWorktableDisplay implements Display { | ||
@Getter | ||
private final List<EntryIngredient> inputEntries; | ||
@Getter | ||
private final List<EntryIngredient> outputEntries; | ||
@Getter | ||
private final IModifierWorktableRecipe recipe; | ||
|
||
public ModifierWorktableDisplay(IModifierWorktableRecipe recipe) { | ||
ImmutableList.Builder<EntryIngredient> inputs = ImmutableList.builder(); | ||
ImmutableList.Builder<EntryIngredient> outputs = ImmutableList.builder(); | ||
inputs.add(EntryIngredients.ofItemStacks(recipe.getInputTools())); | ||
int max = Math.min(2, recipe.getInputCount()); | ||
for (int i = 0; i < max; i++) { | ||
inputs.add(EntryIngredients.ofItemStacks(recipe.getDisplayItems(i))); | ||
} | ||
// modifier input | ||
if (recipe.isModifierOutput()) | ||
outputs.add(EntryIngredients.of(TConstructREIConstants.MODIFIER_TYPE, recipe.getModifierOptions(null))); | ||
else | ||
outputs.add(EntryIngredients.of(TConstructREIConstants.MODIFIER_TYPE, recipe.getModifierOptions(null))); | ||
|
||
this.inputEntries = inputs.build(); | ||
this.outputEntries = outputs.build(); | ||
this.recipe = recipe; | ||
} | ||
|
||
@Override | ||
public CategoryIdentifier<ModifierWorktableDisplay> getCategoryIdentifier() { | ||
return TConstructREIConstants.MODIFIER_WORKTABLE; | ||
} | ||
} |