Skip to content

Commit

Permalink
Almost finished. Just need to fix chemical wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Aug 29, 2024
1 parent 6fa3b7b commit 6323a27
Show file tree
Hide file tree
Showing 44 changed files with 593 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.latvian.mods.kubejs.mekanism;

import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
import dev.latvian.mods.kubejs.recipe.component.SimpleRecipeComponent;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.recipes.ingredients.ChemicalStackIngredient;
import mekanism.api.recipes.ingredients.chemical.ChemicalIngredient;
import mekanism.api.recipes.ingredients.creator.IngredientCreatorAccess;

public interface ChemicalRecipeComponents {
RecipeComponent<Chemical> CHEMICAL = new SimpleRecipeComponent<>("mekanism:chemical", Chemical.CODEC, MekanismChemicalWrapper.CHEMICAL_TYPE_INFO);
RecipeComponent<ChemicalStack> CHEMICAL_STACK = new SimpleRecipeComponent<>("mekanism:chemical_stack", ChemicalStack.OPTIONAL_CODEC, MekanismChemicalWrapper.CHEMICAL_STACK_TYPE_INFO);
RecipeComponent<ChemicalIngredient> CHEMICAL_INGREDIENT = new SimpleRecipeComponent<>("mekanism:chemical_ingredient", IngredientCreatorAccess.chemical().codec(), MekanismChemicalWrapper.CHEMICAL_INGREDIENT_TYPE_INFO);
RecipeComponent<ChemicalStackIngredient> CHEMICAL_STACK_INGREDIENT = new SimpleRecipeComponent<>("mekanism:chemical_stack_ingredient", ChemicalStackIngredient.CODEC, MekanismChemicalWrapper.CHEMICAL_STACK_INGREDIENT_TYPE_INFO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package dev.latvian.mods.kubejs.mekanism;

import com.mojang.brigadier.StringReader;
import dev.latvian.mods.rhino.type.TypeInfo;
import dev.latvian.mods.rhino.util.HideFromJS;
import mekanism.api.MekanismAPI;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.recipes.ingredients.ChemicalStackIngredient;
import mekanism.api.recipes.ingredients.chemical.ChemicalIngredient;
import mekanism.api.recipes.ingredients.chemical.EmptyChemicalIngredient;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.fluids.FluidType;
import org.codehaus.plexus.util.cli.CommandLineException;

public interface MekanismChemicalWrapper {
TypeInfo CHEMICAL_TYPE_INFO = TypeInfo.of(Chemical.class);
TypeInfo CHEMICAL_STACK_TYPE_INFO = TypeInfo.of(ChemicalStack.class);
TypeInfo CHEMICAL_INGREDIENT_TYPE_INFO = TypeInfo.of(ChemicalIngredient.class);
TypeInfo CHEMICAL_STACK_INGREDIENT_TYPE_INFO = TypeInfo.of(ChemicalStackIngredient.class);

static Chemical of(Object from) {
return switch (from) {
case null -> MekanismAPI.EMPTY_CHEMICAL;
case Chemical c -> c;
case ChemicalStack c -> c.getChemical();
default -> {
var str = from.toString();

if (str.isEmpty() || str.equals("mekanism:empty")) {
yield MekanismAPI.EMPTY_CHEMICAL;
} else {
yield MekanismAPI.CHEMICAL_REGISTRY.get(ResourceLocation.parse(str));
}
}
};
}

static ChemicalStack stack(Chemical chemical, long amount) {
return new ChemicalStack(chemical, amount);
}

private static long readAmount(StringReader reader) throws CommandLineException {
// long amount = FluidWrapper.readFluidAmount(reader);
return 0L;
}

@HideFromJS
static ChemicalStack wrapStack(Object from) {
return switch (from) {
case null -> null;
case ChemicalStack c -> c;
case Chemical c -> new ChemicalStack(c, FluidType.BUCKET_VOLUME);
default -> {
var str = from.toString();

if (str.isEmpty() || str.equals("mekanism:empty")) {
yield ChemicalStack.EMPTY;
} else {
yield new ChemicalStack(of(from), FluidType.BUCKET_VOLUME);
}
}
};
}

@HideFromJS
static ChemicalIngredient wrapIngredient(Object from) {
return EmptyChemicalIngredient.INSTANCE;
}

static ChemicalStackIngredient ingredientStack(ChemicalIngredient ingredient, long amount) {
return new ChemicalStackIngredient(ingredient, amount);
}

@HideFromJS
static ChemicalStackIngredient wrapStackIngredient(Object from) {
return new ChemicalStackIngredient(EmptyChemicalIngredient.INSTANCE, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

import dev.latvian.mods.kubejs.plugin.KubeJSPlugin;
import dev.latvian.mods.kubejs.recipe.schema.RecipeComponentFactoryRegistry;
import dev.latvian.mods.kubejs.recipe.schema.RecipeSchemaRegistry;
import dev.latvian.mods.kubejs.registry.BuilderTypeRegistry;
import dev.latvian.mods.kubejs.script.BindingRegistry;
import dev.latvian.mods.kubejs.script.DataComponentTypeInfoRegistry;
import dev.latvian.mods.kubejs.script.TypeWrapperRegistry;
import dev.latvian.mods.rhino.type.TypeInfo;
import mekanism.api.MekanismAPI;
import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import mekanism.api.recipes.ingredients.ChemicalStackIngredient;
import mekanism.api.recipes.ingredients.chemical.ChemicalIngredient;
import mekanism.common.registration.MekanismDeferredHolder;
import mekanism.common.registries.MekanismDataComponents;
import net.minecraft.core.component.DataComponentType;

import java.lang.reflect.Modifier;

public class MekanismKubeJSPlugin implements KubeJSPlugin {
@Override
Expand All @@ -19,39 +31,48 @@ public void registerBuilderTypes(BuilderTypeRegistry registry) {
});
}

@Override
public void registerBindings(BindingRegistry bindings) {
bindings.add("MekanismChemical", MekanismChemicalWrapper.class);
}

@Override
public void registerTypeWrappers(TypeWrapperRegistry registry) {
registry.register(Chemical.class, MekanismChemicalWrapper::of);
registry.register(ChemicalStack.class, MekanismChemicalWrapper::wrapStack);
registry.register(ChemicalIngredient.class, MekanismChemicalWrapper::wrapIngredient);
registry.register(ChemicalStackIngredient.class, MekanismChemicalWrapper::wrapStackIngredient);
}

@Override
public void registerRecipeComponents(RecipeComponentFactoryRegistry registry) {
registry.register(ChemicalRecipeComponents.CHEMICAL);
registry.register(ChemicalRecipeComponents.CHEMICAL_STACK);
registry.register(ChemicalRecipeComponents.CHEMICAL_INGREDIENT);
registry.register(ChemicalRecipeComponents.CHEMICAL_STACK_INGREDIENT);
}

@Override
public void registerRecipeSchemas(RecipeSchemaRegistry registry) {
/*
registry.namespace(MekanismAPI.MEKANISM_MODID)
.register("crushing", ItemToItemRecipeSchema.SCHEMA)
.register("enriching", ItemToItemRecipeSchema.SCHEMA)
.register("smelting", ItemToItemRecipeSchema.SCHEMA)
.register("chemical_infusing", ChemicalInfusingRecipeSchema.SCHEMA)
.register("combining", CombiningRecipeSchema.SCHEMA)
// separating = new ElectrolysisRecipeSerializer(ElectrolysisIRecipe.SCHEMA)
// washing = new FluidSlurryToSlurryRecipeSerializer(FluidSlurryToSlurryIRecipe.SCHEMA)
// evaporating = new FluidToFluidRecipeSerializer(FluidToFluidIRecipe.SCHEMA)
// activating = new GasToGasRecipeSerializer(ActivatingIRecipe.SCHEMA)
// centrifuging = new GasToGasRecipeSerializer(CentrifugingIRecipe.SCHEMA)
.register("crystallizing", CrystallizingRecipeSchema.SCHEMA)
.register("dissolution", ChemicalDissolutionRecipeSchema.SCHEMA)
.register("compressing", ItemAndGasToItemRecipeSchema.SCHEMA)
.register("purifying", ItemAndGasToItemRecipeSchema.SCHEMA)
.register("injecting", ItemAndGasToItemRecipeSchema.SCHEMA)
// nucleosynthesizing = new NucleosynthesizingRecipeSerializer(NucleosynthesizingIRecipe.SCHEMA)
.register("energy_conversion", EnergyConversionRecipeSchema.SCHEMA)
.register("gas_conversion", GasConversionRecipeSchema.SCHEMA)
.register("oxidizing", OxidizingRecipeSchema.SCHEMA)
// infusion_conversion = new ItemStackToInfuseTypeRecipeSerializer(InfusionConversionIRecipe.SCHEMA)
.register("metallurgic_infusing", MetallurgicInfusingRecipeSchema.SCHEMA)
.register("reaction", PressurizedReactionRecipeSchema.SCHEMA)
// rotary = new RotaryRecipeSerializer(new RotaryIRecipe.Factory())
.register("sawing", SawingRecipeSchema.SCHEMA)
;
*/
public void registerDataComponentTypeDescriptions(DataComponentTypeInfoRegistry registry) {
try {
var dctt = TypeInfo.of(DataComponentType.class);

for (var field : MekanismDataComponents.class.getDeclaredFields()) {
if (field.getType() == MekanismDeferredHolder.class
&& Modifier.isPublic(field.getModifiers())
&& Modifier.isStatic(field.getModifiers())
) {
var t = TypeInfo.of(field.getGenericType()).param(1);

if (t.is(dctt)) {
var t2 = t.param(0);
var d = (DataComponentType<?>) (((MekanismDeferredHolder) field.get(null)).get());
registry.register(d, t2);
}
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "mekanism:base/chemical_to_chemical"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"keys": [
{
"name": "output",
"role": "output",
"type": "mekanism:chemical_stack"
},
{
"name": "left_input",
"role": "input",
"type": "mekanism:chemical_stack_ingredient"
},
{
"name": "right_input",
"role": "input",
"type": "mekanism:chemical_stack_ingredient"
}
],
"unique": ["output"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"keys": [
{
"name": "output",
"role": "output",
"type": "mekanism:chemical_stack"
},
{
"name": "input",
"role": "input",
"type": "mekanism:chemical_stack_ingredient"
}
],
"unique": ["output"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"keys": [
{
"name": "output",
"role": "output",
"type": "item_stack"
},
{
"name": "input",
"role": "input",
"type": "mekanism:chemical_stack_ingredient"
}
],
"unique": ["output"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"keys": [
{
"name": "output",
"role": "output",
"type": "mekanism:chemical_stack"
},
{
"name": "fluid_input",
"role": "input",
"type": "flat_sized_fluid_ingredient"
},
{
"name": "chemical_input",
"role": "input",
"type": "mekanism:chemical_stack_ingredient"
}
],
"unique": ["output"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"keys": [
{
"name": "output",
"role": "output",
"type": "fluid_stack"
},
{
"name": "input",
"role": "input",
"type": "flat_sized_fluid_ingredient"
}
],
"unique": ["output"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"keys": [
{
"name": "output",
"role": "output",
"type": "item_stack"
},
{
"name": "item_input",
"role": "input",
"type": "flat_sized_ingredient"
},
{
"name": "chemical_input",
"role": "input",
"type": "mekanism:chemical_stack_ingredient"
},
{
"name": "per_tick_usage",
"type": "boolean"
}
],
"unique": ["output"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"keys": [
{
"name": "output",
"role": "output",
"type": "mekanism:chemical_stack"
},
{
"name": "input",
"role": "input",
"type": "flat_sized_ingredient"
}
],
"unique": ["output"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"keys": [
{
"name": "input",
"role": "input",
"type": "flat_sized_ingredient"
},
{
"name": "output",
"role": "output",
"type": "long<1,max>"
}
],
"unique": ["input"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"keys": [
{
"name": "output",
"role": "output",
"type": "item_stack"
},
{
"name": "input",
"role": "input",
"type": "flat_sized_ingredient"
}
],
"unique": ["output"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "special"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "special"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "mekanism:base/chemical_to_chemical"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "mekanism:base/item_to_chemical"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "mekanism:base/chemical_chemical_to_chemical"
}
Loading

0 comments on commit 6323a27

Please sign in to comment.