Skip to content

Commit

Permalink
+ add KubeJs support
Browse files Browse the repository at this point in the history
+ fix #19
  • Loading branch information
cnlimiter committed Sep 16, 2023
1 parent 7f7dd2e commit 9f114d7
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 167 deletions.
25 changes: 5 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,8 @@ repositories {
maven { url = 'https://maven.blamejared.com' }
maven { url = 'https://maven.theillusivec4.top/' }
maven { url = 'https://maven.melanx.de/' }
maven {
url = "https://maven.architectury.dev"
content {
includeGroup "me.shedaniel"
}
}
maven {
url = "https://maven.saps.dev/minecraft"
content {
includeGroup "dev.latvian.mods"
}
}
maven { url = "https://maven.architectury.dev" }
maven { url = "https://maven.saps.dev/minecraft" }
maven {
name = 'Twilight Forest'
url = 'https://modmaven.dev/'
Expand Down Expand Up @@ -160,14 +150,9 @@ dependencies {
compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-forge-${minecraft_version}:${crafttweaker_version}")
compileOnly fg.deobf("curse.maven:jade-324717:${jade_id}")

// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")

// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
compileOnly fg.deobf("dev.latvian.mods:kubejs-forge:${kubejs_version}")
compileOnly fg.deobf("dev.latvian.mods:rhino-forge:${rhino_version}")
compileOnly fg.deobf("dev.architectury:architectury-forge:${architectury_version}")
}

// This block of code expands all declared replace properties in the specified resource targets.
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ mapping_channel=official
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=1.20.1


kubejs_version=2001.6.3-build.46
architectury_version=9.1.12
rhino_version=2001.2.2-build.6
## Mod Properties

# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,27 @@ public boolean matches(IItemHandler inventory) {
}

@Override
public boolean matches(Container inv, Level level) {
public boolean matches(@NotNull Container inv, @NotNull Level level) {
return this.matches(new InvWrapper(inv));
}

@Override
public NonNullList<Ingredient> getIngredients() {
public @NotNull NonNullList<Ingredient> getIngredients() {
return this.inputs;
}

@Override
public ResourceLocation getId() {
public @NotNull ResourceLocation getId() {
return this.recipeId;
}

@Override
public RecipeSerializer<?> getSerializer() {
public @NotNull RecipeSerializer<?> getSerializer() {
return ModRecipeSerializers.SHAPED_EXTREME_CRAFT_SERIALIZER.get();
}

@Override
public RecipeType<?> getType() {
public @NotNull RecipeType<?> getType() {
return ModRecipeTypes.EXTREME_CRAFT_RECIPE.get();
}

Expand All @@ -134,7 +134,7 @@ public boolean canCraftInDimensions(int width, int height) {
}

@Override
public NonNullList<ItemStack> getRemainingItems(Container inv) {
public @NotNull NonNullList<ItemStack> getRemainingItems(@NotNull Container inv) {
if (this.transformers != null) {
var remaining = NonNullList.withSize(inv.getContainerSize(), ItemStack.EMPTY);

Expand Down Expand Up @@ -179,7 +179,7 @@ public void setTransformers(Map<Integer, Function<ItemStack, ItemStack>> transfo

public static class Serializer implements RecipeSerializer<ShapedExtremeCraftingRecipe> {
@Override
public ShapedExtremeCraftingRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
public @NotNull ShapedExtremeCraftingRecipe fromJson(@NotNull ResourceLocation recipeId, @NotNull JsonObject json) {
var map = ShapedRecipe.keyFromJson(GsonHelper.getAsJsonObject(json, "key"));
var pattern = ShapedRecipe.shrink(ShapedExtremeCraftingRecipe.patternFromJson(GsonHelper.getAsJsonArray(json, "pattern")));
int width = pattern[0].length();
Expand All @@ -191,7 +191,7 @@ public ShapedExtremeCraftingRecipe fromJson(ResourceLocation recipeId, JsonObjec
}

@Override
public ShapedExtremeCraftingRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
public ShapedExtremeCraftingRecipe fromNetwork(@NotNull ResourceLocation recipeId, FriendlyByteBuf buffer) {
int width = buffer.readVarInt();
int height = buffer.readVarInt();
var inputs = NonNullList.withSize(width * height, Ingredient.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package committee.nova.mods.avaritia.init.compat.kubejs;

import dev.latvian.mods.kubejs.item.InputItem;
import dev.latvian.mods.kubejs.item.OutputItem;
import dev.latvian.mods.kubejs.recipe.RecipeJS;
import dev.latvian.mods.kubejs.recipe.RecipeKey;
import dev.latvian.mods.kubejs.recipe.component.ItemComponents;
import dev.latvian.mods.kubejs.recipe.component.NumberComponent;
import dev.latvian.mods.kubejs.recipe.component.TimeComponent;
import dev.latvian.mods.kubejs.recipe.schema.RecipeSchema;

/**
* Author cnlimiter
* CreateTime 2023/9/17 0:50
* Name CompressRecipeSchema
* Description
*/

public interface CompressRecipeSchema {
RecipeKey<InputItem[]> INGREDIENTS = ItemComponents.INPUT_ARRAY.key("ingredients");
RecipeKey<OutputItem> OUTPUT = ItemComponents.OUTPUT.key("result");
RecipeKey<Long> COMPRESS_TIME = TimeComponent.TICKS.key("timeRequired").optional(240L);
RecipeKey<Integer> MATERIAL_COUNT = NumberComponent.INT.key("materialCount").optional(1000);
RecipeSchema SCHEMA = new RecipeSchema(RecipeJS.class, RecipeJS::new, INGREDIENTS, OUTPUT, MATERIAL_COUNT, COMPRESS_TIME);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package committee.nova.mods.avaritia.init.compat.kubejs;

import committee.nova.mods.avaritia.init.registry.ModRecipeSerializers;
import dev.latvian.mods.kubejs.KubeJSPlugin;
import dev.latvian.mods.kubejs.recipe.schema.RegisterRecipeSchemasEvent;
import dev.latvian.mods.kubejs.recipe.schema.minecraft.ShapedRecipeSchema;
import dev.latvian.mods.kubejs.recipe.schema.minecraft.ShapelessRecipeSchema;

/**
* Name: Avaritia-forge / KubeJSAvaritiaPlugin
* Author: cnlimiter
* CreateTime: 2023/9/17 0:49
* Description:
*/

public class KubeJSAvaritiaPlugin extends KubeJSPlugin {

@Override
public void registerRecipeSchemas(RegisterRecipeSchemasEvent event) {
event.register(ModRecipeSerializers.SHAPED_EXTREME_CRAFT_SERIALIZER.getId(), ShapedRecipeSchema.SCHEMA);
event.register(ModRecipeSerializers.SHAPELESS_EXTREME_CRAFT_SERIALIZER.getId(), ShapelessRecipeSchema.SCHEMA);
event.register(ModRecipeSerializers.COMPRESSOR_SERIALIZER.getId(), CompressRecipeSchema.SCHEMA);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package committee.nova.mods.avaritia.init.compat.kubejs;

import dev.latvian.mods.kubejs.recipe.schema.RecipeSchema;
import dev.latvian.mods.kubejs.recipe.schema.minecraft.ShapedRecipeSchema;

import static dev.latvian.mods.kubejs.recipe.schema.minecraft.ShapedRecipeSchema.INGREDIENTS;
import static dev.latvian.mods.kubejs.recipe.schema.minecraft.ShapedRecipeSchema.RESULT;

/**
* Author cnlimiter
* CreateTime 2023/9/17 2:07
* Name ShapedExtremeCraftingRecipeSchema
* Description
*/

public interface ShapedExtremeCraftingRecipeSchema {
RecipeSchema SCHEMA = new RecipeSchema(ShapedRecipeSchema.ShapedRecipeJS.class, ShapedRecipeSchema.ShapedRecipeJS::new, INGREDIENTS, RESULT);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.ApiStatus;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -39,33 +40,6 @@ public static void onRegisterRecipes(RegisterRecipesEvent event) {
if (compressorRecipe != null)
event.register(compressorRecipe);
}

//infinity_catalyst
// NonNullList<ItemStack> catalystIngredients = NonNullList.create();
//
// SingularityRegistryHandler.getInstance().getSingularities()
// .stream()
// .filter(s -> s.getIngredient() != Ingredient.EMPTY)
// .limit(74)
// .map(SingularityUtils::getItemForSingularity)
// .forEach(catalystIngredients::add);
//
// // add others
// catalystIngredients.add(new ItemStack(Blocks.EMERALD_BLOCK));
// catalystIngredients.add(new ItemStack(ModItems.crystal_matrix_ingot.get()));
// catalystIngredients.add(new ItemStack(ModItems.neutron_ingot.get()));
// catalystIngredients.add(new ItemStack(ModItems.cosmic_meatballs.get()));
// catalystIngredients.add(new ItemStack(ModItems.ultimate_stew.get()));
// catalystIngredients.add(new ItemStack(ModItems.endest_pearl.get()));
// catalystIngredients.add(new ItemStack(ModItems.record_fragment.get()));
//
// event.register(addExtremeShapelessRecipe(
// ModItems.infinity_catalyst.get().getDefaultInstance(),
// catalystIngredients
// ));



}


Expand All @@ -83,25 +57,4 @@ private static CompressorRecipe makeSingularityRecipe(Singularity singularity) {
return new CompressorRecipe(recipeId, ingredient, output, ingredientCount, timeRequired);
}

public static ShapelessExtremeCraftingRecipe addExtremeShapelessRecipe(ItemStack result, List<ItemStack> ingredients) {
List<ItemStack> arraylist = new ArrayList<>();

for (ItemStack stack : ingredients) {
if (stack != null) {
arraylist.add(stack.copy());
} else {
throw new RuntimeException("Invalid shapeless recipes!");
}
}

return new ShapelessExtremeCraftingRecipe(ForgeRegistries.ITEMS.getKey(result.getItem()), getList(arraylist), result);
}

private static NonNullList<Ingredient> getList(List<ItemStack> arrayList) {
NonNullList<Ingredient> ingredients = NonNullList.create();
for (ItemStack stack : arrayList) {
ingredients.add(Ingredient.of(stack));
}
return ingredients;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import committee.nova.mods.avaritia.Static;
import committee.nova.mods.avaritia.common.crafting.recipe.ShapelessExtremeCraftingRecipe;
import committee.nova.mods.avaritia.common.item.singularity.Singularity;
import committee.nova.mods.avaritia.init.config.ModConfig;
import committee.nova.mods.avaritia.init.handler.SingularityRegistryHandler;
import committee.nova.mods.avaritia.init.registry.ModItems;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.conditions.ICondition;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.ApiStatus;

import java.util.ArrayList;
import java.util.List;

/**
* Description:
Expand Down Expand Up @@ -128,4 +135,28 @@ public static Singularity getSingularity(ItemStack stack) {

return null;
}


@ApiStatus.Experimental
public static ShapelessExtremeCraftingRecipe addExtremeShapelessRecipe(ItemStack result, List<ItemStack> ingredients) {
List<ItemStack> arraylist = new ArrayList<>();

for (ItemStack stack : ingredients) {
if (stack != null) {
arraylist.add(stack.copy());
} else {
throw new RuntimeException("Invalid shapeless recipes!");
}
}

return new ShapelessExtremeCraftingRecipe(ForgeRegistries.ITEMS.getKey(result.getItem()), getList(arraylist), result);
}

private static NonNullList<Ingredient> getList(List<ItemStack> arrayList) {
NonNullList<Ingredient> ingredients = NonNullList.create();
for (ItemStack stack : arrayList) {
ingredients.add(Ingredient.of(stack));
}
return ingredients;
}
}

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/resources/kubejs.classfilter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
+committee.nova.mods.avaritia.common.crafting.recipe
+committee.nova.mods.avaritia.init.compact.kubejs
Loading

0 comments on commit 9f114d7

Please sign in to comment.