Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brewery Potion Recipe Handler #2506

Open
wants to merge 5 commits into
base: 1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,7 @@
"entity.gtceu.industrial_tnt": "⟘N⟘ ןɐıɹʇsnpuI",
"entity.gtceu.powderbarrel": "ןǝɹɹɐqɹǝpʍoԀ",
"fluid.empty": "ʎʇdɯƎ",
"fluid.gtceu.potion": "uoıʇoԀ",
"fluid.spawnlocation.name": "uoıʇɐɯɹoɟuI uıǝΛ pınןℲ",
"fluid.tile.lava": "ɐʌɐꞀ",
"fluid.tile.water": "ɹǝʇɐM",
Expand Down Expand Up @@ -3448,6 +3449,7 @@
"gtceu.recipe_memory_widget.tooltip.0": "pıɹb buıʇɟɐɹɔ ǝɥʇ oʇuı ǝdıɔǝɹ sıɥʇ ʇnduı ʎןןɐɔıʇɐɯoʇnɐ oʇ ʞɔıןɔ ʇɟǝꞀㄥ§",
"gtceu.recipe_memory_widget.tooltip.1": "ǝdıɔǝɹ sıɥʇ ʞɔoןun/ʞɔoן oʇ ʞɔıןɔ ʇɟıɥSㄥ§",
"gtceu.recipe_type.show_recipes": "sǝdıɔǝᴚ ʍoɥS",
"gtceu.rei.group.potion_fluids": "spınןℲ uoıʇoԀ",
"gtceu.research_station": "uoıʇɐʇS ɥɔɹɐǝsǝᴚ",
"gtceu.rock_breaker": "ɹǝʞɐǝɹᗺ ʞɔoᴚ",
"gtceu.scanner": "ɹǝuuɐɔS",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,7 @@
"entity.gtceu.industrial_tnt": "Industrial TNT",
"entity.gtceu.powderbarrel": "Powderbarrel",
"fluid.empty": "Empty",
"fluid.gtceu.potion": "Potion",
"fluid.spawnlocation.name": "Fluid Vein Information",
"fluid.tile.lava": "Lava",
"fluid.tile.water": "Water",
Expand Down Expand Up @@ -3448,6 +3449,7 @@
"gtceu.recipe_memory_widget.tooltip.0": "§7Left click to automatically input this recipe into the crafting grid",
"gtceu.recipe_memory_widget.tooltip.1": "§7Shift click to lock/unlock this recipe",
"gtceu.recipe_type.show_recipes": "Show Recipes",
"gtceu.rei.group.potion_fluids": "Potion Fluids",
"gtceu.research_station": "Research Station",
"gtceu.rock_breaker": "Rock Breaker",
"gtceu.scanner": "Scanner",
Expand Down
6 changes: 6 additions & 0 deletions src/generated/resources/data/forge/tags/fluids/potion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"gtceu:flowing_potion",
"gtceu:potion"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import com.gregtechceu.gtceu.api.recipe.modifier.ParallelLogic;
import com.gregtechceu.gtceu.api.recipe.ui.GTRecipeTypeUI;
import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable;
import com.gregtechceu.gtceu.api.transfer.fluid.TagOrCycleFluidHandler;
import com.gregtechceu.gtceu.client.TooltipsHandler;
import com.gregtechceu.gtceu.integration.xei.entry.fluid.FluidEntryList;
import com.gregtechceu.gtceu.integration.xei.entry.fluid.FluidStackList;
import com.gregtechceu.gtceu.integration.xei.entry.fluid.FluidTagList;
import com.gregtechceu.gtceu.integration.xei.handlers.fluid.CycleFluidEntryHandler;
import com.gregtechceu.gtceu.integration.xei.widgets.GTRecipeWidget;
import com.gregtechceu.gtceu.utils.FluidKey;
import com.gregtechceu.gtceu.utils.GTHashMaps;
Expand All @@ -28,13 +31,10 @@

import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.fluids.FluidStack;

import com.mojang.datafixers.util.Either;
import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
Expand Down Expand Up @@ -304,8 +304,7 @@ public int getMaxParallelRatio(IRecipeCapabilityHolder holder, GTRecipe recipe,
public Object createXEIContainer(List<?> contents) {
// cast is safe if you don't pass the wrong thing.
// noinspection unchecked
return new TagOrCycleFluidHandler(
(List<Either<List<Pair<TagKey<Fluid>, Integer>>, List<FluidStack>>>) contents);
return new CycleFluidEntryHandler((List<FluidEntryList>) contents);
}

@NotNull
Expand Down Expand Up @@ -334,8 +333,8 @@ public void applyWidgetInfo(@NotNull Widget widget,
@Nullable Content content,
@Nullable Object storage, int recipeTier, int chanceTier) {
if (widget instanceof TankWidget tank) {
if (storage instanceof TagOrCycleFluidHandler fluidHandler) {
tank.setFluidTank(fluidHandler, index);
if (storage instanceof CycleFluidEntryHandler cycleHandler) {
tank.setFluidTank(cycleHandler, index);
} else if (storage instanceof IFluidHandlerModifiable fluidHandler) {
tank.setFluidTank(new OverlayingFluidStorage(fluidHandler, index));
}
Expand All @@ -350,10 +349,7 @@ public void applyWidgetInfo(@NotNull Widget widget,
FluidIngredient ingredient = FluidRecipeCapability.CAP.of(content.content);
if (!isXEI && ingredient.getStacks().length > 0) {
FluidStack stack = ingredient.getStacks()[0];
TooltipsHandler.appendFluidTooltips(stack.getFluid(),
stack.getAmount(),
tooltips::add,
TooltipFlag.NORMAL);
TooltipsHandler.appendFluidTooltips(stack, tooltips::add, TooltipFlag.NORMAL);
}

GTRecipeWidget.setConsumedChance(content,
Expand All @@ -370,24 +366,24 @@ public void applyWidgetInfo(@NotNull Widget widget,
}
}

// Maps fluids to Either<(tag with count), FluidStack>s
public static Either<List<Pair<TagKey<Fluid>, Integer>>, List<FluidStack>> mapFluid(FluidIngredient ingredient) {
// Maps fluids to a FluidEntryList for XEI: either a FluidTagList or a FluidStackList
public static FluidEntryList mapFluid(FluidIngredient ingredient) {
int amount = ingredient.getAmount();
CompoundTag tag = ingredient.getNbt();

List<Pair<TagKey<Fluid>, Integer>> tags = new ArrayList<>();
List<FluidStack> fluids = new ArrayList<>();
FluidTagList tags = new FluidTagList();
FluidStackList fluids = new FluidStackList();
for (FluidIngredient.Value value : ingredient.values) {
if (value instanceof FluidIngredient.TagValue tagValue) {
tags.add(Pair.of(tagValue.getTag(), amount));
tags.add(tagValue.getTag(), amount, ingredient.getNbt());
} else {
fluids.addAll(value.getFluids().stream().map(fluid -> new FluidStack(fluid, amount, tag)).toList());
}
}
if (!tags.isEmpty()) {
return Either.left(tags);
return tags;
} else {
return Either.right(fluids);
return fluids;
}
}

Expand Down
Loading
Loading