diff --git a/build.gradle b/build.gradle index 7182524b..65209049 100644 --- a/build.gradle +++ b/build.gradle @@ -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/' @@ -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. diff --git a/gradle.properties b/gradle.properties index 3430f368..e965df17 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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} diff --git a/src/main/java/committee/nova/mods/avaritia/common/crafting/recipe/ShapedExtremeCraftingRecipe.java b/src/main/java/committee/nova/mods/avaritia/common/crafting/recipe/ShapedExtremeCraftingRecipe.java index c38797d6..f79bce83 100644 --- a/src/main/java/committee/nova/mods/avaritia/common/crafting/recipe/ShapedExtremeCraftingRecipe.java +++ b/src/main/java/committee/nova/mods/avaritia/common/crafting/recipe/ShapedExtremeCraftingRecipe.java @@ -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 getIngredients() { + public @NotNull NonNullList 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(); } @@ -134,7 +134,7 @@ public boolean canCraftInDimensions(int width, int height) { } @Override - public NonNullList getRemainingItems(Container inv) { + public @NotNull NonNullList getRemainingItems(@NotNull Container inv) { if (this.transformers != null) { var remaining = NonNullList.withSize(inv.getContainerSize(), ItemStack.EMPTY); @@ -179,7 +179,7 @@ public void setTransformers(Map> transfo public static class Serializer implements RecipeSerializer { @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(); @@ -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); diff --git a/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/CompressRecipeSchema.java b/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/CompressRecipeSchema.java new file mode 100644 index 00000000..1ffc2b41 --- /dev/null +++ b/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/CompressRecipeSchema.java @@ -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 INGREDIENTS = ItemComponents.INPUT_ARRAY.key("ingredients"); + RecipeKey OUTPUT = ItemComponents.OUTPUT.key("result"); + RecipeKey COMPRESS_TIME = TimeComponent.TICKS.key("timeRequired").optional(240L); + RecipeKey MATERIAL_COUNT = NumberComponent.INT.key("materialCount").optional(1000); + RecipeSchema SCHEMA = new RecipeSchema(RecipeJS.class, RecipeJS::new, INGREDIENTS, OUTPUT, MATERIAL_COUNT, COMPRESS_TIME); + +} diff --git a/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/KubeJSAvaritiaPlugin.java b/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/KubeJSAvaritiaPlugin.java new file mode 100644 index 00000000..651604fb --- /dev/null +++ b/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/KubeJSAvaritiaPlugin.java @@ -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); + } +} diff --git a/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/ShapedExtremeCraftingRecipeSchema.java b/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/ShapedExtremeCraftingRecipeSchema.java new file mode 100644 index 00000000..285716e3 --- /dev/null +++ b/src/main/java/committee/nova/mods/avaritia/init/compat/kubejs/ShapedExtremeCraftingRecipeSchema.java @@ -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); + +} diff --git a/src/main/java/committee/nova/mods/avaritia/init/handler/DynamicRecipeHandler.java b/src/main/java/committee/nova/mods/avaritia/init/handler/DynamicRecipeHandler.java index 8a5c3790..bf47591a 100644 --- a/src/main/java/committee/nova/mods/avaritia/init/handler/DynamicRecipeHandler.java +++ b/src/main/java/committee/nova/mods/avaritia/init/handler/DynamicRecipeHandler.java @@ -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; @@ -39,33 +40,6 @@ public static void onRegisterRecipes(RegisterRecipesEvent event) { if (compressorRecipe != null) event.register(compressorRecipe); } - - //infinity_catalyst -// NonNullList 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 -// )); - - - } @@ -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 ingredients) { - List 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 getList(List arrayList) { - NonNullList ingredients = NonNullList.create(); - for (ItemStack stack : arrayList) { - ingredients.add(Ingredient.of(stack)); - } - return ingredients; - } } diff --git a/src/main/java/committee/nova/mods/avaritia/util/SingularityUtils.java b/src/main/java/committee/nova/mods/avaritia/util/SingularityUtils.java index 2ba8e739..0833332f 100644 --- a/src/main/java/committee/nova/mods/avaritia/util/SingularityUtils.java +++ b/src/main/java/committee/nova/mods/avaritia/util/SingularityUtils.java @@ -4,10 +4,12 @@ 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; @@ -15,6 +17,11 @@ 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: @@ -128,4 +135,28 @@ public static Singularity getSingularity(ItemStack stack) { return null; } + + + @ApiStatus.Experimental + public static ShapelessExtremeCraftingRecipe addExtremeShapelessRecipe(ItemStack result, List ingredients) { + List 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 getList(List arrayList) { + NonNullList ingredients = NonNullList.create(); + for (ItemStack stack : arrayList) { + ingredients.add(Ingredient.of(stack)); + } + return ingredients; + } } diff --git a/src/main/java/committee/nova/mods/avaritia/util/recipes/IngredientsCache.java b/src/main/java/committee/nova/mods/avaritia/util/recipes/IngredientsCache.java deleted file mode 100644 index 002cb1ae..00000000 --- a/src/main/java/committee/nova/mods/avaritia/util/recipes/IngredientsCache.java +++ /dev/null @@ -1,89 +0,0 @@ -package committee.nova.mods.avaritia.util.recipes; - -import net.minecraft.core.NonNullList; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.Ingredient; - -import java.util.*; - -/** - * Description: - * Author: cnlimiter - * Date: 2022/5/15 20:39 - * Version: 1.0 - */ -public class IngredientsCache { - private static final IngredientsCache INSTANCE = new IngredientsCache(); - private final Map>> lists; - - private IngredientsCache() { - this.lists = new HashMap<>(); - } - - public static IngredientsCache getInstance() { - return INSTANCE; - } - - private static List> createIngredientsList(NonNullList ingredients) { - var lists = new ArrayList(); - - for (var ingredient : ingredients) { - var items = Arrays.stream(ingredient.getItems()).map(ItemStack::getItem).toList(); - var matched = false; - - // increment quantity if there's already a matching list - for (var list : lists) { - if (list.containsAll(items)) { - list.quantity++; - matched = true; - break; - } - } - - if (!matched) { - lists.add(new ItemList(items)); - } - } - - return lists.stream() - .map(s -> s.items.stream() - .map(i -> (Component) Component.literal(s.quantity + "x ").append(i.getDefaultInstance().getHoverName())) - .toList() - ) - .toList(); - } - - public List getIngredientsList(ResourceLocation id, NonNullList ingredients) { - return this.lists.computeIfAbsent(id, r -> createIngredientsList(ingredients)) - .stream() - .map(l -> { - var index = (System.currentTimeMillis() / 2000L) % l.size(); - return l.get(Math.toIntExact(index)); - }) - .toList(); - } - - public void onResourceManagerReload(ResourceManager manager) { - this.lists.clear(); - } - - private static class ItemList { - public final List items; - private final Set itemSet; - public int quantity; - - public ItemList(List items) { - this.itemSet = new HashSet<>(items); - this.items = items; - this.quantity = 1; - } - - public boolean containsAll(Collection items) { - return this.itemSet.containsAll(items); - } - } -} diff --git a/src/main/resources/kubejs.classfilter.txt b/src/main/resources/kubejs.classfilter.txt new file mode 100644 index 00000000..210f2e17 --- /dev/null +++ b/src/main/resources/kubejs.classfilter.txt @@ -0,0 +1,2 @@ ++committee.nova.mods.avaritia.common.crafting.recipe ++committee.nova.mods.avaritia.init.compact.kubejs \ No newline at end of file diff --git a/src/main/resources/kubejs.plugins.txt b/src/main/resources/kubejs.plugins.txt new file mode 100644 index 00000000..76c872a5 --- /dev/null +++ b/src/main/resources/kubejs.plugins.txt @@ -0,0 +1 @@ +committee.nova.mods.avaritia.init.compact.kubejs.KubeJSAvaritiaPlugin \ No newline at end of file