Filled potions

- Fix fluid potions recipes in JEI
This commit is contained in:
IThundxr 2025-02-02 13:37:05 -05:00
parent 59742c7515
commit 111a9ce5d0
Failed to generate hash of commit
3 changed files with 14 additions and 32 deletions

View file

@ -1,9 +1,5 @@
package com.simibubi.create.content.fluids.potion;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import com.mojang.serialization.Codec;
@ -20,7 +16,6 @@ import net.minecraft.core.component.DataComponents;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.level.BlockAndTintGetter;
@ -51,12 +46,6 @@ public class PotionFluid extends VirtualFluid {
return fluidStack;
}
public static FluidStack withEffects(int amount, PotionContents potionContents) {
FluidStack fluidStack = of(amount, potionContents, BottleType.REGULAR);
appendEffects(fluidStack, potionContents.customEffects());
return fluidStack;
}
public static FluidStack addPotionToFluidStack(FluidStack fs, PotionContents potionContents) {
if (potionContents == PotionContents.EMPTY) {
fs.remove(DataComponents.POTION_CONTENTS);
@ -66,16 +55,6 @@ public class PotionFluid extends VirtualFluid {
return fs;
}
public static FluidStack appendEffects(FluidStack fs, Collection<MobEffectInstance> customEffects) {
if (customEffects.isEmpty())
return fs;
PotionContents contents = fs.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
List<MobEffectInstance> effects = new ArrayList<>(customEffects);
effects.addAll(contents.customEffects());
fs.set(DataComponents.POTION_CONTENTS, new PotionContents(contents.potion(), contents.customColor(), effects));
return fs;
}
public enum BottleType implements StringRepresentable {
REGULAR, SPLASH, LINGERING;

View file

@ -63,7 +63,7 @@ public class PotionFluidHandler {
BottleType bottleTypeFromItem = bottleTypeFromItem(stack.getItem());
if (potion.is(Potions.WATER) && potion.customEffects().isEmpty() && bottleTypeFromItem == BottleType.REGULAR)
return new FluidStack(Fluids.WATER, 250);
FluidStack fluid = PotionFluid.withEffects(250, potion);
FluidStack fluid = getFluidFromPotion(potion, bottleTypeFromItem, 250);
fluid.set(AllDataComponents.POTION_FLUID_BOTTLE_TYPE, bottleTypeFromItem);
return fluid;
}
@ -103,7 +103,8 @@ public class PotionFluidHandler {
// Modified version of PotionContents#addPotionTooltip
@OnlyIn(Dist.CLIENT)
public static void addPotionTooltip(FluidStack fs, Consumer<Component> tooltipAdder, float durationFactor) {
Iterable<MobEffectInstance> effects = fs.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).getAllEffects();
PotionContents contents = fs.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
Iterable<MobEffectInstance> effects = contents.getAllEffects();
List<Pair<Holder<Attribute>, AttributeModifier>> list = Lists.newArrayList();

View file

@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import com.simibubi.create.Create;
@ -16,8 +15,8 @@ import com.simibubi.create.content.processing.recipe.ProcessingRecipeBuilder;
import com.simibubi.create.foundation.fluid.FluidIngredient;
import com.simibubi.create.foundation.mixin.accessor.PotionBrewingAccessor;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.core.Holder.Reference;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
@ -81,8 +80,8 @@ public class PotionMixingRecipes {
for (Item container : allowedSupportedContainers) {
BottleType bottleType = PotionFluidHandler.bottleTypeFromItem(container);
for (PotionBrewing.Mix<Potion> mix : ((PotionBrewingAccessor) potionBrewing).create$getPotionMixes()) {
FluidStack fromFluid = PotionFluidHandler.getFluidFromPotion(new PotionContents(Optional.of(mix.from()), Optional.empty(), mix.from().value().getEffects()), bottleType, 1000);
FluidStack toFluid = PotionFluidHandler.getFluidFromPotion(new PotionContents(Optional.of(mix.to()), Optional.empty(), mix.to().value().getEffects()), bottleType, 1000);
FluidStack fromFluid = PotionFluidHandler.getFluidFromPotion(new PotionContents(mix.from()), bottleType, 1000);
FluidStack toFluid = PotionFluidHandler.getFluidFromPotion(new PotionContents(mix.to()), bottleType, 1000);
mixingRecipes.add(createRecipe("potion_mixing_vanilla_" + recipeIndex++, mix.ingredient(), fromFluid, toFluid));
}
@ -101,11 +100,14 @@ public class PotionMixingRecipes {
BottleType toBottleType = PotionFluidHandler.bottleTypeFromItem(to);
Ingredient ingredient = mix.ingredient();
for (Map.Entry<ResourceKey<Potion>, Potion> potionEntry : BuiltInRegistries.POTION.entrySet()) {
Potion potion = potionEntry.getValue();
List<Reference<Potion>> potions = level.registryAccess()
.lookupOrThrow(Registries.POTION)
.listElements()
.toList();
FluidStack fromFluid = PotionFluidHandler.getFluidFromPotion(new PotionContents(Optional.of(BuiltInRegistries.POTION.wrapAsHolder(potion)), Optional.empty(), potion.getEffects()), fromBottleType, 1000);
FluidStack toFluid = PotionFluidHandler.getFluidFromPotion(new PotionContents(Optional.of(BuiltInRegistries.POTION.wrapAsHolder(potion)), Optional.empty(), potion.getEffects()), toBottleType, 1000);
for (Reference<Potion> potion : potions) {
FluidStack fromFluid = PotionFluidHandler.getFluidFromPotion(new PotionContents(potion), fromBottleType, 1000);
FluidStack toFluid = PotionFluidHandler.getFluidFromPotion(new PotionContents(potion), toBottleType, 1000);
mixingRecipes.add(createRecipe("potion_mixing_vanilla_" + recipeIndex++, ingredient, fromFluid, toFluid));
}