Skip to content

Commit

Permalink
Fix errors in REI integration
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealWormbo committed Jul 28, 2024
1 parent ed3717b commit f0ab367
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.block.Block;

import org.jetbrains.annotations.Nullable;

import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.item.AncientWillContainer;
import vazkii.botania.api.recipe.*;
import vazkii.botania.client.core.handler.CorporeaInputHandler;
import vazkii.botania.common.block.BotaniaBlocks;
import vazkii.botania.common.block.BotaniaFlowerBlocks;
import vazkii.botania.common.crafting.*;
import vazkii.botania.common.crafting.BotaniaRecipeTypes;
import vazkii.botania.common.item.AncientWillItem;
import vazkii.botania.common.item.BotaniaItems;
import vazkii.botania.common.item.equipment.tool.terrasteel.TerraShattererItem;
Expand Down Expand Up @@ -78,7 +80,7 @@ public void registerCategories(CategoryRegistry helper) {
new TerrestrialAgglomerationREICategory(),
new OrechidREICategory(BotaniaREICategoryIdentifiers.ORECHID, BotaniaFlowerBlocks.orechid),
new OrechidREICategory(BotaniaREICategoryIdentifiers.ORECHID_IGNEM, BotaniaFlowerBlocks.orechidIgnem),
new MarimorphosisREICategory()
new OrechidREICategory(BotaniaREICategoryIdentifiers.MARIMORPHOSIS, BotaniaFlowerBlocks.marimorphosis)
));

