Skip to content

Commit

Permalink
finished up fluid changeover enough to compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Feb 23, 2025
1 parent 73b20c9 commit d81cd28
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public int drawInfo(TankMachine.TankRenderWidget instance, PoseStack stack, Font
return 8;
}
renderer.draw(stack, FluidPlatformUtils.INSTANCE.getFluidDisplayName(instance.stack).getString(), left, top, 0xFAFAFF);
String fluidAmount = String.valueOf(instance.stack.getFluidAmount());
String fluidAmount = String.valueOf(instance.stack.getAmount());
renderer.draw(stack, fluidAmount + " mb", left, top + 8, 0xFAFAFF);
return 16;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void mouseOver(PoseStack stack, double mouseX, double mouseY, float parti
RenderSystem.enableDepthTest();
List<Component> str = new ArrayList<>();
str.add(FluidPlatformUtils.INSTANCE.getFluidDisplayName(this.stack));
long mb = this.stack.getAmount();
int mb = this.stack.getAmount();
str.add(Utils.translatable("antimatter.tooltip.fluid.amount", mb + " L").withStyle(ChatFormatting.BLUE));
str.add(Utils.translatable("antimatter.tooltip.fluid.temp", FluidPlatformUtils.INSTANCE.getFluidTemperature(this.stack.getFluid())).withStyle(ChatFormatting.RED));
String liquid = !FluidPlatformUtils.INSTANCE.isFluidGaseous(this.stack.getFluid()) ? "liquid" : "gas";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import com.google.common.collect.ImmutableList;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import earth.terrarium.botarium.forge.fluid.ForgeFluidHolder;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import lombok.Getter;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.forge.ForgeTypes;
import mezz.jei.api.helpers.IJeiHelpers;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.api.ingredients.subtypes.UidContext;
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.registration.IRecipeCatalystRegistration;
import mezz.jei.api.registration.IRecipeCategoryRegistration;
Expand Down Expand Up @@ -44,6 +50,7 @@
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.NotNull;
Expand All @@ -58,6 +65,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

@SuppressWarnings("removal")
Expand Down Expand Up @@ -91,7 +99,7 @@ public void onRuntimeAvailable(@NotNull IJeiRuntime jeiRuntime) {
AntimatterJEIREIPlugin.getFluidsToHide().forEach(c -> c.accept(fluidList));
// wish there was a better way to do this
if (!fluidList.isEmpty()){
runtime.getIngredientManager().removeIngredientsAtRuntime(JEIPlatformHelper.INSTANCE.getFluidIngredientObjectType(), (Collection) fluidList.stream().map(f -> JEIPlatformHelper.INSTANCE.getFluidObject(FluidHolder.of(f))).toList());
runtime.getIngredientManager().removeIngredientsAtRuntime(ForgeTypes.FLUID_STACK, fluidList.stream().map(f -> new FluidStack(f, 1)).toList());
runtime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM, fluidList.stream().map(i -> i.getBucket().getDefaultInstance()).toList());
}
//runtime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM, AntimatterAPI.all(BlockSurfaceRock.class).stream().map(b -> new ItemStack(b, 1)).filter(t -> !t.isEmpty()).collect(Collectors.toList()));
Expand Down Expand Up @@ -236,9 +244,7 @@ public void registerRecipeTransferHandlers(IRecipeTransferRegistration registrat

public static <T> void addModDescriptor(List<Component> tooltip, T t) {
if (t == null || helpers == null) return;
Object o = t;
if (t instanceof FluidHolder holder) o = JEIPlatformHelper.INSTANCE.getFluidObject(holder);
String text = helpers.getModIdHelper().getFormattedModNameForModId(getRuntime().getIngredientManager().getIngredientHelper(o).getDisplayModId(o));
String text = helpers.getModIdHelper().getFormattedModNameForModId(getRuntime().getIngredientManager().getIngredientHelper((Object) t).getDisplayModId(t));
tooltip.add(Utils.literal(text));
}

Expand All @@ -264,4 +270,45 @@ public void registerRecipeCatalysts(@NotNull IRecipeCatalystRegistration registr
});
});
}

