Skip to content
This repository has been archived by the owner on Jun 25, 2023. It is now read-only.

Commit

Permalink
Add ModifierWorktable to rei compat from jei
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaMode committed Apr 26, 2023
1 parent 61c9b77 commit a8495ae
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/slimeknights/tconstruct/plugin/rei/REIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import slimeknights.tconstruct.library.recipe.modifiers.severing.SeveringRecipe;
import slimeknights.tconstruct.library.recipe.molding.MoldingRecipe;
import slimeknights.tconstruct.library.recipe.partbuilder.IDisplayPartBuilderRecipe;
import slimeknights.tconstruct.library.recipe.worktable.IModifierWorktableRecipe;
import slimeknights.tconstruct.library.tools.SlotType;
import slimeknights.tconstruct.library.tools.item.IModifiableDisplay;
import slimeknights.tconstruct.plugin.jei.entity.DefaultEntityMeltingRecipe;
Expand All @@ -67,6 +68,8 @@
import slimeknights.tconstruct.plugin.rei.modifiers.ModifierEntryDefinition;
import slimeknights.tconstruct.plugin.rei.modifiers.ModifierRecipeCategory;
import slimeknights.tconstruct.plugin.rei.modifiers.ModifierRecipeDisplay;
import slimeknights.tconstruct.plugin.rei.modifiers.ModifierWorktableCategory;
import slimeknights.tconstruct.plugin.rei.modifiers.ModifierWorktableDisplay;
import slimeknights.tconstruct.plugin.rei.partbuilder.PartBuilderCategory;
import slimeknights.tconstruct.plugin.rei.partbuilder.PartBuilderDisplay;
import slimeknights.tconstruct.plugin.rei.partbuilder.PatternEntryDefinition;
Expand Down Expand Up @@ -99,12 +102,15 @@ public void registerCategories(CategoryRegistry registry) {
registry.add(new SeveringCategory());
// part builder
registry.add(new PartBuilderCategory());
// modifier worktable
registry.add(new ModifierWorktableCategory());

// tables
registry.addWorkstations(TConstructREIConstants.PART_BUILDER, EntryStacks.of(TinkerTables.partBuilder));
registry.addWorkstations(TConstructREIConstants.MODIFIERS, EntryStacks.of(TinkerTables.tinkerStation));
registry.addWorkstations(TConstructREIConstants.MODIFIERS, EntryStacks.of(TinkerTables.tinkersAnvil));
registry.addWorkstations(TConstructREIConstants.MODIFIERS, EntryStacks.of(TinkerTables.scorchedAnvil));
registry.addWorkstations(TConstructREIConstants.MODIFIER_WORKTABLE, EntryStacks.of(TinkerTables.modifierWorktable));

// smeltery
registry.addWorkstations(TConstructREIConstants.MELTING, EntryStacks.of(TinkerSmeltery.searedMelter));
Expand Down Expand Up @@ -221,6 +227,10 @@ public void registerDisplays(DisplayRegistry registry) {
MaterialItemList.setRecipes(materialRecipes);
List<IDisplayPartBuilderRecipe> partRecipes = RecipeHelper.getJEIRecipes(manager, TinkerRecipeTypes.PART_BUILDER.get(), IDisplayPartBuilderRecipe.class);
partRecipes.forEach(partRecipe -> registry.add(new PartBuilderDisplay(partRecipe)));

// modifier worktable
List<IModifierWorktableRecipe> modifierWorktableRecipes = RecipeHelper.getJEIRecipes(manager, TinkerRecipeTypes.MODIFIER_WORKTABLE.get(), IModifierWorktableRecipe.class);
modifierWorktableRecipes.forEach(iModifierWorktableRecipe -> registry.add(new ModifierWorktableDisplay(iModifierWorktableRecipe)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.type.EntryType;
import mezz.jei.api.recipe.RecipeType;
import net.minecraft.world.entity.EntityType;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.recipe.partbuilder.Pattern;
import slimeknights.tconstruct.library.recipe.worktable.IModifierWorktableRecipe;
import slimeknights.tconstruct.plugin.rei.casting.CastingDisplay;
import slimeknights.tconstruct.plugin.rei.entity.EntityMeltingRecipeDisplay;
import slimeknights.tconstruct.plugin.rei.entity.SeveringDisplay;
import slimeknights.tconstruct.plugin.rei.melting.MeltingDisplay;
import slimeknights.tconstruct.plugin.rei.modifiers.ModifierRecipeDisplay;
import slimeknights.tconstruct.plugin.rei.modifiers.ModifierWorktableDisplay;
import slimeknights.tconstruct.plugin.rei.partbuilder.PartBuilderDisplay;

public class TConstructREIConstants {
Expand Down Expand Up @@ -39,6 +42,9 @@ public class TConstructREIConstants {
// part builder
public static final CategoryIdentifier<PartBuilderDisplay> PART_BUILDER = type("part_builder");

// modifier workstation
public static final CategoryIdentifier<ModifierWorktableDisplay> MODIFIER_WORKTABLE = type("worktable");

private static <D extends Display> CategoryIdentifier<D> type(String name) {
return CategoryIdentifier.of(TConstruct.MOD_ID, name);
}
Expand Down
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));
}
}
}
}
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;
}
}

0 comments on commit a8495ae

Please sign in to comment.