Skip to content

Commit

Permalink
turned platform classes in integration into java services
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Oct 18, 2024
1 parent 028e38f commit b905214
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.blamejared.crafttweaker.api.fluid.IFluidStack;
import dev.architectury.injectables.annotations.ExpectPlatform;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import muramasa.antimatter.util.ImplLoader;

public class CrafttweakerUtils {
@ExpectPlatform
public static FluidHolder fromIFluidStack(IFluidStack fluidStack){
throw new AssertionError();
}
public interface CrafttweakerUtils {
CrafttweakerUtils INSTANCE = ImplLoader.load(CrafttweakerUtils.class);
FluidHolder fromIFluidStack(IFluidStack fluidStack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void addRecipe(String name, String map, IIngredient[] in, IItemStack[] ou
ResourceLocation resourceLocation = new ResourceLocation(Ref.ID, name);
List<Ingredient> input = in == null ? Collections.emptyList() : Arrays.stream(in).map(IIngredient::asVanillaIngredient).toList();
ItemStack[] itemOut = out == null ? IRecipeMap.EMPTY_ITEM : Arrays.stream(out).map(IItemStack::getInternal).toArray(ItemStack[]::new);
List<FluidIngredient> fluidIn = fIn == null ? Collections.emptyList() : Arrays.stream(fIn).map(t -> FluidIngredient.of(CrafttweakerUtils.fromIFluidStack(t))).toList();
FluidHolder[] fluidOut = fOut == null ? IRecipeMap.EMPTY_FLUID : Arrays.stream(fOut).map(CrafttweakerUtils::fromIFluidStack).toArray(FluidHolder[]::new);
List<FluidIngredient> fluidIn = fIn == null ? Collections.emptyList() : Arrays.stream(fIn).map(t -> FluidIngredient.of(CrafttweakerUtils.INSTANCE.fromIFluidStack(t))).toList();
FluidHolder[] fluidOut = fOut == null ? IRecipeMap.EMPTY_FLUID : Arrays.stream(fOut).map(CrafttweakerUtils.INSTANCE::fromIFluidStack).toArray(FluidHolder[]::new);
Recipe recipe = new Recipe(input, itemOut, fluidIn, fluidOut, duration, eu, special, amps);
recipe.setIds(resourceLocation, map);
CraftTweakerAPI.apply(new ActionAddRecipe<>(this, recipe));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
package muramasa.antimatter.integration.jei;

import dev.architectury.injectables.annotations.ExpectPlatform;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
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.gui.builder.IRecipeSlotBuilder;
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.RecipeType;
import mezz.jei.api.registration.*;
import mezz.jei.api.runtime.IJeiRuntime;
import muramasa.antimatter.Antimatter;
import muramasa.antimatter.AntimatterAPI;
import muramasa.antimatter.Ref;
import muramasa.antimatter.fluid.AntimatterFluid;
import muramasa.antimatter.integration.jei.category.MultiMachineInfoCategory;
import muramasa.antimatter.integration.jei.category.RecipeMapCategory;
import muramasa.antimatter.integration.jei.extension.JEIMaterialRecipeExtension;
import muramasa.antimatter.integration.jeirei.AntimatterJEIREIPlugin;
import muramasa.antimatter.item.ItemBattery;
import muramasa.antimatter.item.ItemMultiTextureBattery;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.machine.types.Machine;
import muramasa.antimatter.material.Material;
import muramasa.antimatter.material.MaterialTypeItem;
import muramasa.antimatter.recipe.IRecipe;
import muramasa.antimatter.recipe.Recipe;
import muramasa.antimatter.recipe.map.IRecipeMap;
Expand All @@ -40,7 +32,6 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
Expand All @@ -51,20 +42,19 @@
import net.minecraft.world.level.material.Fluid;
import org.jetbrains.annotations.NotNull;
import tesseract.TesseractCapUtils;
import tesseract.api.context.TesseractItemContext;
import tesseract.api.gt.IEnergyItem;
import tesseract.api.gt.IGTNode;
import tesseract.api.wrapper.ItemStackWrapper;

import java.util.*;
import java.util.stream.Collectors;

import static muramasa.antimatter.machine.MachineFlag.RECIPE;

@SuppressWarnings("removal")
@JeiPlugin
public class AntimatterJEIPlugin implements IModPlugin {
public static final Map<String, RecipeType<IRecipe>> RECIPE_TYPES = new Object2ObjectOpenHashMap<>();
@Getter
private static IJeiRuntime runtime;
private static IJeiHelpers helpers;

Expand All @@ -91,7 +81,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(AntimatterJEIPlugin.getFluidIngredientObjectType(), (Collection) fluidList.stream().map(f -> AntimatterJEIPlugin.getFluidObject(FluidHolder.of(f))).toList());
runtime.getIngredientManager().removeIngredientsAtRuntime(JEIPlatformHelper.INSTANCE.getFluidIngredientObjectType(), (Collection) fluidList.stream().map(f -> JEIPlatformHelper.INSTANCE.getFluidObject(FluidHolder.of(f))).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 @@ -202,39 +192,10 @@ public void registerRecipeTransferHandlers(IRecipeTransferRegistration registrat
});
}

@ExpectPlatform
public static void uses(FluidHolder val, boolean USE) {
throw new AssertionError();
}

@ExpectPlatform
public static void addFluidIngredients(IRecipeSlotBuilder builder, List<FluidHolder> stacks){
throw new AssertionError();
}

@ExpectPlatform
public static Object getFluidObject(FluidHolder fluidHolder){
throw new AssertionError();
}

@ExpectPlatform
public static IIngredientType<?> getFluidIngredientObjectType(){
throw new AssertionError();
}

@ExpectPlatform
public static FluidHolder getIngredient(ITypedIngredient<?> ingredient){
throw new AssertionError();
}

public static IJeiRuntime getRuntime() {
return runtime;
}

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 = getFluidObject(holder);
if (t instanceof FluidHolder holder) o = JEIPlatformHelper.INSTANCE.getFluidObject(holder);
String text = helpers.getModIdHelper().getFormattedModNameForModId(getRuntime().getIngredientManager().getIngredientHelper(o).getDisplayModId(o));
tooltip.add(Utils.literal(text));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package muramasa.antimatter.integration.jei;

import dev.architectury.injectables.annotations.ExpectPlatform;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.ITypedIngredient;
import muramasa.antimatter.util.ImplLoader;

import java.util.List;

public interface JEIPlatformHelper {
JEIPlatformHelper INSTANCE = ImplLoader.load(JEIPlatformHelper.class);

void uses(FluidHolder val, boolean USE);

void addFluidIngredients(IRecipeSlotBuilder builder, List<FluidHolder> stacks);

Object getFluidObject(FluidHolder fluidHolder);

IIngredientType<?> getFluidIngredientObjectType();

FluidHolder getIngredient(ITypedIngredient<?> ingredient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import muramasa.antimatter.gui.GuiData;
import muramasa.antimatter.gui.SlotData;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.integration.jei.AntimatterJEIPlugin;
import muramasa.antimatter.integration.jei.JEIPlatformHelper;
import muramasa.antimatter.integration.jeirei.renderer.IRecipeInfoRenderer;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.recipe.IRecipe;
Expand Down Expand Up @@ -203,7 +203,7 @@ 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));
AntimatterJEIPlugin.addFluidIngredients(slot, Arrays.asList(fluids.get(s).getStacks()));
JEIPlatformHelper.INSTANCE.addFluidIngredients(slot, Arrays.asList(fluids.get(s).getStacks()));
slot.setFluidRenderer((int)fluids.get(s).getAmount(), true, 16, 16);
int finalS = s;
slot.addTooltipCallback((ing, list) -> {
Expand All @@ -223,7 +223,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, IRecipe recipe, IFocusGroup
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);
AntimatterJEIPlugin.addFluidIngredients(slot, Collections.singletonList(fluids[s]));
JEIPlatformHelper.INSTANCE.addFluidIngredients(slot, Collections.singletonList(fluids[s]));
int finalS = s;
slot.addTooltipCallback((ing, list) -> {
FluidHolder stack = fluids[finalS];
Expand All @@ -247,7 +247,7 @@ private void createFluidTooltip(IRecipeSlotView ing, List<Component> list, Fluid
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(AntimatterJEIPlugin.getIngredient(ing.getDisplayedIngredient().get())))
if (Utils.hasNoConsumeTag(JEIPlatformHelper.INSTANCE.getIngredient(ing.getDisplayedIngredient().get())))
list.add(Utils.literal("Does not get consumed in the process").withStyle(ChatFormatting.WHITE));
list.add(component);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import muramasa.antimatter.gui.slot.ISlotProvider;
import muramasa.antimatter.integration.create.client.PonderIntegration;
import muramasa.antimatter.integration.jei.AntimatterJEIPlugin;
import muramasa.antimatter.integration.jei.JEIPlatformHelper;
import muramasa.antimatter.integration.rei.REIUtils;
import muramasa.antimatter.machine.BlockMachine;
import muramasa.antimatter.machine.Tier;
Expand All @@ -20,7 +21,6 @@
import muramasa.antimatter.recipe.map.IRecipeMap;
import muramasa.antimatter.recipe.map.RecipeMap;
import muramasa.antimatter.structure.Pattern;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ItemLike;
Expand All @@ -31,7 +31,6 @@
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static muramasa.antimatter.gui.SlotType.*;
import static muramasa.antimatter.gui.SlotType.FL_OUT;
Expand Down Expand Up @@ -146,7 +145,7 @@ public static void showCategory(Machine<?> type, Tier tier) {

public static void uses(FluidHolder val, boolean USE) {
if (AntimatterAPI.isModLoaded(Ref.MOD_JEI) && !AntimatterAPI.isModLoaded(Ref.MOD_REI)){
AntimatterJEIPlugin.uses(val, USE);
JEIPlatformHelper.INSTANCE.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 @@ -7,20 +7,19 @@
import dev.latvian.mods.kubejs.script.ScriptType;
import muramasa.antimatter.Ref;
import muramasa.antimatter.event.MaterialEvent;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import net.minecraft.resources.ResourceLocation;

public class AntimatterKubeJS extends KubeJSPlugin {

@Override
public void initStartup() {
super.initStartup();
onRegister();
if (AntimatterPlatformUtils.INSTANCE.isFabric()) {
KubeJSPlatform.INSTANCE.onRegister();
}
}

@ExpectPlatform
private static void onRegister(){
throw new AssertionError();
}

@Override
public void addBindings(BindingsEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package muramasa.antimatter.integration.kubejs;

import muramasa.antimatter.util.ImplLoader;

public interface KubeJSPlatform {
KubeJSPlatform INSTANCE = ImplLoader.load(KubeJSPlatform.class);
void onRegister();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import com.blamejared.crafttweaker.api.fluid.IFluidStack;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import earth.terrarium.botarium.common.fluid.utils.FluidHooks;
import muramasa.antimatter.integration.ct.CrafttweakerUtils;

public class CrafttweakerUtilsImpl {
public static FluidHolder fromIFluidStack(IFluidStack fluidStack){
public class CrafttweakerUtilsImpl implements CrafttweakerUtils {
public FluidHolder fromIFluidStack(IFluidStack fluidStack){
return FluidHooks.newFluidHolder(fluidStack.getFluid(), fluidStack.getAmount(), fluidStack.getTag().getInternal());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.RecipeIngredientRole;
import muramasa.antimatter.integration.jei.AntimatterJEIPlugin;
import muramasa.antimatter.integration.jei.JEIPlatformHelper;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.material.Fluid;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class AntimatterJEIPluginImpl {
public static void uses(FluidHolder val, boolean USE) {
public class JEIPlatformHelperImpl implements JEIPlatformHelper {
@Override
public void uses(FluidHolder val, boolean USE) {
//TODO uncomment when https://github.com/mezz/JustEnoughItems/issues/2891
IJeiFluidIngredient v = new JeiFLuidWrapper(val);
AntimatterJEIPlugin.getRuntime().getRecipesGui().show(new IFocus<IJeiFluidIngredient>() {
Expand Down Expand Up @@ -61,19 +63,23 @@ public Mode getMode() {
});
}

public static Object getFluidObject(FluidHolder fluidHolder){
@Override
public Object getFluidObject(FluidHolder fluidHolder){
return new JeiFLuidWrapper(fluidHolder);
}

public static IIngredientType<?> getFluidIngredientObjectType(){
@Override
public IIngredientType<?> getFluidIngredientObjectType(){
return FabricTypes.FLUID_STACK;
}

public static void addFluidIngredients(IRecipeSlotBuilder builder, List<FluidHolder> stacks){
@Override
public void addFluidIngredients(IRecipeSlotBuilder builder, List<FluidHolder> stacks){
builder.addIngredients(FabricTypes.FLUID_STACK, stacks.stream().map(JeiFLuidWrapper::new).collect(Collectors.toList()));
}

public static FluidHolder getIngredient(ITypedIngredient<?> ingredient){
@Override
public FluidHolder getIngredient(ITypedIngredient<?> ingredient){
IJeiFluidIngredient fluidIngredient = ingredient.getIngredient(FabricTypes.FLUID_STACK).get();
return FluidHooks.newFluidHolder(fluidIngredient.getFluid(), fluidIngredient.getAmount(), fluidIngredient.getTag().get());
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package muramasa.antimatter.integration.kubejs.fabric;

import muramasa.antimatter.fabric.AntimatterImpl;
import muramasa.antimatter.integration.kubejs.KubeJSPlatform;

public class KubeJSPlatformImpl implements KubeJSPlatform {
@Override
public void onRegister(){
new AntimatterImpl().initialize(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
muramasa.antimatter.integration.ct.fabric.CrafttweakerUtilsImpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
muramasa.antimatter.integration.jei.fabric.JEIPlatformHelperImpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
muramasa.antimatter.integration.kubejs.fabric.KubeJSPlatformImpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import com.blamejared.crafttweaker.api.fluid.IFluidStack;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import earth.terrarium.botarium.forge.fluid.ForgeFluidHolder;
import muramasa.antimatter.integration.ct.CrafttweakerUtils;

public class CrafttweakerUtilsImpl {
public static FluidHolder fromIFluidStack(IFluidStack fluidStack){
public class CrafttweakerUtilsImpl implements CrafttweakerUtils {
public FluidHolder fromIFluidStack(IFluidStack fluidStack){
return new ForgeFluidHolder(fluidStack.getInternal());
}
}
Loading

0 comments on commit b905214

Please sign in to comment.