public static void uses(FluidStack val, boolean USE) {
AntimatterJEIPlugin.getRuntime().getRecipesGui().show(new IFocus<FluidStack>() {
@Override
public ITypedIngredient<FluidStack> getTypedValue() {
return new ITypedIngredient<>() {
@Override
public IIngredientType<FluidStack> getType() {
return ForgeTypes.FLUID_STACK;
}

@Override
public FluidStack getIngredient() {
return val;
}

@Override
public <V> Optional<V> getIngredient(IIngredientType<V> ingredientType) {
if (ingredientType == ForgeTypes.FLUID_STACK) return ((Optional<V>) Optional.of(val));
return Optional.empty();
}
};
}

@Override
public RecipeIngredientRole getRole() {
return USE ? RecipeIngredientRole.INPUT : RecipeIngredientRole.OUTPUT;
}

@Override
public <T> Optional<IFocus<T>> checkedCast(IIngredientType<T> ingredientType) {
return Optional.empty();
}

@Override
public Mode getMode() {
return USE ? Mode.INPUT : Mode.OUTPUT;
}

});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.forge.ForgeTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
Expand Down Expand Up @@ -43,6 +44,7 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.fluids.FluidStack;
import tesseract.TesseractGraphWrappers;

import java.util.Arrays;
Expand Down Expand Up @@ -230,11 +232,11 @@ public void setRecipe(IRecipeLayoutBuilder builder, IRecipe recipe, IFocusGroup
slotCount = Math.min(slotCount, fluids.size());
for (int s = 0; s < slotCount; s++) {
IRecipeSlotBuilder slot = builder.addSlot(RecipeIngredientRole.INPUT, slots.get(s).getX() - (offsetX - 1), slots.get(s).getY() - (offsetY - 1));
JEIPlatformHelper.INSTANCE.addFluidIngredients(slot, Arrays.asList(fluids.get(s).getStacks()));
slot.addIngredients(ForgeTypes.FLUID_STACK, Arrays.asList(fluids.get(s).getStacks()));
slot.setFluidRenderer((int)fluids.get(s).getAmount(), true, 16, 16);
int finalS = s;
slot.addTooltipCallback((ing, list) -> {
FluidHolder stack = fluids.get(finalS).getStacks()[0];
FluidStack stack = fluids.get(finalS).getStacks()[0];
createFluidTooltip(ing, list, stack);
});
inputFluids++;
Expand All @@ -245,32 +247,32 @@ public void setRecipe(IRecipeLayoutBuilder builder, IRecipe recipe, IFocusGroup
slots = gui.getSlots().getSlots(SlotType.FL_OUT, guiTier);
slotCount = slots.size();
if (slotCount > 0) {
FluidHolder[] fluids = recipe.getOutputFluids();
FluidStack[] fluids = recipe.getOutputFluids();
slotCount = Math.min(slotCount, fluids.length);
for (int s = 0; s < slotCount; s++) {
IRecipeSlotBuilder slot = builder.addSlot(RecipeIngredientRole.OUTPUT, slots.get(s).getX() - (offsetX - 1), slots.get(s).getY() - (offsetY - 1));
slot.setFluidRenderer((int)fluids[s].getFluidAmount(), true, 16, 16);
JEIPlatformHelper.INSTANCE.addFluidIngredients(slot, Collections.singletonList(fluids[s]));
slot.setFluidRenderer(fluids[s].getAmount(), true, 16, 16);
slot.addIngredients(ForgeTypes.FLUID_STACK, Collections.singletonList(fluids[s]));
int finalS = s;
slot.addTooltipCallback((ing, list) -> {
FluidHolder stack = fluids[finalS];
FluidStack stack = fluids[finalS];
createFluidTooltip(ing, list, stack);
});
}
}
}
}

private void createFluidTooltip(IRecipeSlotView ing, List<Component> list, FluidHolder stack) {
private void createFluidTooltip(IRecipeSlotView ing, List<Component> list, FluidStack stack) {
Component component = list.get(2);
list.remove(2);
list.remove(1);
long mb = stack.getFluidAmount();
int mb = stack.getAmount();
list.add(Utils.translatable("antimatter.tooltip.fluid.amount", mb + " L").withStyle(ChatFormatting.BLUE));
list.add(Utils.translatable("antimatter.tooltip.fluid.temp", FluidPlatformUtils.INSTANCE.getFluidTemperature(stack.getFluid())).withStyle(ChatFormatting.RED));
String liquid = !FluidPlatformUtils.INSTANCE.isFluidGaseous(stack.getFluid()) ? "liquid" : "gas";
list.add(Utils.translatable("antimatter.tooltip.fluid." + liquid).withStyle(ChatFormatting.GREEN));
if (Utils.hasNoConsumeTag(JEIPlatformHelper.INSTANCE.getIngredient(ing.getDisplayedIngredient().get())))
if (Utils.hasNoConsumeTag(ing.getDisplayedIngredient().get().getIngredient(ForgeTypes.FLUID_STACK).get()))
list.add(Utils.literal("Does not get consumed in the process").withStyle(ChatFormatting.WHITE));
list.add(component);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.loading.FMLEnvironment;

import java.util.ArrayList;
Expand Down Expand Up @@ -159,9 +160,9 @@ public static void showCategories(ResourceLocation... categories){

//To perform a JEI lookup for fluid. Use defines direction.

public static void uses(FluidHolder val, boolean USE) {
public static void uses(FluidStack val, boolean USE) {
if (AntimatterAPI.isModLoaded(Ref.MOD_JEI) && !AntimatterAPI.isModLoaded(Ref.MOD_REI)){
JEIPlatformHelper.INSTANCE.uses(val, USE);
AntimatterJEIPlugin.uses(val, USE);
} else if (AntimatterAPI.isModLoaded(Ref.MOD_REI)){
REIUtils.uses(val, USE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void create(ListJS listJS) {
}
if (listJS.get(3) != null) for (Object inputFluid : ListJS.orSelf(listJS.get(3))) {
if (inputFluid instanceof FluidStackJS fluidStack){
this.fluidInput.add(FluidIngredient.of(REIUtils.fromREIFluidStack(fluidStack.getFluidStack()));
this.fluidInput.add(FluidIngredient.of(REIUtils.fromREIFluidStack(fluidStack.getFluidStack())));
} else if (inputFluid instanceof MapJS map){
this.fluidInput.add(AntimatterRecipeSerializer.getFluidIngredient(map.toJson()));
} else {
Expand Down Expand Up @@ -97,7 +97,7 @@ public void create(ListJS listJS) {
amps = 1;
special = 0;
}
if (inputItems.size() == 0 && fluidInput.size() == 0) {
if (inputItems.isEmpty() && fluidInput.isEmpty()) {
throw new IllegalStateException("No input in recipe");
}
}
Expand Down Expand Up @@ -132,12 +132,12 @@ public void deserialize() {
}
}

public static JsonElement serializeStack(FluidHolder stack) {
public static JsonElement serializeStack(FluidStack stack) {
JsonObject obj = new JsonObject();
obj.addProperty("fluid", FluidPlatformUtils.INSTANCE.getFluidId(stack.getFluid()).toString());
obj.addProperty("amount", stack.getFluidAmount());
if (stack.getCompound() != null) {
obj.add("tag", NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, stack.getCompound()));
obj.addProperty("amount", stack.getAmount());
if (stack.getTag() != null) {
obj.add("tag", NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, stack.getTag()));
}
return obj;
}
Expand Down Expand Up @@ -166,32 +166,32 @@ public static JsonElement serializeFluid(FluidIngredient stack) {

@Override
public void serialize() {
if (inputItems.size() > 0) {
if (!inputItems.isEmpty()) {
JsonArray arr = new JsonArray();
inputItems.forEach(t -> arr.add(t.toJson()));
this.json.add("inputItems", arr);
}
if (outputItems.size() > 0) {
if (!outputItems.isEmpty()) {
JsonArray arr = new JsonArray();
outputItems.forEach(t -> arr.add(t.toResultJson()));
this.json.add("outputItems", arr);
}
if (fluidInput.size() > 0) {
if (!fluidInput.isEmpty()) {
JsonArray arr = new JsonArray();
fluidInput.forEach(t -> arr.add(serializeFluid(t)));
this.json.add("inputFluids", arr);
}
if (fluidOutput.size() > 0) {
if (!fluidOutput.isEmpty()) {
JsonArray arr = new JsonArray();
fluidOutput.forEach(t -> arr.add(serializeStack(t)));
this.json.add("outputFluids", arr);
}
if (outputChances.size() > 0) {
if (!outputChances.isEmpty()) {
JsonArray arr = new JsonArray();
outputChances.forEach(arr::add);
this.json.add("outputChances", arr);
}
if (inputChances.size() > 0) {
if (!inputChances.isEmpty()) {
JsonArray arr = new JsonArray();
inputChances.forEach(arr::add);
this.json.add("inputChances", arr);
Expand Down
Loading

0 comments on commit d81cd28

Please sign in to comment.