helper.addWorkstations(BuiltinPlugin.CRAFTING, EntryStacks.of(BotaniaItems.craftingHalo), EntryStacks.of(BotaniaItems.autocraftingHalo));
Expand Down Expand Up @@ -121,15 +123,14 @@ public void registerDisplays(DisplayRegistry helper) {
registerCompositeLensRecipeWrapper(helper);
registerTerraPickTippingRecipeWrapper(helper);

helper.registerFiller(PetalApothecaryRecipe.class, PetalApothecaryREIDisplay::new);
helper.registerFiller(BotanicalBreweryRecipe.class, BreweryREIDisplay::new);
Predicate<? extends ElvenTradeRecipe> pred = recipe -> !recipe.isReturnRecipe();
helper.registerFiller(ElvenTradeRecipe.class, pred, ElvenTradeREIDisplay::new);
helper.registerFiller(LexiconElvenTradeRecipe.class, ElvenTradeREIDisplay::new);
helper.registerFiller(ManaInfusionRecipe.class, ManaPoolREIDisplay::new);
helper.registerFiller(PureDaisyRecipe.class, PureDaisyREIDisplay::new);
helper.registerFiller(RunicAltarRecipe.class, RunicAltarREIDisplay::new);
helper.registerFiller(TerrestrialAgglomerationRecipe.class, TerrestrialAgglomerationREIDisplay::new);
helper.registerRecipeFiller(PetalApothecaryRecipe.class, BotaniaRecipeTypes.PETAL_TYPE, PetalApothecaryREIDisplay::new);
helper.registerRecipeFiller(BotanicalBreweryRecipe.class, BotaniaRecipeTypes.BREW_TYPE, BreweryREIDisplay::new);
Predicate<RecipeHolder<ElvenTradeRecipe>> pred = recipe -> !recipe.value().isReturnRecipe();
helper.registerRecipeFiller(ElvenTradeRecipe.class, BotaniaRecipeTypes.ELVEN_TRADE_TYPE::equals, pred, ElvenTradeREIDisplay::new);
helper.registerRecipeFiller(ManaInfusionRecipe.class, BotaniaRecipeTypes.MANA_INFUSION_TYPE, ManaPoolREIDisplay::new);
helper.registerRecipeFiller(PureDaisyRecipe.class, BotaniaRecipeTypes.PURE_DAISY_TYPE, PureDaisyREIDisplay::new);
helper.registerRecipeFiller(RunicAltarRecipe.class, BotaniaRecipeTypes.RUNE_TYPE, RunicAltarREIDisplay::new);
helper.registerRecipeFiller(TerrestrialAgglomerationRecipe.class, BotaniaRecipeTypes.TERRA_PLATE_TYPE, TerrestrialAgglomerationREIDisplay::new);

try {
for (var entry : FabricXplatImpl.CUSTOM_STRIPPING.entrySet()) {
Expand All @@ -141,9 +142,9 @@ public void registerDisplays(DisplayRegistry helper) {

helper.registerRecipeFiller(OrechidRecipe.class, BotaniaRecipeTypes.ORECHID_TYPE,
OrechidREIDisplay::new);
helper.registerRecipeFiller(OrechidIgnemRecipe.class, BotaniaRecipeTypes.ORECHID_IGNEM_TYPE,
helper.registerRecipeFiller(OrechidRecipe.class, BotaniaRecipeTypes.ORECHID_IGNEM_TYPE,
OrechidIgnemREIDisplay::new);
helper.registerRecipeFiller(MarimorphosisRecipe.class, BotaniaRecipeTypes.MARIMORPHOSIS_TYPE,
helper.registerRecipeFiller(OrechidRecipe.class, BotaniaRecipeTypes.MARIMORPHOSIS_TYPE,
MarimorphosisREIDisplay::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;

import org.jetbrains.annotations.NotNull;

Expand All @@ -24,15 +25,15 @@
import java.util.Optional;

public abstract class BotaniaRecipeDisplay<T extends Recipe<Container>> implements Display {
protected final T recipe;
protected final RecipeHolder<? extends T> recipe;
protected List<EntryIngredient> inputs;
protected EntryIngredient outputs;

public BotaniaRecipeDisplay(T recipe) {
public BotaniaRecipeDisplay(RecipeHolder<? extends T> recipe) {
this.recipe = recipe;
this.inputs = EntryIngredients.ofIngredients(recipe.getIngredients());
this.inputs = EntryIngredients.ofIngredients(recipe.value().getIngredients());
// TODO 1.19.4 figure out the proper way to get a registry access
this.outputs = EntryIngredients.of(recipe.getResultItem(RegistryAccess.EMPTY));
this.outputs = EntryIngredients.of(recipe.value().getResultItem(RegistryAccess.EMPTY));
}

@Override
Expand All @@ -49,6 +50,6 @@ public BotaniaRecipeDisplay(T recipe) {

@Override
public @NotNull Optional<ResourceLocation> getDisplayLocation() {
return Optional.ofNullable(this.recipe).map(T::getId);
return Optional.ofNullable(this.recipe).map(RecipeHolder::id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import me.shedaniel.rei.api.common.util.EntryIngredients;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.common.crafting.BotanicalBreweryRecipe;
import vazkii.botania.api.recipe.BotanicalBreweryRecipe;
import vazkii.botania.common.item.BotaniaItems;

import java.util.ArrayList;
Expand All @@ -26,13 +27,13 @@
public class BreweryREIDisplay extends BotaniaRecipeDisplay<BotanicalBreweryRecipe> {
private final EntryIngredient containers;

public BreweryREIDisplay(BotanicalBreweryRecipe recipe) {
public BreweryREIDisplay(RecipeHolder<? extends BotanicalBreweryRecipe> recipe) {
super(recipe);
List<ItemStack> items = Arrays.asList(new ItemStack(BotaniaItems.vial), new ItemStack(BotaniaItems.flask), new ItemStack(BotaniaItems.incenseStick), new ItemStack(BotaniaItems.bloodPendant));
this.containers = EntryIngredients.ofItemStacks(items);
List<ItemStack> outputs = new ArrayList<>();
for (ItemStack stack : items) {
ItemStack brewed = recipe.getOutput(stack);
ItemStack brewed = recipe.value().getOutput(stack);
if (!brewed.isEmpty()) {
outputs.add(brewed);
}
Expand All @@ -46,7 +47,7 @@ public EntryIngredient getContainers() {

@Override
public int getManaCost() {
return recipe.getManaUsage();
return recipe.value().getManaUsage();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.util.EntryIngredients;

import net.minecraft.world.item.crafting.RecipeHolder;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.api.recipe.ElvenTradeRecipe;
import vazkii.botania.common.block.block_entity.AlfheimPortalBlockEntity;

public class ElvenTradeREIDisplay extends BotaniaRecipeDisplay<ElvenTradeRecipe> {

public ElvenTradeREIDisplay(ElvenTradeRecipe recipe) {
public ElvenTradeREIDisplay(RecipeHolder<? extends ElvenTradeRecipe> recipe) {
super(recipe);
this.outputs = EntryIngredients.ofItemStacks(recipe.getOutputs());
this.outputs = EntryIngredients.ofItemStacks(recipe.value().getOutputs());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@

import me.shedaniel.rei.api.common.category.CategoryIdentifier;

import net.minecraft.world.item.crafting.RecipeHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import vazkii.botania.api.recipe.ManaInfusionRecipe;
import vazkii.botania.api.recipe.StateIngredient;
import vazkii.botania.common.crafting.ManaInfusionRecipe;

public class ManaPoolREIDisplay extends BotaniaRecipeDisplay<ManaInfusionRecipe> {
@Nullable
private final StateIngredient catalyst;

public ManaPoolREIDisplay(ManaInfusionRecipe recipe) {
public ManaPoolREIDisplay(RecipeHolder<? extends ManaInfusionRecipe> recipe) {
super(recipe);
this.catalyst = recipe.getRecipeCatalyst();
this.catalyst = recipe.value().getRecipeCatalyst();
}

@Nullable
Expand All @@ -32,7 +34,7 @@ public StateIngredient getCatalyst() {

@Override
public int getManaCost() {
return recipe.getManaToConsume();
return recipe.value().getManaToConsume();
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

import me.shedaniel.rei.api.common.category.CategoryIdentifier;

import vazkii.botania.common.crafting.MarimorphosisRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;

public class MarimorphosisREIDisplay extends OrechidBaseREIDisplay<MarimorphosisRecipe> {
public MarimorphosisREIDisplay(MarimorphosisRecipe recipe) {
import vazkii.botania.api.recipe.OrechidRecipe;

public class MarimorphosisREIDisplay extends OrechidBaseREIDisplay {
public MarimorphosisREIDisplay(RecipeHolder<? extends OrechidRecipe> recipe) {
super(recipe);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.EntryStacks;

import net.minecraft.world.item.crafting.RecipeHolder;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.api.recipe.OrechidRecipe;
Expand All @@ -20,14 +22,14 @@
import java.util.List;
import java.util.stream.Collectors;

public abstract class OrechidBaseREIDisplay<T extends OrechidRecipe> implements Display {
public abstract class OrechidBaseREIDisplay implements Display {
private final List<EntryIngredient> stone;
private final List<EntryIngredient> ores;
private final T recipe;
private final RecipeHolder<? extends OrechidRecipe> recipe;

public OrechidBaseREIDisplay(T recipe) {
stone = Collections.singletonList(EntryIngredient.of(recipe.getInput().getDisplayedStacks().stream().map(EntryStacks::of).collect(Collectors.toList())));
ores = Collections.singletonList(EntryIngredient.of(recipe.getOutput().getDisplayedStacks().stream().map(EntryStacks::of).collect(Collectors.toList())));
public OrechidBaseREIDisplay(RecipeHolder<? extends OrechidRecipe> recipe) {
stone = Collections.singletonList(EntryIngredient.of(recipe.value().getInput().getDisplayedStacks().stream().map(EntryStacks::of).collect(Collectors.toList())));
ores = Collections.singletonList(EntryIngredient.of(recipe.value().getOutput().getDisplayedStacks().stream().map(EntryStacks::of).collect(Collectors.toList())));
this.recipe = recipe;
}

Expand All @@ -41,7 +43,7 @@ public OrechidBaseREIDisplay(T recipe) {
return ores;
}

public T getRecipe() {
public RecipeHolder<? extends OrechidRecipe> getRecipe() {
return recipe;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

import me.shedaniel.rei.api.common.category.CategoryIdentifier;

import net.minecraft.world.item.crafting.RecipeHolder;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.common.crafting.OrechidIgnemRecipe;
import vazkii.botania.api.recipe.OrechidRecipe;

public class OrechidIgnemREIDisplay extends OrechidBaseREIDisplay<OrechidIgnemRecipe> {
public OrechidIgnemREIDisplay(OrechidIgnemRecipe recipe) {
public class OrechidIgnemREIDisplay extends OrechidBaseREIDisplay {
public OrechidIgnemREIDisplay(RecipeHolder<? extends OrechidRecipe> recipe) {
super(recipe);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@

import static vazkii.botania.fabric.integration.rei.PureDaisyREICategory.setupPureDaisyDisplay;

public class OrechidREICategory implements DisplayCategory<OrechidBaseREIDisplay<?>> {
public class OrechidREICategory implements DisplayCategory<OrechidBaseREIDisplay> {
private final EntryStack<ItemStack> orechid;
private final CategoryIdentifier<? extends OrechidBaseREIDisplay<?>> categoryId;
private final CategoryIdentifier<? extends OrechidBaseREIDisplay> categoryId;
private final String langKey;

public OrechidREICategory(CategoryIdentifier<? extends OrechidBaseREIDisplay<?>> categoryId, Block orechid) {
public OrechidREICategory(CategoryIdentifier<? extends OrechidBaseREIDisplay> categoryId, Block orechid) {
this.categoryId = categoryId;
this.orechid = EntryStacks.of(orechid);
this.langKey = "botania.nei." + (orechid == BotaniaFlowerBlocks.orechidIgnem ? "orechidIgnem" : "orechid");
}

@Override
public @NotNull CategoryIdentifier<? extends OrechidBaseREIDisplay<?>> getCategoryIdentifier() {
public @NotNull CategoryIdentifier<? extends OrechidBaseREIDisplay> getCategoryIdentifier() {
return categoryId;
}

Expand All @@ -62,16 +62,16 @@ public OrechidREICategory(CategoryIdentifier<? extends OrechidBaseREIDisplay<?>>
}

@Override
public @NotNull List<Widget> setupDisplay(OrechidBaseREIDisplay<?> display, Rectangle bounds) {
public @NotNull List<Widget> setupDisplay(OrechidBaseREIDisplay display, Rectangle bounds) {
List<Widget> widgets = setupPureDaisyDisplay(display, bounds, orechid);

final Double chance = getChance(display.getRecipe());
final Double chance = getChance(display.getRecipe().value());
if (chance != null) {
final Component chanceComponent = OrechidUIHelper.getPercentageComponent(chance);
final Point center = new Point(bounds.getCenterX() - 8, bounds.getCenterY() - 9);
final Label chanceLabel = Widgets.createLabel(new Point(center.x + 51, center.y - 11), chanceComponent)
.rightAligned().color(0x555555, 0xAAAAAA).noShadow();
chanceLabel.tooltip(getChanceTooltipComponents(chance, display.getRecipe()).toArray(Component[]::new));
chanceLabel.tooltip(getChanceTooltipComponents(chance, display.getRecipe().value()).toArray(Component[]::new));
widgets.add(chanceLabel);
}

Expand All @@ -81,7 +81,9 @@ public OrechidREICategory(CategoryIdentifier<? extends OrechidBaseREIDisplay<?>>
@NotNull
protected Stream<Component> getChanceTooltipComponents(double chance, OrechidRecipe recipe) {
final var ratio = OrechidUIHelper.getRatioForChance(chance);
return Stream.of(OrechidUIHelper.getRatioTooltipComponent(ratio));
Stream<Component> genericChanceTooltipComponents = Stream.of(OrechidUIHelper.getRatioTooltipComponent(ratio));
Stream<Component> biomeChanceTooltipComponents = OrechidUIHelper.getBiomeChanceAndRatioTooltipComponents(chance, recipe);
return Stream.concat(genericChanceTooltipComponents, biomeChanceTooltipComponents);
}

@Nullable
Expand All @@ -95,7 +97,7 @@ public int getDisplayHeight() {
}

@Override
public int getDisplayWidth(OrechidBaseREIDisplay<?> display) {
public int getDisplayWidth(OrechidBaseREIDisplay display) {
return 112;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

import me.shedaniel.rei.api.common.category.CategoryIdentifier;

import net.minecraft.world.item.crafting.RecipeHolder;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.common.crafting.OrechidRecipe;
import vazkii.botania.api.recipe.OrechidRecipe;

public class OrechidREIDisplay extends OrechidBaseREIDisplay<OrechidRecipe> {
public class OrechidREIDisplay extends OrechidBaseREIDisplay {

public OrechidREIDisplay(OrechidRecipe recipe) {
public OrechidREIDisplay(RecipeHolder<? extends OrechidRecipe> recipe) {
super(recipe);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.EntryIngredients;

import net.minecraft.world.item.crafting.RecipeHolder;

import org.jetbrains.annotations.NotNull;

import vazkii.botania.common.crafting.PetalApothecaryRecipe;
import vazkii.botania.api.recipe.PetalApothecaryRecipe;

public class PetalApothecaryREIDisplay extends BotaniaRecipeDisplay<PetalApothecaryRecipe> {
private EntryIngredient reagent;
private final EntryIngredient reagent;

public PetalApothecaryREIDisplay(PetalApothecaryRecipe recipe) {
public PetalApothecaryREIDisplay(RecipeHolder<? extends PetalApothecaryRecipe> recipe) {
super(recipe);
reagent = EntryIngredients.ofIngredient(recipe.getReagent());
reagent = EntryIngredients.ofIngredient(recipe.value().getReagent());
}

public EntryIngredient getReagent() {
Expand Down
Loading

0 comments on commit f0ab367

Please sign in to comment.