From 469d35f4165c2e2baa2d93e09e2ec9af52252eac Mon Sep 17 00:00:00 2001 From: dmzz-yyhyy Date: Fri, 28 Jun 2024 17:05:21 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0rei=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/generator/lang/ItemTooltipLang.java | 1 + .../data/recipe/anvil/AnvilRecipe.java | 20 +- .../integration/emi/DoubleBlockIcon.java | 2 +- .../integration/emi/ui/BlockWidget.java | 2 +- .../rei/AnvilCraftCategoryIdentifier.java | 35 +++ .../rei/AnvilCraftCategoryIdentifiers.java | 133 +++++++++++ .../rei/AnvilCraftEntryIngredient.java | 53 +++++ .../integration/rei/AnvilCraftReiPlugin.java | 6 + .../rei/client/AnvilCraftReiClientPlugin.java | 152 +++++++++++++ .../rei/client/AnvilRecipeDisplay.java | 205 +++++++++++++++++ .../client/AnvilRecipeDisplayCategory.java | 206 ++++++++++++++++++ .../rei/client/DoubleBlockIcon.java | 53 +++++ .../rei/client/widget/BlockWidget.java | 111 ++++++++++ fabric/build.gradle | 9 +- .../assets/anvilcraft/lang/en_ud.json | 1 + .../assets/anvilcraft/lang/en_us.json | 1 + .../data/anvilcraft/recipes/zombie.json | 4 +- fabric/src/main/resources/fabric.mod.json | 6 + forge/build.gradle | 8 +- .../assets/anvilcraft/lang/en_ud.json | 1 + .../assets/anvilcraft/lang/en_us.json | 1 + .../data/anvilcraft/recipes/zombie.json | 4 +- .../rei/AnvilCraftReiPluginForge.java | 7 + .../AnvilCraftReiClientPluginForge.java | 7 + settings.gradle | 6 +- 25 files changed, 1009 insertions(+), 25 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifier.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifiers.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftEntryIngredient.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPlugin.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplay.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplayCategory.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/DoubleBlockIcon.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/widget/BlockWidget.java create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/lang/ItemTooltipLang.java b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/lang/ItemTooltipLang.java index 5e7404231..fc1f043ae 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/lang/ItemTooltipLang.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/lang/ItemTooltipLang.java @@ -15,5 +15,6 @@ public static void init(@NotNull RegistrateLangProvider provider) { (item, s) -> provider.add(TooltipEventListener.getTranslationKey(item), s) ); provider.add("tooltip.anvilcraft.item.reinforced_concrete", "Creeper proof"); + provider.add("tooltip.anvilcraft.item.recipe.processing.chance", "%1$s%% Chance"); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipe.java b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipe.java index d2d23fbf3..415baed0f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipe.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipe.java @@ -937,7 +937,7 @@ public static void init() { if (recipe.getIngredients().isEmpty()) return null; return new AnvilRecipe( AnvilCraft.of(recipe.getId().getPath() + "_translate_from_smelting_recipe"), - recipe.getResultItem(registryAccess) + recipe.getResultItem(registryAccess).copy() ) .setAnvilRecipeType(AnvilRecipeType.SUPER_HEATING) .addPredicates( @@ -947,7 +947,7 @@ public static void init() { ), new HasBlock(new Vec3(0, -1, 0), new HasBlock.ModBlockPredicate().block(Blocks.CAULDRON)) ) - .addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess))) + .addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess).copy().copy())) .addPredicates(HasItemIngredient.of(new Vec3(0, -1, 0), recipe.getIngredients().get(0))); } @@ -960,7 +960,7 @@ public static void init() { Ingredient ingredient = recipe.getIngredients().get(0); AnvilRecipe anvilRecipe = new AnvilRecipe( AnvilCraft.of(recipe.getId().getPath() + "_translate_from_blasting_recipe"), - recipe.getResultItem(registryAccess) + recipe.getResultItem(registryAccess).copy() ) .setAnvilRecipeType(AnvilRecipeType.SUPER_HEATING) .addPredicates( @@ -971,7 +971,7 @@ public static void init() { new HasBlock(new Vec3(0, -1, 0), new HasBlock.ModBlockPredicate().block(Blocks.CAULDRON)) ) .addPredicates(HasItemIngredient.of(new Vec3(0, -1, 0), ingredient)); - ItemStack resultItem = recipe.getResultItem(registryAccess); + ItemStack resultItem = recipe.getResultItem(registryAccess).copy(); for (ItemStack item : ingredient.getItems()) { if (item.is(ModItemTags.RAW_ORES) || item.is(ModItemTags.RAW_ORES_FORGE) @@ -992,7 +992,7 @@ public static void init() { if (recipe.getIngredients().isEmpty()) return null; return new AnvilRecipe( AnvilCraft.of(recipe.getId().getPath() + "_translate_from_smoking_recipe"), - recipe.getResultItem(registryAccess) + recipe.getResultItem(registryAccess).copy() ) .setAnvilRecipeType(AnvilRecipeType.COOKING) .addPredicates( @@ -1002,7 +1002,7 @@ public static void init() { ), new HasBlock(new Vec3(0, -1, 0), new HasBlock.ModBlockPredicate().block(Blocks.CAULDRON)) ) - .addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess))) + .addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess).copy())) .addPredicates(HasItemIngredient.of(new Vec3(0, -1, 0), recipe.getIngredients().get(0))); } @@ -1014,7 +1014,7 @@ public static void init() { if (recipe.getIngredients().isEmpty()) return null; return new AnvilRecipe( AnvilCraft.of(recipe.getId().getPath() + "_translate_from_campfire_recipe"), - recipe.getResultItem(registryAccess) + recipe.getResultItem(registryAccess).copy() ) .setAnvilRecipeType(AnvilRecipeType.COOKING) .addPredicates( @@ -1026,7 +1026,7 @@ public static void init() { new Vec3(0, -1, 0), new HasBlock.ModBlockPredicate().block(Blocks.CAULDRON)) ) - .addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess))) + .addOutcomes(new SpawnItem(new Vec3(0, -1, 0), 1, recipe.getResultItem(registryAccess).copy())) .addPredicates(HasItemIngredient.of(new Vec3(0, -1, 0), recipe.getIngredients().get(0))); } @@ -1035,10 +1035,10 @@ public static void init() { */ public static @Nullable AnvilRecipe of(@NotNull CraftingRecipe recipe, RegistryAccess registryAccess) { if (recipe.getIngredients().isEmpty()) return null; - ItemStack resultItem = recipe.getResultItem(registryAccess); + ItemStack resultItem = recipe.getResultItem(registryAccess).copy(); AnvilRecipe anvilRecipe = new AnvilRecipe( AnvilCraft.of(recipe.getId().getPath() + "_translate_from_crafting_recipe"), - recipe.getResultItem(registryAccess) + recipe.getResultItem(registryAccess).copy() ).addOutcomes(new SpawnItem(new Vec3(0.0, -1.0, 0.0), 1.0, resultItem)); if (recipe instanceof ShapedRecipe shapedRecipe) { NonNullList ingredients = shapedRecipe.getIngredients(); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/DoubleBlockIcon.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/DoubleBlockIcon.java index 07741268e..5358f56d6 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/DoubleBlockIcon.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/DoubleBlockIcon.java @@ -19,7 +19,7 @@ private DoubleBlockIcon(@Nullable BlockWidget widget1, @Nullable BlockWidget wid } /** - * REI + * EMI */ public static @NotNull DoubleBlockIcon of(@Nullable BlockState state1, @Nullable BlockState state2) { return new DoubleBlockIcon( diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/ui/BlockWidget.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/ui/BlockWidget.java index 017d11e7f..dc2b7e016 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/ui/BlockWidget.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/ui/BlockWidget.java @@ -31,7 +31,7 @@ public class BlockWidget extends Widget implements DrawableWidgetConsumer { private int size = 25; /** - * REI + * EMI */ public BlockWidget(BlockState blockState, int posY, int offsetX, int offsetY) { this.blockState = blockState; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifier.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifier.java new file mode 100644 index 000000000..360c70666 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifier.java @@ -0,0 +1,35 @@ +package dev.dubhe.anvilcraft.integration.rei; + +import dev.dubhe.anvilcraft.integration.rei.client.AnvilRecipeDisplay; +import lombok.Getter; +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import net.minecraft.network.chat.Component; + +@Getter +public class AnvilCraftCategoryIdentifier { + private CategoryIdentifier categoryIdentifier = null; + private Component title = null; + private Renderer icon = null; + + public static AnvilCraftCategoryIdentifier creat() { + return new AnvilCraftCategoryIdentifier(); + } + + public AnvilCraftCategoryIdentifier setCategoryIdentifier( + CategoryIdentifier categoryIdentifier + ) { + this.categoryIdentifier = categoryIdentifier; + return this; + } + + public AnvilCraftCategoryIdentifier setTitle(Component title) { + this.title = title; + return this; + } + + public AnvilCraftCategoryIdentifier setIcon(Renderer icon) { + this.icon = icon; + return this; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifiers.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifiers.java new file mode 100644 index 000000000..934fb849d --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifiers.java @@ -0,0 +1,133 @@ +package dev.dubhe.anvilcraft.integration.rei; + +import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipeType; +import dev.dubhe.anvilcraft.init.ModBlocks; +import dev.dubhe.anvilcraft.integration.rei.client.DoubleBlockIcon; +import dev.dubhe.anvilcraft.integration.rei.client.widget.BlockWidget; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LayeredCauldronBlock; + +import java.util.HashMap; + +public class AnvilCraftCategoryIdentifiers { + public static HashMap ALL = new HashMap<>(); + public static final AnvilCraftCategoryIdentifier STAMPING = register( + AnvilRecipeType.STAMPING, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "stamping")) + .setTitle(Component.translatable("emi.category.anvilcraft.stamping")) + .setIcon(new BlockWidget(ModBlocks.STAMPING_PLATFORM.getDefaultState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier SIEVING = register( + AnvilRecipeType.SIEVING, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "sieving")) + .setTitle(Component.translatable("emi.category.anvilcraft.sieving")) + .setIcon(new BlockWidget(Blocks.SCAFFOLDING.defaultBlockState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier BULGING = register( + AnvilRecipeType.BULGING, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "bulging")) + .setTitle(Component.translatable("emi.category.anvilcraft.bulging")) + .setIcon(new BlockWidget(Blocks.WATER_CAULDRON.defaultBlockState() + .setValue(LayeredCauldronBlock.LEVEL, 3), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier BULGING_LIKE = register( + AnvilRecipeType.BULGING_LIKE, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "bulging_like")) + .setTitle(Component.translatable("emi.category.anvilcraft.bulging_like")) + .setIcon(new BlockWidget(Blocks.CAULDRON.defaultBlockState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier FLUID_HANDLING = register( + AnvilRecipeType.FLUID_HANDLING, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "fluid_handling")) + .setTitle(Component.translatable("emi.category.anvilcraft.fluid_handling")) + .setIcon(new BlockWidget(Blocks.WATER_CAULDRON.defaultBlockState() + .setValue(LayeredCauldronBlock.LEVEL, 3), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier CRYSTALLIZE = register( + AnvilRecipeType.CRYSTALLIZE, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "crystallize")) + .setTitle(Component.translatable("emi.category.anvilcraft.crystallize")) + .setIcon(new BlockWidget(Blocks.POWDER_SNOW_CAULDRON.defaultBlockState() + .setValue(LayeredCauldronBlock.LEVEL, 3), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier COMPACTION = register( + AnvilRecipeType.COMPACTION, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "compaction")) + .setTitle(Component.translatable("emi.category.anvilcraft.compaction")) + .setIcon(new BlockWidget(Blocks.ANVIL.defaultBlockState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier COMPRESS = register( + AnvilRecipeType.COMPRESS, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "compress")) + .setTitle(Component.translatable("emi.category.anvilcraft.compress")) + .setIcon(new BlockWidget(Blocks.CAULDRON.defaultBlockState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier COOKING = register( + AnvilRecipeType.COOKING, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "cooking")) + .setTitle(Component.translatable("emi.category.anvilcraft.cooking")) + .setIcon(DoubleBlockIcon.of(Blocks.CAULDRON, Blocks.CAMPFIRE))); + public static final AnvilCraftCategoryIdentifier ITEM_INJECT = register( + AnvilRecipeType.ITEM_INJECT, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "item_inject")) + .setTitle(Component.translatable("emi.category.anvilcraft.item_inject")) + .setIcon(new BlockWidget(Blocks.IRON_ORE.defaultBlockState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier BLOCK_SMASH = register( + AnvilRecipeType.BLOCK_SMASH, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "block_smash")) + .setTitle(Component.translatable("emi.category.anvilcraft.block_smash")) + .setIcon(new BlockWidget(Blocks.ANVIL.defaultBlockState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier ITEM_SMASH = register( + AnvilRecipeType.ITEM_SMASH, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "item_smash")) + .setTitle(Component.translatable("emi.category.anvilcraft.item_smash")) + .setIcon(new BlockWidget(Blocks.IRON_TRAPDOOR.defaultBlockState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier SQUEEZE = register( + AnvilRecipeType.SQUEEZE, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "squeeze")) + .setTitle(Component.translatable("emi.category.anvilcraft.squeeze")) + .setIcon(new BlockWidget(Blocks.ANVIL.defaultBlockState(), 0, 0, 0))); + public static final AnvilCraftCategoryIdentifier SUPER_HEATING = register( + AnvilRecipeType.SUPER_HEATING, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "super_heating")) + .setTitle(Component.translatable("emi.category.anvilcraft.super_heating")) + .setIcon(DoubleBlockIcon.of(Blocks.CAULDRON, ModBlocks.HEATER.get()))); + + public static final AnvilCraftCategoryIdentifier TIMEWARP = register( + AnvilRecipeType.TIMEWARP, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "timewarp")) + .setTitle(Component.translatable("emi.category.anvilcraft.timewarp")) + .setIcon(DoubleBlockIcon.of(Blocks.CAULDRON, ModBlocks.CORRUPTED_BEACON.get()))); + + public static final AnvilCraftCategoryIdentifier GENERIC = register( + AnvilRecipeType.GENERIC, + AnvilCraftCategoryIdentifier.creat() + .setCategoryIdentifier(CategoryIdentifier.of(AnvilCraft.MOD_ID, "generic")) + .setTitle(Component.translatable("emi.category.anvilcraft.generic")) + .setIcon(new BlockWidget(Blocks.ANVIL.defaultBlockState(), 0, 0, 0))); + + public static AnvilCraftCategoryIdentifier register( + AnvilRecipeType anvilRecipeType, + AnvilCraftCategoryIdentifier anvilCraftCategoryIdentifier + ) { + ALL.put(anvilRecipeType, anvilCraftCategoryIdentifier); + return anvilCraftCategoryIdentifier; + } + + public static AnvilCraftCategoryIdentifier get( + AnvilRecipeType anvilRecipeType + ) { + if (!ALL.containsKey(anvilRecipeType)) return AnvilCraftCategoryIdentifiers.GENERIC; + return ALL.get(anvilRecipeType); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftEntryIngredient.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftEntryIngredient.java new file mode 100644 index 000000000..c5af854b7 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftEntryIngredient.java @@ -0,0 +1,53 @@ +package dev.dubhe.anvilcraft.integration.rei; + +import dev.dubhe.anvilcraft.data.recipe.anvil.RecipeOutcome; +import dev.dubhe.anvilcraft.data.recipe.anvil.outcome.SelectOne; +import dev.dubhe.anvilcraft.data.recipe.anvil.outcome.SpawnItem; +import lombok.Getter; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.world.item.ItemStack; + +import java.util.HashMap; + +@Getter +public class AnvilCraftEntryIngredient { + final EntryIngredient entryIngredient; + final float chance; + final boolean isSelectOne; + public HashMap, Float> selectOneChanceMap = new HashMap<>(); + + private AnvilCraftEntryIngredient(EntryIngredient entryIngredient, float chance, boolean isSelectOne) { + this.entryIngredient = entryIngredient; + this.chance = chance; + this.isSelectOne = isSelectOne; + } + + public static AnvilCraftEntryIngredient of(EntryIngredient entryIngredient) { + return new AnvilCraftEntryIngredient(entryIngredient, 1f, false); + } + + public static AnvilCraftEntryIngredient of(EntryIngredient entryIngredient, float chance) { + return new AnvilCraftEntryIngredient(entryIngredient, chance, false); + } + + /** + * 从{@link SelectOne}创建{@link AnvilCraftEntryIngredient} + * + * @param selectOne {@link SelectOne} + * @return {@link AnvilCraftEntryIngredient} + */ + public static AnvilCraftEntryIngredient of(SelectOne selectOne) { + HashMap, Float> selectOneChanceMap = new HashMap<>(); + for (RecipeOutcome recipeOutcome : selectOne.getOutcomes()) { + if (recipeOutcome instanceof SpawnItem spawnItem) { + selectOneChanceMap.put(EntryStacks.of(spawnItem.getResult()), (float) spawnItem.getChance()); + } + } + AnvilCraftEntryIngredient anvilCraftEntryIngredient = + new AnvilCraftEntryIngredient(EntryIngredient.of(selectOneChanceMap.keySet()), 1, true); + anvilCraftEntryIngredient.selectOneChanceMap = selectOneChanceMap; + return anvilCraftEntryIngredient; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPlugin.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPlugin.java new file mode 100644 index 000000000..af260ace7 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPlugin.java @@ -0,0 +1,6 @@ +package dev.dubhe.anvilcraft.integration.rei; + +import me.shedaniel.rei.api.common.plugins.REIServerPlugin; + +public class AnvilCraftReiPlugin implements REIServerPlugin { +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java new file mode 100644 index 000000000..2d0339b59 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java @@ -0,0 +1,152 @@ +package dev.dubhe.anvilcraft.integration.rei.client; + +import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; +import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipeType; +import dev.dubhe.anvilcraft.init.ModBlocks; +import dev.dubhe.anvilcraft.integration.rei.AnvilCraftCategoryIdentifiers; +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; +import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.world.level.block.Blocks; + +public class AnvilCraftReiClientPlugin implements REIClientPlugin { + @Override + public void registerCategories(CategoryRegistry registry) { + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.STAMPING)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.SIEVING)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.BULGING)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.BULGING_LIKE)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.FLUID_HANDLING)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.CRYSTALLIZE)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.COMPACTION)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.COMPRESS)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.COOKING)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.ITEM_INJECT)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.BLOCK_SMASH)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.ITEM_SMASH)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.SQUEEZE)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.SUPER_HEATING)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.TIMEWARP)); + registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.GENERIC)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.STAMPING.getCategoryIdentifier(), + EntryStacks.of(ModBlocks.STAMPING_PLATFORM.get()), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.SIEVING.getCategoryIdentifier(), + EntryStacks.of(Blocks.SCAFFOLDING), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.BULGING.getCategoryIdentifier(), + EntryStacks.of(Blocks.WATER_CAULDRON), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.BULGING_LIKE.getCategoryIdentifier(), + EntryStacks.of(Blocks.CAULDRON), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.FLUID_HANDLING.getCategoryIdentifier(), + EntryStacks.of(Blocks.WATER_CAULDRON), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.CRYSTALLIZE.getCategoryIdentifier(), + EntryStacks.of(Blocks.POWDER_SNOW_CAULDRON), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.COMPACTION.getCategoryIdentifier(), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.COMPRESS.getCategoryIdentifier(), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.COOKING.getCategoryIdentifier(), + EntryStacks.of(Blocks.CAMPFIRE), + EntryStacks.of(Blocks.SOUL_CAMPFIRE), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.ITEM_INJECT.getCategoryIdentifier(), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.BLOCK_SMASH.getCategoryIdentifier(), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.ITEM_SMASH.getCategoryIdentifier(), + EntryStacks.of(Blocks.IRON_TRAPDOOR), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.SQUEEZE.getCategoryIdentifier(), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.SUPER_HEATING.getCategoryIdentifier(), + EntryStacks.of(Blocks.CAULDRON), + EntryStacks.of(ModBlocks.HEATER), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.TIMEWARP.getCategoryIdentifier(), + EntryStacks.of(ModBlocks.CORRUPTED_BEACON), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + + registry.addWorkstations(AnvilCraftCategoryIdentifiers.GENERIC.getCategoryIdentifier(), + EntryStacks.of(ModBlocks.ROYAL_ANVIL), + EntryStacks.of(Blocks.ANVIL), + EntryStacks.of(Blocks.CHIPPED_ANVIL), + EntryStacks.of(Blocks.DAMAGED_ANVIL)); + } + + @Override + public void registerDisplays(DisplayRegistry registry) { + AnvilRecipeManager.getAnvilRecipeList() + .stream() + .filter(recipe -> recipe.getAnvilRecipeType() != AnvilRecipeType.MULTIBLOCK_CRAFTING) + .forEach(recipe -> + registry.add(AnvilRecipeDisplay.of( + AnvilCraftCategoryIdentifiers.get(recipe.getAnvilRecipeType()), + recipe))); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplay.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplay.java new file mode 100644 index 000000000..cb30e619a --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplay.java @@ -0,0 +1,205 @@ +package dev.dubhe.anvilcraft.integration.rei.client; + +import com.google.common.collect.ImmutableSet; +import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe; +import dev.dubhe.anvilcraft.data.recipe.anvil.RecipeOutcome; +import dev.dubhe.anvilcraft.data.recipe.anvil.RecipePredicate; +import dev.dubhe.anvilcraft.data.recipe.anvil.outcome.SelectOne; +import dev.dubhe.anvilcraft.data.recipe.anvil.outcome.SetBlock; +import dev.dubhe.anvilcraft.data.recipe.anvil.outcome.SpawnItem; +import dev.dubhe.anvilcraft.data.recipe.anvil.predicate.HasBlock; +import dev.dubhe.anvilcraft.data.recipe.anvil.predicate.HasBlockIngredient; +import dev.dubhe.anvilcraft.data.recipe.anvil.predicate.HasFluidCauldron; +import dev.dubhe.anvilcraft.data.recipe.anvil.predicate.HasItem; +import dev.dubhe.anvilcraft.integration.rei.AnvilCraftCategoryIdentifier; +import dev.dubhe.anvilcraft.integration.rei.AnvilCraftEntryIngredient; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.basic.BasicDisplay; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.core.Holder; +import net.minecraft.core.NonNullList; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +public class AnvilRecipeDisplay extends BasicDisplay { + final AnvilCraftCategoryIdentifier anvilCraftCategoryIdentifier; + final List inputBlockStates; + final List outputBlockStates; + final List inputItems; + final List outputItems; + + private AnvilRecipeDisplay( + @NotNull AnvilCraftCategoryIdentifier anvilCraftCategoryIdentifier, + @NotNull List inputBlockStates, + @NotNull List outputBlockStates, + @NotNull List inputItems, + @NotNull List outputItems, + @NotNull List inputs, + @NotNull List outputs, + @NotNull ResourceLocation location + ) { + super(inputs, outputs, Optional.of(location)); + this.anvilCraftCategoryIdentifier = anvilCraftCategoryIdentifier; + this.inputBlockStates = inputBlockStates; + this.outputBlockStates = outputBlockStates; + this.inputItems = inputItems; + this.outputItems = outputItems; + } + + /** + * 创建AnvilRecipeDisplay + * + * @param anvilCraftCategoryIdentifier 铁砧工艺类别标识符 + * @param anvilRecipe 铁砧配方 + * @return {@link AnvilRecipeDisplay} + */ + @SuppressWarnings("unchecked") + public static , V extends T> AnvilRecipeDisplay of( + AnvilCraftCategoryIdentifier anvilCraftCategoryIdentifier, + AnvilRecipe anvilRecipe) { + ArrayList inputs = new ArrayList<>(); + ArrayList outputs = new ArrayList<>(); + NonNullList inputBlockStates = NonNullList.withSize(2, Blocks.AIR.defaultBlockState()); + NonNullList outputBlockStates = NonNullList.withSize(2, Blocks.AIR.defaultBlockState()); + ArrayList inputItems = new ArrayList<>(); + ArrayList outputItems = new ArrayList<>(); + for (RecipePredicate recipePredicate : anvilRecipe.getPredicates()) { + if (recipePredicate instanceof HasBlock hasBlock) { + boolean flag = hasBlock instanceof HasBlockIngredient; + HasBlock.ModBlockPredicate matchBlock = hasBlock.getMatchBlock(); + TagKey tag = matchBlock.getTag(); + Map properties = matchBlock.getProperties(); + Set blockSet = matchBlock.getBlocks(); + if (tag != null) blockSet.addAll( + BuiltInRegistries.BLOCK.getOrCreateTag(tag).stream().map(Holder::value).toList() + ); + List blocks = blockSet.stream() + .map(block1 -> { + BlockState workBlockState = block1.defaultBlockState(); + ImmutableSet> keySet = workBlockState.getValues().keySet(); + for (Property property : keySet) { + if (!properties.containsKey(property.getName())) continue; + String value = properties.get(property.getName()); + Optional first = property.getAllValues() + .map(Property.Value::value) + .filter(v -> value.equals(v.toString())) + .findFirst(); + if (first.isEmpty()) continue; + workBlockState = workBlockState.setValue((Property) property, (V) first.get()); + } + return workBlockState; + }) + .toList(); + if (hasBlock.getOffset().equals(new Vec3(0.0d, -1.0d, 0.0d))) { + inputBlockStates.set(0, blocks.get(0)); + if (!flag) outputBlockStates.set(0, blocks.get(0)); + continue; + } + if (hasBlock.getOffset().equals(new Vec3(0.0d, -2.0d, 0.0d))) { + inputBlockStates.set(1, blocks.get(0)); + if (!flag) outputBlockStates.set(1, blocks.get(0)); + continue; + } + inputs.add(EntryIngredient.of( + hasBlock.getMatchBlock().getBlocks().stream().map(EntryStacks::of).collect(Collectors.toList())) + ); + } else if (recipePredicate instanceof HasFluidCauldron hasFluidCauldron) { + if (hasFluidCauldron.getOffset().equals(new Vec3(0.0d, -1.0d, 0.0d))) { + inputBlockStates.set(0, hasFluidCauldron.getMatchBlock().defaultBlockState()); + outputBlockStates.set(0, hasFluidCauldron.getMatchBlock().defaultBlockState()); + continue; + } + if (hasFluidCauldron.getOffset().equals(new Vec3(0.0d, -2.0d, 0.0d))) { + inputBlockStates.set(1, hasFluidCauldron.getMatchBlock().defaultBlockState()); + outputBlockStates.set(0, hasFluidCauldron.getMatchBlock().defaultBlockState()); + continue; + } + inputs.add(EntryIngredient.of(EntryStacks.of(hasFluidCauldron.getMatchBlock()))); + } else if (recipePredicate instanceof HasItem hasItem && hasItem.getMatchItem().count.getMin() != null) { + EntryIngredient entryIngredient = + !hasItem.getMatchItem().getItems().isEmpty() + ? EntryIngredient.of( + hasItem.getMatchItem().getItems().stream() + .map(item -> + EntryStacks.of( + new ItemStack(item, hasItem.getMatchItem().count.getMin()) + )) + .collect(Collectors.toList())) + : EntryIngredient.of( + StreamSupport.stream( + BuiltInRegistries.ITEM.getTagOrEmpty( + Objects.requireNonNull(hasItem.getMatchItem().getTag()) + ).spliterator(), + false) + .map(itemHolder -> EntryStacks.of(new ItemStack( + itemHolder, + hasItem.getMatchItem().count.getMin()))) + .toList()); + inputs.add(entryIngredient); + inputItems.add(entryIngredient); + } + } + for (RecipeOutcome recipeOutcome : anvilRecipe.getOutcomes()) { + if (recipeOutcome instanceof SpawnItem spawnItem) { + outputs.add(EntryIngredient.of(EntryStacks.of(spawnItem.getResult()))); + outputItems.add(AnvilCraftEntryIngredient.of( + EntryIngredient.of(EntryStacks.of(spawnItem.getResult())), + (float) spawnItem.getChance()) + ); + } else if (recipeOutcome instanceof SetBlock setBlock) { + if (setBlock.getOffset().equals(new Vec3(0.0d, -1.0d, 0.0d))) { + outputBlockStates.set(0, setBlock.getResult()); + continue; + } + if (setBlock.getOffset().equals(new Vec3(0.0d, -2.0d, 0.0d))) { + outputBlockStates.set(1, setBlock.getResult()); + continue; + } + outputs.add(EntryIngredient.of(EntryStacks.of(setBlock.getResult().getBlock()))); + } else if (recipeOutcome instanceof SelectOne selectOne) { + ArrayList> entryStacks = new ArrayList<>(); + for (RecipeOutcome selectOneOutcome : selectOne.getOutcomes()) { + if (selectOneOutcome instanceof SpawnItem spawnItem) { + entryStacks.add(EntryStacks.of(spawnItem.getResult())); + } else if (selectOneOutcome instanceof SetBlock setBlock) { + entryStacks.add(EntryStacks.of(setBlock.getResult().getBlock())); + } + } + EntryIngredient selectOneIngredient = EntryIngredient.of(entryStacks); + outputs.add(selectOneIngredient); + outputItems.add(AnvilCraftEntryIngredient.of(selectOne)); + } + } + return new AnvilRecipeDisplay( + anvilCraftCategoryIdentifier, + inputBlockStates, outputBlockStates, + inputItems, outputItems, + inputs, outputs, + anvilRecipe.getId() + ); + } + + @Override + public CategoryIdentifier getCategoryIdentifier() { + return anvilCraftCategoryIdentifier.getCategoryIdentifier(); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplayCategory.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplayCategory.java new file mode 100644 index 000000000..eba4046bf --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplayCategory.java @@ -0,0 +1,206 @@ +package dev.dubhe.anvilcraft.integration.rei.client; + +import com.google.common.collect.Lists; +import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.integration.rei.AnvilCraftCategoryIdentifier; +import dev.dubhe.anvilcraft.integration.rei.AnvilCraftEntryIngredient; +import dev.dubhe.anvilcraft.integration.rei.client.widget.BlockWidget; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.gui.widgets.Slot; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.client.util.ClientEntryStacks; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import net.minecraft.ChatFormatting; +import net.minecraft.core.Direction; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.AnvilBlock; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec2; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class AnvilRecipeDisplayCategory implements DisplayCategory { + public static final ResourceLocation REI_GUI_TEXTURES = AnvilCraft.of("textures/gui/container/emi/emi.png"); + protected static final BlockState ANVIL_BLOCK_STATE = Blocks.ANVIL + .defaultBlockState() + .setValue(AnvilBlock.FACING, Direction.WEST); + final AnvilCraftCategoryIdentifier anvilCraftCategoryIdentifier; + + public AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifier anvilCraftCategoryIdentifier) { + this.anvilCraftCategoryIdentifier = anvilCraftCategoryIdentifier; + } + + @Override + public CategoryIdentifier getCategoryIdentifier() { + return anvilCraftCategoryIdentifier.getCategoryIdentifier(); + } + + @Override + public Component getTitle() { + return anvilCraftCategoryIdentifier.getTitle(); + } + + @Override + public Renderer getIcon() { + return anvilCraftCategoryIdentifier.getIcon(); + } + + @Override + public int getDisplayHeight() { + return 84; + } + + @Override + public int getDisplayWidth(AnvilRecipeDisplay display) { + return 266; + } + + @Override + public List setupDisplay(AnvilRecipeDisplay display, Rectangle bounds) { + Point startPoint = new Point(bounds.getCenterX() - 133, bounds.getCenterY() - 42); + List widgets = Lists.newArrayList(); + widgets.add(Widgets.createRecipeBase(bounds)); + this.addStraightArrow(widgets, startPoint.x + 120, startPoint.y + 41); + if (!display.inputItems.isEmpty()) { + this.addInputArrow(widgets, startPoint.x + 72, startPoint.y + 32); + this.addInputSlots(widgets, startPoint, display.inputItems); + } + if (!display.outputItems.isEmpty()) { + this.addOutputArrow(widgets, startPoint.x + 163, startPoint.y + 30); + this.addOutputs(widgets, startPoint, display.outputItems); + } + widgets.add(new BlockWidget(ANVIL_BLOCK_STATE, 1, startPoint.x + 90, startPoint.y + 25)); + widgets.add(new BlockWidget(display.inputBlockStates.get(1), -2, startPoint.x + 90, startPoint.y + 25)); + widgets.add(new BlockWidget(display.inputBlockStates.get(0), -1, startPoint.x + 90, startPoint.y + 25)); + widgets.add(new BlockWidget(ANVIL_BLOCK_STATE, 0, startPoint.x + 135, startPoint.y + 25)); + widgets.add(new BlockWidget(display.outputBlockStates.get(1), -2, startPoint.x + 135, startPoint.y + 25)); + widgets.add(new BlockWidget(display.outputBlockStates.get(0), -1, startPoint.x + 135, startPoint.y + 25)); + return widgets; + } + + protected void addStraightArrow(List widgets, int x, int y) { + widgets.add(Widgets.createTexturedWidget(REI_GUI_TEXTURES, x, y, 0, 19, 12, 11)); + widgets.add(Widgets.createTexturedWidget(REI_GUI_TEXTURES, x, y, 0, 19, 12, 11)); + } + + protected void addInputArrow(List widgets, int x, int y) { + widgets.add(Widgets.createTexturedWidget(REI_GUI_TEXTURES, x, y, 0, 31, 16, 8)); + } + + protected void addOutputArrow(List widgets, int x, int y) { + widgets.add(Widgets.createTexturedWidget(REI_GUI_TEXTURES, x, y, 0, 40, 16, 10)); + } + + protected void addInputSlots(List widgets, Point startPoint, List inputs) { + List posList = this.getSlotsPosList(inputs.size()); + Vec2 size = this.getSlotsComposeSize(inputs.size()); + int x = inputs.size() == 1 ? startPoint.x + 40 : startPoint.x + (int) ((26 - size.x / 2) + 10); + int y = startPoint.y + (int) ((26 - size.y / 2) + 15); + Iterator ingredientIterator = inputs.iterator(); + for (Vec2 vec2 : posList) { + this.addSlot(ingredientIterator.next(), (int) (x + vec2.x), (int) (y + vec2.y), widgets); + } + } + + protected List getSlotsPosList(int length) { + ArrayList vec2List = new ArrayList<>(); + final int modelNumber = length <= 4 ? 2 : 3; + for (int index = 0; index < length; index++) { + vec2List.add(new Vec2( + 20 * (index % modelNumber), + 20 * (int) ((float) index / modelNumber) + )); + } + return vec2List; + } + + protected Vec2 getSlotsComposeSize(int length) { + if (length <= 0) return Vec2.ZERO; + if (length == 1) return new Vec2(18, 18); + final int modelNumber = length <= 4 ? 2 : 3; + return new Vec2( + modelNumber * 20 + (modelNumber - 1) * 2, + (int) ((float) length / modelNumber) * 20 + ((int) ((float) length / modelNumber) - 1) * 2 + ); + } + + protected void addSlot(EntryIngredient ingredient, int x, int y, List widgets) { + this.addSimpleSlot(ingredient, x, y, widgets); + } + + + protected void addSlot(AnvilCraftEntryIngredient ingredient, int x, int y, List widgets) { + if (ingredient.isSelectOne()) { + this.addSelectOneSlot(ingredient, x, y, widgets); + return; + } + if (ingredient.getChance() < 1) { + this.addChanceSlot(ingredient, x, y, widgets); + return; + } + this.addSimpleSlot(ingredient.getEntryIngredient(), x, y, widgets); + } + + protected void addSimpleSlot(EntryIngredient ingredient, int x, int y, List widgets) { + widgets.add(Widgets.createTexturedWidget(REI_GUI_TEXTURES, x, y, 0, 0, 18, 18)); + widgets.add(Widgets.createSlot(new Point(x + 1, y + 1)) + .entries(ingredient) + .disableBackground()); + } + + protected void addChanceSlot(AnvilCraftEntryIngredient ingredient, int x, int y, List widgets) { + widgets.add(Widgets.createTexturedWidget(REI_GUI_TEXTURES, x, y, 19, 0, 18, 18)); + Slot chanceSlot = Widgets.createSlot(new Point(x + 1, y + 1)) + .entries(ingredient.getEntryIngredient()) + .disableBackground(); + ClientEntryStacks.setTooltipProcessor(chanceSlot.getCurrentEntry(), (entryStack, tooltip) -> { + float chance = ingredient.getChance(); + if (chance != 1) + tooltip.add(Component.translatable("tooltip.anvilcraft.item.recipe.processing.chance", + chance < 0.01 ? "<1" : (int) (chance * 100)) + .withStyle(ChatFormatting.GOLD)); + return tooltip; + }); + widgets.add(chanceSlot); + } + + protected void addSelectOneSlot(AnvilCraftEntryIngredient ingredient, int x, int y, List widgets) { + widgets.add(Widgets.createTexturedWidget(REI_GUI_TEXTURES, x, y, 38, 0, 18, 18)); + Slot selectOneSlot = Widgets.createSlot(new Point(x + 1, y + 1)) + .entries(ingredient.getEntryIngredient()) + .disableBackground(); + ClientEntryStacks.setTooltipProcessor(selectOneSlot.getCurrentEntry(), (entryStack, tooltip) -> { + if (!ingredient.selectOneChanceMap.containsKey(entryStack)) return tooltip; + float chance = ingredient.selectOneChanceMap.get(entryStack); + if (chance != 1) + tooltip.add(Component.translatable("tooltip.anvilcraft.item.recipe.processing.chance", + chance < 0.01 ? "<1" : (int) (chance * 100)) + .withStyle(ChatFormatting.GOLD)); + return tooltip; + }); + widgets.add(selectOneSlot); + } + + protected void addOutputs(List widgets, Point startPoint, List outputs) { + int outputSize = outputs.size(); + List posList = this.getSlotsPosList(outputSize); + Vec2 composeSize = this.getSlotsComposeSize(outputSize); + int x = outputSize == 1 ? startPoint.x + 190 : startPoint.x + (int) ((26 - composeSize.x / 2) + 190); + int y = startPoint.y + (int) ((26 - composeSize.y / 2) + 15); + Iterator entryIngredientIterator = outputs.iterator(); + for (Vec2 vec2 : posList) { + if (entryIngredientIterator.hasNext()) { + this.addSlot(entryIngredientIterator.next(), (int) (x + vec2.x), (int) (y + vec2.y), widgets); + } + } + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/DoubleBlockIcon.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/DoubleBlockIcon.java new file mode 100644 index 000000000..1dd0e35b1 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/DoubleBlockIcon.java @@ -0,0 +1,53 @@ +package dev.dubhe.anvilcraft.integration.rei.client; + +import com.mojang.blaze3d.vertex.PoseStack; +import dev.dubhe.anvilcraft.integration.rei.client.widget.BlockWidget; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.Renderer; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class DoubleBlockIcon implements Renderer { + private final @Nullable BlockWidget widget1; + private final @Nullable BlockWidget widget2; + + private DoubleBlockIcon(@Nullable BlockWidget widget1, @Nullable BlockWidget widget2) { + this.widget1 = widget1; + this.widget2 = widget2; + } + + /** + * REI + */ + public static @NotNull DoubleBlockIcon of(@Nullable BlockState state1, @Nullable BlockState state2) { + return new DoubleBlockIcon( + state1 != null ? new BlockWidget(state1, 0, 0, 0) : null, + state2 != null ? new BlockWidget(state2, -1, 0, 0) : null + ); + } + + public static @NotNull DoubleBlockIcon of(@NotNull Block block1, @NotNull Block block2) { + return DoubleBlockIcon.of(block1.defaultBlockState(), block2.defaultBlockState()); + } + + @Override + public void render(GuiGraphics graphics, Rectangle bounds, int mouseX, int mouseY, float delta) { + PoseStack pose = graphics.pose(); + pose.pushPose(); + pose.translate(bounds.x + 1, bounds.y - 0.5d, 0.0d); + if (this.widget1 != null) { + this.widget1.setSize(12); + this.widget1.setOffsetX(1); + this.widget1.render(graphics, 0, 0, delta); + } + if (this.widget2 != null) { + this.widget2.setSize(12); + this.widget2.setOffsetX(1); + this.widget2.render(graphics, 0, 0, delta); + } + pose.popPose(); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/widget/BlockWidget.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/widget/BlockWidget.java new file mode 100644 index 000000000..3bf7819f1 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/widget/BlockWidget.java @@ -0,0 +1,111 @@ +package dev.dubhe.anvilcraft.integration.rei.client.widget; + +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.vertex.PoseStack; +import dev.dubhe.anvilcraft.util.BlockStateRender; +import lombok.Setter; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; +import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; +import me.shedaniel.rei.api.client.view.ViewSearchBuilder; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + + +@Setter +public class BlockWidget extends WidgetWithBounds implements Renderer { + private final BlockState blockState; + private final int posY; + private int offsetX; + private int offsetY; + private int size = 25; + private boolean wasClicked = false; + + /** + * REI BlockWidget + * + * @param blockState 显示的方块状态 + * @param posY 显示的y坐标 + * @param offsetX x轴偏移量 + * @param offsetY y轴偏移量 + */ + public BlockWidget(BlockState blockState, int posY, int offsetX, int offsetY) { + this.blockState = blockState; + this.posY = posY; + this.offsetX = offsetX; + this.offsetY = offsetY; + } + + @Override + public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + PoseStack pose = guiGraphics.pose(); + pose.pushPose(); + pose.translate(this.offsetX, this.offsetY, 0.0); + BlockStateRender.renderBlock(this.blockState, this.posY, guiGraphics, this.size); + pose.popPose(); + Tooltip tooltip = getTooltip(TooltipContext.ofMouse()); + if (containsMouse(mouseX, mouseY) && tooltip != null) { + tooltip.queue(); + } + } + + @Override + public void render(GuiGraphics graphics, Rectangle bounds, int mouseX, int mouseY, float delta) { + PoseStack pose = graphics.pose(); + pose.pushPose(); + pose.translate(bounds.x, bounds.y, 0.0); + BlockStateRender.renderBlock(this.blockState, this.posY, graphics, bounds.height); + pose.popPose(); + } + + @Override + public @NotNull List children() { + return List.of(); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (containsMouse(mouseX, mouseY)) { + wasClicked = true; + } + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (wasClicked && containsMouse(mouseX, mouseY)) { + if ((ConfigObject.getInstance().getRecipeKeybind().getType() + != InputConstants.Type.MOUSE && button == 0) + || ConfigObject.getInstance().getRecipeKeybind().matchesMouse(button)) + return ViewSearchBuilder.builder().addRecipesFor(EntryStacks.of(this.blockState.getBlock())).open(); + else if ((ConfigObject.getInstance().getUsageKeybind().getType() + != InputConstants.Type.MOUSE && button == 1) + || ConfigObject.getInstance().getUsageKeybind().matchesMouse(button)) + return ViewSearchBuilder.builder().addUsagesFor(EntryStacks.of(this.blockState.getBlock())).open(); + } + return false; + } + + @Override + public @Nullable Tooltip getTooltip(TooltipContext context) { + if (this.blockState.isAir()) return null; + if (this.blockState.getBlock().asItem().equals(Items.AIR)) + return Tooltip.create(context.getPoint(), this.blockState.getBlock().getName()); + return EntryStacks.of(this.blockState.getBlock()).getTooltip(context); + } + + @Override + public Rectangle getBounds() { + return new Rectangle(this.offsetX, this.offsetY - size * 0.56 * posY, size, size); + } +} diff --git a/fabric/build.gradle b/fabric/build.gradle index e3732e667..32ef896cf 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -101,7 +101,7 @@ dependencies { // Development QOL modCompileOnly fabric.lazydfu - modImplementation fabric.modmenu + modCompileOnly fabric.modmenu // JEI modCompileOnlyApi(fabric.jei.common.api) { transitive = false } @@ -109,13 +109,14 @@ dependencies { modCompileOnly(fabric.jei.fabric.impl) { transitive = false } // REI + modRuntimeOnly "dev.architectury:architectury-fabric:9.2.14" modCompileOnly(fabric.rei.plugin) { transitive = false } modCompileOnly(fabric.rei.api) { transitive = false } - modCompileOnly(fabric.rei.fabric) { transitive = false } + modRuntimeOnly(fabric.rei.fabric) { transitive = false } // EMI modCompileOnly("dev.emi:emi-fabric:${fabric.versions.emi.get()}:api") - modImplementation fabric.emi + modCompileOnly fabric.emi // Jade modImplementation fabric.jade @@ -181,7 +182,7 @@ jar { archiveClassifier.set("dev") } -tasks.register('dataDelete', Delete){ +tasks.register('dataDelete', Delete) { group 'loom' delete forge_project.files('src/generated') } diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index b6b8ea0b5..ca2c9eff7 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -434,6 +434,7 @@ "tooltip.anvilcraft.item.power_converter_big": "Mʞ 6 sǝɯnsuoɔ 'ƎℲ oʇuı ɹǝʍod ʇɹǝʌuoƆ", "tooltip.anvilcraft.item.power_converter_middle": "Mʞ Ɛ sǝɯnsuoɔ 'ƎℲ oʇuı ɹǝʍod ʇɹǝʌuoƆ", "tooltip.anvilcraft.item.power_converter_small": "Mʞ Ɩ sǝɯnsuoɔ 'ƎℲ oʇuı ɹǝʍod ʇɹǝʌuoƆ", + "tooltip.anvilcraft.item.recipe.processing.chance": "ǝɔuɐɥƆ %1$s%%", "tooltip.anvilcraft.item.reinforced_concrete": "ɟooɹd ɹǝdǝǝɹƆ", "tooltip.anvilcraft.item.remote_transmission_pole": "8 ɟo ǝɔuɐʇsıp uoıssıɯsuɐɹʇ ɐ ɥʇıʍ pıɹb ɹǝʍod ɐ pןınᗺ", "tooltip.anvilcraft.item.resin_block": "ʎʇıʇuƎbuıʌıꞀ sǝɹnʇɐǝɹɔ ǝןıʇsoɥ ʞɐǝʍ ɹo ʎןpuǝıɹɟ ǝɹnʇdɐɔ oʇ ǝs∩", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index b35b6a205..9f5ca4326 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -434,6 +434,7 @@ "tooltip.anvilcraft.item.power_converter_big": "Convert power into FE, consumes 9 kW", "tooltip.anvilcraft.item.power_converter_middle": "Convert power into FE, consumes 3 kW", "tooltip.anvilcraft.item.power_converter_small": "Convert power into FE, consumes 1 kW", + "tooltip.anvilcraft.item.recipe.processing.chance": "%1$s%% Chance", "tooltip.anvilcraft.item.reinforced_concrete": "Creeper proof", "tooltip.anvilcraft.item.remote_transmission_pole": "Build a power grid with a transmission distance of 8", "tooltip.anvilcraft.item.resin_block": "Use to capture friendly or weak hostile creatures LivingEntity", diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json b/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json index 47781098d..019a4d6b3 100644 --- a/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json @@ -17,7 +17,7 @@ } ], "transformOptions": [ - "replaceAnvil", - "keepInventory" + "keepInventory", + "replaceAnvil" ] } \ No newline at end of file diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 53c74fc08..6cbf11186 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -37,6 +37,12 @@ ], "jade": [ "dev.dubhe.anvilcraft.integration.jade.AnvilCraftJadePlugin" + ], + "rei_client": [ + "dev.dubhe.anvilcraft.integration.rei.client.AnvilCraftReiClientPlugin" + ], + "rei_common": [ + "dev.dubhe.anvilcraft.integration.rei.AnvilCraftReiPlugin" ] }, "mixins": [ diff --git a/forge/build.gradle b/forge/build.gradle index 32a2daf4a..70405f1bd 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -44,7 +44,7 @@ loom { convertAccessWideners = true extraAccessWideners.add loom.accessWidenerPath.get().asFile.name - dataGen{ + dataGen { mod(mod_id) } } @@ -99,6 +99,7 @@ configurations { repositories { // mavens for Forge-exclusives + maven { url = "https://maven.shedaniel.me/" } maven { url = "https://maven.theillusivec4.top/" } // Curios maven { url = "https://maven.parchmentmc.org" } // Parchment mappings maven { url = "https://maven.quiltmc.org/repository/release" } // Quilt Mappings @@ -130,13 +131,14 @@ dependencies { modCompileOnly(forge.jei.forge.impl) { transitive = false } // REI + modRuntimeOnly "dev.architectury:architectury-forge:9.2.14" modCompileOnly(forge.rei.plugin) { transitive = false } modCompileOnly(forge.rei.api) { transitive = false } - modCompileOnly(forge.rei.forge) { transitive = false } + modRuntimeOnly(forge.rei.forge) { transitive = false } // EMI modCompileOnly("dev.emi:emi-forge:${fabric.versions.emi.get()}:api") - modImplementation forge.emi + modCompileOnly forge.emi // Jade modImplementation(forge.jade) diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index b6b8ea0b5..ca2c9eff7 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -434,6 +434,7 @@ "tooltip.anvilcraft.item.power_converter_big": "Mʞ 6 sǝɯnsuoɔ 'ƎℲ oʇuı ɹǝʍod ʇɹǝʌuoƆ", "tooltip.anvilcraft.item.power_converter_middle": "Mʞ Ɛ sǝɯnsuoɔ 'ƎℲ oʇuı ɹǝʍod ʇɹǝʌuoƆ", "tooltip.anvilcraft.item.power_converter_small": "Mʞ Ɩ sǝɯnsuoɔ 'ƎℲ oʇuı ɹǝʍod ʇɹǝʌuoƆ", + "tooltip.anvilcraft.item.recipe.processing.chance": "ǝɔuɐɥƆ %1$s%%", "tooltip.anvilcraft.item.reinforced_concrete": "ɟooɹd ɹǝdǝǝɹƆ", "tooltip.anvilcraft.item.remote_transmission_pole": "8 ɟo ǝɔuɐʇsıp uoıssıɯsuɐɹʇ ɐ ɥʇıʍ pıɹb ɹǝʍod ɐ pןınᗺ", "tooltip.anvilcraft.item.resin_block": "ʎʇıʇuƎbuıʌıꞀ sǝɹnʇɐǝɹɔ ǝןıʇsoɥ ʞɐǝʍ ɹo ʎןpuǝıɹɟ ǝɹnʇdɐɔ oʇ ǝs∩", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index b35b6a205..9f5ca4326 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -434,6 +434,7 @@ "tooltip.anvilcraft.item.power_converter_big": "Convert power into FE, consumes 9 kW", "tooltip.anvilcraft.item.power_converter_middle": "Convert power into FE, consumes 3 kW", "tooltip.anvilcraft.item.power_converter_small": "Convert power into FE, consumes 1 kW", + "tooltip.anvilcraft.item.recipe.processing.chance": "%1$s%% Chance", "tooltip.anvilcraft.item.reinforced_concrete": "Creeper proof", "tooltip.anvilcraft.item.remote_transmission_pole": "Build a power grid with a transmission distance of 8", "tooltip.anvilcraft.item.resin_block": "Use to capture friendly or weak hostile creatures LivingEntity", diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json b/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json index 47781098d..019a4d6b3 100644 --- a/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json +++ b/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json @@ -17,7 +17,7 @@ } ], "transformOptions": [ - "replaceAnvil", - "keepInventory" + "keepInventory", + "replaceAnvil" ] } \ No newline at end of file diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java new file mode 100644 index 000000000..3d9859fbf --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java @@ -0,0 +1,7 @@ +package dev.dubhe.anvilcraft.integration.rei; + +import me.shedaniel.rei.forge.REIPluginCommon; + +@REIPluginCommon +public class AnvilCraftReiPluginForge extends AnvilCraftReiPlugin{ +} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java new file mode 100644 index 000000000..1a5a0267f --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java @@ -0,0 +1,7 @@ +package dev.dubhe.anvilcraft.integration.rei.client; + +import me.shedaniel.rei.forge.REIPluginClient; + +@REIPluginClient +public class AnvilCraftReiClientPluginForge extends AnvilCraftReiClientPlugin { +} diff --git a/settings.gradle b/settings.gradle index 94f3d8e3a..d0ec671f9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,17 +3,19 @@ pluginManagement { maven { url "https://maven.fabricmc.net/" } maven { url "https://maven.architectury.dev/" } maven { url "https://maven.minecraftforge.net/" } + maven { url "https://maven.shedaniel.me/" } gradlePluginPortal() } } +// Minecraft Version +def minecraftVersion = "${minecraft_version}" + dependencyResolutionManagement { repositories { mavenCentral() } versionCatalogs { - // Minecraft Version - def minecraftVersion = "${minecraft_version}" // Mod Dependencies Versions // Common From 7c30657543272566b9bb7bf157ba2c69c0584641 Mon Sep 17 00:00:00 2001 From: dmzz-yyhyy Date: Fri, 28 Jun 2024 20:22:00 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=AD=A3forge=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/fabric/ServerWorldEventListener.java | 3 ++- .../dubhe/anvilcraft/event/forge/LevelEventListener.java | 5 ++++- .../integration/rei/AnvilCraftReiPluginForge.java | 7 ------- .../rei/client/AnvilCraftReiClientPluginForge.java | 7 ------- .../integration/rei/forge/AnvilCraftReiPluginForge.java | 9 +++++++++ .../rei/forge/client/AnvilCraftReiClientPluginForge.java | 9 +++++++++ 6 files changed, 24 insertions(+), 16 deletions(-) delete mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java delete mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/AnvilCraftReiPluginForge.java create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/client/AnvilCraftReiClientPluginForge.java diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java index d67849a98..4a6a8c47b 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java @@ -1,8 +1,8 @@ package dev.dubhe.anvilcraft.event.fabric; -import dev.dubhe.anvilcraft.api.chargecollector.ChargeCollectorManager; import dev.dubhe.anvilcraft.api.entity.fakeplayer.fabric.AnvilCraftBlockPlacerFakePlayer; import dev.dubhe.anvilcraft.api.entity.player.AnvilCraftBlockPlacer; +import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; import net.minecraft.server.MinecraftServer; @@ -21,6 +21,7 @@ public static void init() { private static void onload(MinecraftServer server, Level level) { if (level instanceof ServerLevel serverLevel) AnvilCraftBlockPlacer.anvilCraftBlockPlacer = new AnvilCraftBlockPlacerFakePlayer(serverLevel); + AnvilRecipeManager.updateRecipes(server); } private static void onUnload(MinecraftServer server, Level level) { diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java index ea66314ab..50b4bedbb 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java @@ -1,9 +1,9 @@ package dev.dubhe.anvilcraft.event.forge; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.chargecollector.ChargeCollectorManager; import dev.dubhe.anvilcraft.api.entity.fakeplayer.forge.AnvilCraftBlockPlacerFakePlayer; import dev.dubhe.anvilcraft.api.entity.player.AnvilCraftBlockPlacer; +import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; import net.minecraft.server.level.ServerLevel; import net.minecraftforge.event.level.LevelEvent; @@ -11,6 +11,8 @@ import net.minecraftforge.fml.common.Mod; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + @Mod.EventBusSubscriber(modid = AnvilCraft.MOD_ID) public class LevelEventListener { @@ -22,6 +24,7 @@ public static void onLevelLoad(@NotNull LevelEvent.Load event) { if (event.getLevel() instanceof ServerLevel serverLevel) AnvilCraftBlockPlacer.anvilCraftBlockPlacer = new AnvilCraftBlockPlacerFakePlayer(serverLevel); + AnvilRecipeManager.updateRecipes(Objects.requireNonNull(event.getLevel().getServer())); } /** diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java deleted file mode 100644 index 3d9859fbf..000000000 --- a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.dubhe.anvilcraft.integration.rei; - -import me.shedaniel.rei.forge.REIPluginCommon; - -@REIPluginCommon -public class AnvilCraftReiPluginForge extends AnvilCraftReiPlugin{ -} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java deleted file mode 100644 index 1a5a0267f..000000000 --- a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.dubhe.anvilcraft.integration.rei.client; - -import me.shedaniel.rei.forge.REIPluginClient; - -@REIPluginClient -public class AnvilCraftReiClientPluginForge extends AnvilCraftReiClientPlugin { -} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/AnvilCraftReiPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/AnvilCraftReiPluginForge.java new file mode 100644 index 000000000..84f64be61 --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/AnvilCraftReiPluginForge.java @@ -0,0 +1,9 @@ +package dev.dubhe.anvilcraft.integration.rei.forge; + +import dev.dubhe.anvilcraft.integration.rei.AnvilCraftReiPlugin; +import me.shedaniel.rei.forge.REIPluginCommon; + +@SuppressWarnings("unused") +@REIPluginCommon +public class AnvilCraftReiPluginForge extends AnvilCraftReiPlugin { +} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/client/AnvilCraftReiClientPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/client/AnvilCraftReiClientPluginForge.java new file mode 100644 index 000000000..fab36dec4 --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/client/AnvilCraftReiClientPluginForge.java @@ -0,0 +1,9 @@ +package dev.dubhe.anvilcraft.integration.rei.forge.client; + +import dev.dubhe.anvilcraft.integration.rei.client.AnvilCraftReiClientPlugin; +import me.shedaniel.rei.forge.REIPluginClient; + +@SuppressWarnings("unused") +@REIPluginClient +public class AnvilCraftReiClientPluginForge extends AnvilCraftReiClientPlugin { +} From 4c54e52cf3ca0997621bb4834ee43fe8612e715b Mon Sep 17 00:00:00 2001 From: dmzz-yyhyy Date: Fri, 28 Jun 2024 20:22:00 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E6=AD=A3forge=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rei/client/AnvilCraftReiClientPlugin.java | 15 --------------- .../event/fabric/ServerWorldEventListener.java | 3 ++- .../event/forge/LevelEventListener.java | 5 ++++- .../integration/rei/AnvilCraftReiPluginForge.java | 7 ------- .../client/AnvilCraftReiClientPluginForge.java | 7 ------- .../rei/forge/AnvilCraftReiPluginForge.java | 9 +++++++++ .../client/AnvilCraftReiClientPluginForge.java | 9 +++++++++ 7 files changed, 24 insertions(+), 31 deletions(-) delete mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java delete mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/AnvilCraftReiPluginForge.java create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/client/AnvilCraftReiClientPluginForge.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java index 2d0339b59..26adc5e47 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java @@ -36,54 +36,46 @@ public void registerCategories(CategoryRegistry registry) { EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.SIEVING.getCategoryIdentifier(), EntryStacks.of(Blocks.SCAFFOLDING), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.BULGING.getCategoryIdentifier(), EntryStacks.of(Blocks.WATER_CAULDRON), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.BULGING_LIKE.getCategoryIdentifier(), EntryStacks.of(Blocks.CAULDRON), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.FLUID_HANDLING.getCategoryIdentifier(), EntryStacks.of(Blocks.WATER_CAULDRON), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.CRYSTALLIZE.getCategoryIdentifier(), EntryStacks.of(Blocks.POWDER_SNOW_CAULDRON), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.COMPACTION.getCategoryIdentifier(), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.COMPRESS.getCategoryIdentifier(), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.COOKING.getCategoryIdentifier(), EntryStacks.of(Blocks.CAMPFIRE), EntryStacks.of(Blocks.SOUL_CAMPFIRE), @@ -91,32 +83,27 @@ public void registerCategories(CategoryRegistry registry) { EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.ITEM_INJECT.getCategoryIdentifier(), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.BLOCK_SMASH.getCategoryIdentifier(), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.ITEM_SMASH.getCategoryIdentifier(), EntryStacks.of(Blocks.IRON_TRAPDOOR), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.SQUEEZE.getCategoryIdentifier(), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.SUPER_HEATING.getCategoryIdentifier(), EntryStacks.of(Blocks.CAULDRON), EntryStacks.of(ModBlocks.HEATER), @@ -124,14 +111,12 @@ public void registerCategories(CategoryRegistry registry) { EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.TIMEWARP.getCategoryIdentifier(), EntryStacks.of(ModBlocks.CORRUPTED_BEACON), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), EntryStacks.of(Blocks.CHIPPED_ANVIL), EntryStacks.of(Blocks.DAMAGED_ANVIL)); - registry.addWorkstations(AnvilCraftCategoryIdentifiers.GENERIC.getCategoryIdentifier(), EntryStacks.of(ModBlocks.ROYAL_ANVIL), EntryStacks.of(Blocks.ANVIL), diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java index d67849a98..4a6a8c47b 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java @@ -1,8 +1,8 @@ package dev.dubhe.anvilcraft.event.fabric; -import dev.dubhe.anvilcraft.api.chargecollector.ChargeCollectorManager; import dev.dubhe.anvilcraft.api.entity.fakeplayer.fabric.AnvilCraftBlockPlacerFakePlayer; import dev.dubhe.anvilcraft.api.entity.player.AnvilCraftBlockPlacer; +import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; import net.minecraft.server.MinecraftServer; @@ -21,6 +21,7 @@ public static void init() { private static void onload(MinecraftServer server, Level level) { if (level instanceof ServerLevel serverLevel) AnvilCraftBlockPlacer.anvilCraftBlockPlacer = new AnvilCraftBlockPlacerFakePlayer(serverLevel); + AnvilRecipeManager.updateRecipes(server); } private static void onUnload(MinecraftServer server, Level level) { diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java index ea66314ab..50b4bedbb 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java @@ -1,9 +1,9 @@ package dev.dubhe.anvilcraft.event.forge; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.chargecollector.ChargeCollectorManager; import dev.dubhe.anvilcraft.api.entity.fakeplayer.forge.AnvilCraftBlockPlacerFakePlayer; import dev.dubhe.anvilcraft.api.entity.player.AnvilCraftBlockPlacer; +import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; import net.minecraft.server.level.ServerLevel; import net.minecraftforge.event.level.LevelEvent; @@ -11,6 +11,8 @@ import net.minecraftforge.fml.common.Mod; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + @Mod.EventBusSubscriber(modid = AnvilCraft.MOD_ID) public class LevelEventListener { @@ -22,6 +24,7 @@ public static void onLevelLoad(@NotNull LevelEvent.Load event) { if (event.getLevel() instanceof ServerLevel serverLevel) AnvilCraftBlockPlacer.anvilCraftBlockPlacer = new AnvilCraftBlockPlacerFakePlayer(serverLevel); + AnvilRecipeManager.updateRecipes(Objects.requireNonNull(event.getLevel().getServer())); } /** diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java deleted file mode 100644 index 3d9859fbf..000000000 --- a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftReiPluginForge.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.dubhe.anvilcraft.integration.rei; - -import me.shedaniel.rei.forge.REIPluginCommon; - -@REIPluginCommon -public class AnvilCraftReiPluginForge extends AnvilCraftReiPlugin{ -} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java deleted file mode 100644 index 1a5a0267f..000000000 --- a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPluginForge.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.dubhe.anvilcraft.integration.rei.client; - -import me.shedaniel.rei.forge.REIPluginClient; - -@REIPluginClient -public class AnvilCraftReiClientPluginForge extends AnvilCraftReiClientPlugin { -} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/AnvilCraftReiPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/AnvilCraftReiPluginForge.java new file mode 100644 index 000000000..84f64be61 --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/AnvilCraftReiPluginForge.java @@ -0,0 +1,9 @@ +package dev.dubhe.anvilcraft.integration.rei.forge; + +import dev.dubhe.anvilcraft.integration.rei.AnvilCraftReiPlugin; +import me.shedaniel.rei.forge.REIPluginCommon; + +@SuppressWarnings("unused") +@REIPluginCommon +public class AnvilCraftReiPluginForge extends AnvilCraftReiPlugin { +} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/client/AnvilCraftReiClientPluginForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/client/AnvilCraftReiClientPluginForge.java new file mode 100644 index 000000000..fab36dec4 --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/integration/rei/forge/client/AnvilCraftReiClientPluginForge.java @@ -0,0 +1,9 @@ +package dev.dubhe.anvilcraft.integration.rei.forge.client; + +import dev.dubhe.anvilcraft.integration.rei.client.AnvilCraftReiClientPlugin; +import me.shedaniel.rei.forge.REIPluginClient; + +@SuppressWarnings("unused") +@REIPluginClient +public class AnvilCraftReiClientPluginForge extends AnvilCraftReiClientPlugin { +} From b6dd5836daf914c54bd787c6db2bf25ab9a97491 Mon Sep 17 00:00:00 2001 From: Gugle Date: Fri, 28 Jun 2024 21:51:22 +0800 Subject: [PATCH 4/8] =?UTF-8?q?mixin=E5=A4=A7=E6=B3=95=E5=A5=BD=EF=BC=81?= =?UTF-8?q?=EF=BC=81=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/api/RipeningManager.java | 2 -- .../impl/PowerComponentTooltipProvider.java | 3 --- .../entity/CorruptedBeaconBlockEntity.java | 7 +------ .../ThermoelectricConverterBlockEntity.java | 2 -- .../recipe/transform/MobTransformRecipe.java | 2 -- .../rei/AnvilCraftCategoryIdentifier.java | 3 ++- .../rei/client/AnvilCraftReiClientPlugin.java | 3 ++- .../rei/client/AnvilRecipeDisplayCategory.java | 3 ++- .../rei/client/widget/BlockWidget.java | 3 ++- .../rei/DefaultDisplayViewingScreenMixin.java | 18 ++++++++++++++++++ .../mixin/plugin/AnvilCraftMixinPlugin.java | 14 ++++++++++---- .../resources/anvilcraft-common.mixins.json | 1 + .../fabric/ItemStorageProxyItemDepository.java | 12 ------------ .../forge/ServerBlockEntityEventListener.java | 2 -- 14 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/mixin/integration/rei/DefaultDisplayViewingScreenMixin.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/RipeningManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/RipeningManager.java index 2ae7170bb..2497e7cb4 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/RipeningManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/RipeningManager.java @@ -1,6 +1,5 @@ package dev.dubhe.anvilcraft.api; -import com.mojang.logging.LogUtils; import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.block.InductionLightBlock; import dev.dubhe.anvilcraft.block.state.LightColor; @@ -16,7 +15,6 @@ import net.minecraft.world.level.block.NyliumBlock; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; import java.util.Collections; import java.util.HashMap; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/tooltip/impl/PowerComponentTooltipProvider.java b/common/src/main/java/dev/dubhe/anvilcraft/api/tooltip/impl/PowerComponentTooltipProvider.java index 70ffe3544..833ff8eee 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/tooltip/impl/PowerComponentTooltipProvider.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/tooltip/impl/PowerComponentTooltipProvider.java @@ -1,8 +1,6 @@ package dev.dubhe.anvilcraft.api.tooltip.impl; import dev.dubhe.anvilcraft.api.power.IPowerComponent; -import dev.dubhe.anvilcraft.api.power.IPowerConsumer; -import dev.dubhe.anvilcraft.api.power.IPowerProducer; import dev.dubhe.anvilcraft.api.power.PowerComponentInfo; import dev.dubhe.anvilcraft.api.power.PowerComponentType; import dev.dubhe.anvilcraft.api.power.SimplePowerGrid; @@ -13,7 +11,6 @@ import net.minecraft.network.chat.Style; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; import java.util.ArrayList; import java.util.List; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CorruptedBeaconBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CorruptedBeaconBlockEntity.java index c937ab842..6784b04d5 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CorruptedBeaconBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CorruptedBeaconBlockEntity.java @@ -6,15 +6,11 @@ import dev.dubhe.anvilcraft.data.recipe.transform.MobTransformContainer; import dev.dubhe.anvilcraft.init.ModBlockEntities; import dev.dubhe.anvilcraft.init.ModRecipeTypes; - -import java.util.Objects; - import lombok.Getter; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.server.commands.data.EntityDataAccessor; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; @@ -27,7 +23,6 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobSpawnType; -import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BeaconBeamBlock; @@ -42,7 +37,7 @@ import java.util.Arrays; import java.util.List; -import java.util.UUID; +import java.util.Objects; public class CorruptedBeaconBlockEntity extends BlockEntity { List beamSections = Lists.newArrayList(); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ThermoelectricConverterBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ThermoelectricConverterBlockEntity.java index 2fc264aa1..f8476d1fc 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ThermoelectricConverterBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ThermoelectricConverterBlockEntity.java @@ -3,11 +3,9 @@ import dev.dubhe.anvilcraft.api.chargecollector.ThermoManager; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import org.jetbrains.annotations.NotNull; import static dev.dubhe.anvilcraft.block.ThermoelectricConverterBlock.DIRECTIONS; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/MobTransformRecipe.java b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/MobTransformRecipe.java index 74f806ca6..1febb4245 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/MobTransformRecipe.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/MobTransformRecipe.java @@ -14,7 +14,6 @@ import net.minecraft.data.recipes.FinishedRecipe; import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.commands.data.EntityDataAccessor; @@ -28,7 +27,6 @@ import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; -import javax.swing.text.html.Option; import java.util.ArrayList; import java.util.Comparator; import java.util.HashSet; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifier.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifier.java index 360c70666..1310522c1 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifier.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/AnvilCraftCategoryIdentifier.java @@ -5,6 +5,7 @@ import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.NotNull; @Getter public class AnvilCraftCategoryIdentifier { @@ -12,7 +13,7 @@ public class AnvilCraftCategoryIdentifier { private Component title = null; private Renderer icon = null; - public static AnvilCraftCategoryIdentifier creat() { + public static @NotNull AnvilCraftCategoryIdentifier creat() { return new AnvilCraftCategoryIdentifier(); } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java index 26adc5e47..6dec3da1a 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilCraftReiClientPlugin.java @@ -9,10 +9,11 @@ import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; import me.shedaniel.rei.api.common.util.EntryStacks; import net.minecraft.world.level.block.Blocks; +import org.jetbrains.annotations.NotNull; public class AnvilCraftReiClientPlugin implements REIClientPlugin { @Override - public void registerCategories(CategoryRegistry registry) { + public void registerCategories(@NotNull CategoryRegistry registry) { registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.STAMPING)); registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.SIEVING)); registry.add(new AnvilRecipeDisplayCategory(AnvilCraftCategoryIdentifiers.BULGING)); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplayCategory.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplayCategory.java index eba4046bf..fbb4c06f3 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplayCategory.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/AnvilRecipeDisplayCategory.java @@ -23,6 +23,7 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec2; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Iterator; @@ -65,7 +66,7 @@ public int getDisplayWidth(AnvilRecipeDisplay display) { } @Override - public List setupDisplay(AnvilRecipeDisplay display, Rectangle bounds) { + public List setupDisplay(@NotNull AnvilRecipeDisplay display, @NotNull Rectangle bounds) { Point startPoint = new Point(bounds.getCenterX() - 133, bounds.getCenterY() - 42); List widgets = Lists.newArrayList(); widgets.add(Widgets.createRecipeBase(bounds)); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/widget/BlockWidget.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/widget/BlockWidget.java index 3bf7819f1..fdbbad1f5 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/widget/BlockWidget.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/rei/client/widget/BlockWidget.java @@ -59,8 +59,9 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo } } + @SuppressWarnings("deprecation") @Override - public void render(GuiGraphics graphics, Rectangle bounds, int mouseX, int mouseY, float delta) { + public void render(@NotNull GuiGraphics graphics, @NotNull Rectangle bounds, int mouseX, int mouseY, float delta) { PoseStack pose = graphics.pose(); pose.pushPose(); pose.translate(bounds.x, bounds.y, 0.0); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/mixin/integration/rei/DefaultDisplayViewingScreenMixin.java b/common/src/main/java/dev/dubhe/anvilcraft/mixin/integration/rei/DefaultDisplayViewingScreenMixin.java new file mode 100644 index 000000000..1cfd65670 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/mixin/integration/rei/DefaultDisplayViewingScreenMixin.java @@ -0,0 +1,18 @@ +package dev.dubhe.anvilcraft.mixin.integration.rei; + +import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; + +@SuppressWarnings("UnstableApiUsage") +@Mixin(DefaultDisplayViewingScreen.class) +public class DefaultDisplayViewingScreenMixin { + @ModifyConstant( + method = "init", + constant = @Constant(intValue = 190) + ) + private int init(int constant) { + return 250; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java b/common/src/main/java/dev/dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java index 4b2261196..8c9856413 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java @@ -1,5 +1,6 @@ package dev.dubhe.anvilcraft.mixin.plugin; +import org.jetbrains.annotations.NotNull; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; @@ -8,13 +9,17 @@ import java.util.Set; public class AnvilCraftMixinPlugin implements IMixinConfigPlugin { - private static boolean hasZetaPiston = false; + private static boolean hasReiScreen = false; + + private boolean isLoaded(String clazz) { + return AnvilCraftMixinPlugin.class.getClassLoader().getResource(clazz) != null; + } @Override public void onLoad(String mixinPackage) { - hasZetaPiston = AnvilCraftMixinPlugin.class.getClassLoader() - .getResource("org/violetmoon/zeta/piston/ZetaPistonStructureResolver.class") != null; + hasZetaPiston = this.isLoaded("org/violetmoon/zeta/piston/ZetaPistonStructureResolver.class"); + hasReiScreen = this.isLoaded("me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.class"); } @Override @@ -23,8 +28,9 @@ public String getRefMapperConfig() { } @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + public boolean shouldApplyMixin(String targetClassName, @NotNull String mixinClassName) { if (mixinClassName.endsWith("PistonStructureResolverMixin")) return !hasZetaPiston; + if (mixinClassName.endsWith("DefaultDisplayViewingScreenMixin")) return hasReiScreen; return true; } diff --git a/common/src/main/resources/anvilcraft-common.mixins.json b/common/src/main/resources/anvilcraft-common.mixins.json index c9b4b0f44..ec7ac8156 100644 --- a/common/src/main/resources/anvilcraft-common.mixins.json +++ b/common/src/main/resources/anvilcraft-common.mixins.json @@ -36,6 +36,7 @@ "client": [ "ClientLevelMixin", "ClientPacketListenerMixin", + "integration.rei.DefaultDisplayViewingScreenMixin", "ItemInHandRendererMixin", "LevelRendererMixin", "TooltipRenderMixin", diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java index afdc4db57..255691c3b 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java @@ -1,11 +1,6 @@ package dev.dubhe.anvilcraft.api.depository.fabric; -import com.google.common.collect.Maps; import dev.dubhe.anvilcraft.api.depository.IItemDepository; -import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectRBTreeMap; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.base.SingleItemStorage; import net.fabricmc.fabric.api.transfer.v1.item.base.SingleStackStorage; @@ -13,19 +8,12 @@ import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil; import net.fabricmc.fabric.api.transfer.v1.storage.StorageView; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; -import net.minecraft.client.gui.components.tabs.Tab; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import java.util.Map; @SuppressWarnings("UnstableApiUsage") public class ItemStorageProxyItemDepository implements IItemDepository { diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEventListener.java index b031eb76d..c5e532e93 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEventListener.java @@ -6,8 +6,6 @@ import dev.dubhe.anvilcraft.api.power.IPowerComponent; import dev.dubhe.anvilcraft.api.power.PowerGrid; import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; -import dev.dubhe.anvilcraft.api.world.load.LoadChuckData; -import dev.dubhe.anvilcraft.block.OverseerBlock; import dev.dubhe.anvilcraft.block.entity.ChargeCollectorBlockEntity; import dev.dubhe.anvilcraft.block.entity.OverseerBlockEntity; import net.minecraft.server.level.ServerLevel; From 4d9a7fcc808c8f27774d17ad16ec35ab3e77577a Mon Sep 17 00:00:00 2001 From: dmzz-yyhyy Date: Fri, 28 Jun 2024 21:58:48 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E8=BF=9B=E5=85=A5=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=88=9D=E5=A7=8B=E5=8C=96AnvilReci?= =?UTF-8?q?peManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/recipe/AnvilRecipeManager.java | 23 ++++++++----------- .../anvilcraft/event/ServerEventListener.java | 4 ++-- .../fabric/ServerWorldEventListener.java | 2 +- .../event/forge/LevelEventListener.java | 7 +++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/recipe/AnvilRecipeManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/recipe/AnvilRecipeManager.java index d940211f8..cb8f96d61 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/recipe/AnvilRecipeManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/recipe/AnvilRecipeManager.java @@ -5,7 +5,7 @@ import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe; import dev.dubhe.anvilcraft.init.ModRecipeTypes; import lombok.Getter; -import net.minecraft.server.MinecraftServer; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.BlastingRecipe; import net.minecraft.world.item.crafting.CampfireCookingRecipe; @@ -28,38 +28,35 @@ public class AnvilRecipeManager { /** * 更新配方 - * - * @param server 服务器实例 */ - public static void updateRecipes(@NotNull MinecraftServer server) { - RecipeManager manager = server.getRecipeManager(); + public static void updateRecipes(@NotNull RecipeManager manager, @NotNull RegistryAccess registryAccess) { ArrayList anvilRecipes = new ArrayList<>(manager.getAllRecipesFor(ModRecipeTypes.ANVIL_RECIPE)); AnvilCraft.EVENT_BUS.post(new RecipeReloadEvent()); anvilRecipes.addAll(externalRecipeList); externalRecipeList = new ArrayList<>(); List needFilter = new ArrayList<>(); for (CampfireCookingRecipe recipe : manager.getAllRecipesFor(RecipeType.CAMPFIRE_COOKING)) { - AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess()); + AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess); if (anvilRecipe != null) anvilRecipes.add(anvilRecipe); } for (SmokingRecipe recipe : manager.getAllRecipesFor(RecipeType.SMOKING)) { - needFilter.add(recipe.getResultItem(server.registryAccess())); - AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess()); + needFilter.add(recipe.getResultItem(registryAccess)); + AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess); if (anvilRecipe != null) anvilRecipes.add(anvilRecipe); } for (BlastingRecipe recipe : manager.getAllRecipesFor(RecipeType.BLASTING)) { - needFilter.add(recipe.getResultItem(server.registryAccess())); - AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess()); + needFilter.add(recipe.getResultItem(registryAccess)); + AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess); if (anvilRecipe != null) anvilRecipes.add(anvilRecipe); } for (SmeltingRecipe recipe : manager.getAllRecipesFor(RecipeType.SMELTING)) { - ItemStack item = recipe.getResultItem(server.registryAccess()); + ItemStack item = recipe.getResultItem(registryAccess); if (needFilter.stream().anyMatch(stack -> item.is(stack.getItem()))) continue; - AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess()); + AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess); if (anvilRecipe != null) anvilRecipes.add(anvilRecipe); } for (CraftingRecipe recipe : manager.getAllRecipesFor(RecipeType.CRAFTING)) { - AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, server.registryAccess()); + AnvilRecipe anvilRecipe = AnvilRecipe.of(recipe, registryAccess); if (anvilRecipe != null) anvilRecipes.add(anvilRecipe); } anvilRecipeList = Collections.synchronizedList( diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/ServerEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/ServerEventListener.java index c88b26eac..dfc35ce4e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/ServerEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/ServerEventListener.java @@ -19,13 +19,13 @@ public class ServerEventListener { public void onServerStarted(@NotNull ServerStartedEvent event) { ModHammerInits.init(); HammerManager.register(); - AnvilRecipeManager.updateRecipes(event.getServer()); + AnvilRecipeManager.updateRecipes(event.getServer().getRecipeManager(), event.getServer().registryAccess()); LevelLoadManager.notifyServerStarted(); } @SubscribeEvent public void onServerEndDataPackReload(@NotNull ServerEndDataPackReloadEvent event) { - AnvilRecipeManager.updateRecipes(event.getServer()); + AnvilRecipeManager.updateRecipes(event.getServer().getRecipeManager(), event.getServer().registryAccess()); } } diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java index 4a6a8c47b..67e26934c 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerWorldEventListener.java @@ -21,7 +21,7 @@ public static void init() { private static void onload(MinecraftServer server, Level level) { if (level instanceof ServerLevel serverLevel) AnvilCraftBlockPlacer.anvilCraftBlockPlacer = new AnvilCraftBlockPlacerFakePlayer(serverLevel); - AnvilRecipeManager.updateRecipes(server); + AnvilRecipeManager.updateRecipes(server.getRecipeManager(), server.registryAccess()); } private static void onUnload(MinecraftServer server, Level level) { diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java index 50b4bedbb..53e9fb486 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java @@ -5,14 +5,13 @@ import dev.dubhe.anvilcraft.api.entity.player.AnvilCraftBlockPlacer; import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.server.level.ServerLevel; import net.minecraftforge.event.level.LevelEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.jetbrains.annotations.NotNull; -import java.util.Objects; - @Mod.EventBusSubscriber(modid = AnvilCraft.MOD_ID) public class LevelEventListener { @@ -24,7 +23,9 @@ public static void onLevelLoad(@NotNull LevelEvent.Load event) { if (event.getLevel() instanceof ServerLevel serverLevel) AnvilCraftBlockPlacer.anvilCraftBlockPlacer = new AnvilCraftBlockPlacerFakePlayer(serverLevel); - AnvilRecipeManager.updateRecipes(Objects.requireNonNull(event.getLevel().getServer())); + if (event.getLevel() instanceof ClientLevel clientLevel) { + AnvilRecipeManager.updateRecipes(clientLevel.getRecipeManager(), clientLevel.registryAccess()); + } } /** From 1242cd357b6c9b91902cb7de981773c40c25d091 Mon Sep 17 00:00:00 2001 From: dmzz-yyhyy Date: Fri, 28 Jun 2024 22:40:23 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmixin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java b/common/src/main/java/dev/dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java index 88b3b9bc6..4890c2b9f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/mixin/plugin/AnvilCraftMixinPlugin.java @@ -1,7 +1,6 @@ package dev.dubhe.anvilcraft.mixin.plugin; import org.jetbrains.annotations.NotNull; -import dev.dubhe.anvilcraft.util.Utils; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; @@ -22,7 +21,7 @@ private boolean isLoaded(String clazz) { public void onLoad(String mixinPackage) { hasZetaPiston = AnvilCraftMixinPlugin.class.getClassLoader() .getResource("org/violetmoon/zeta/piston/ZetaPistonStructureResolver.class") != null; - hasCreate = Utils.isLoaded("create"); + hasCreate = this.isLoaded("com/simibubi/create/Create.class"); hasZetaPiston = this.isLoaded("org/violetmoon/zeta/piston/ZetaPistonStructureResolver.class"); hasReiScreen = this.isLoaded("me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.class"); } From dbc13aa377085a80250b298f592b5904d15029c2 Mon Sep 17 00:00:00 2001 From: dmzz-yyhyy Date: Fri, 28 Jun 2024 22:51:35 +0800 Subject: [PATCH 7/8] =?UTF-8?q?eventListener=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/event/forge/LevelEventListener.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java index 53e9fb486..d231fc77e 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java @@ -7,6 +7,8 @@ import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.server.level.ServerLevel; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.event.level.LevelEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -23,6 +25,14 @@ public static void onLevelLoad(@NotNull LevelEvent.Load event) { if (event.getLevel() instanceof ServerLevel serverLevel) AnvilCraftBlockPlacer.anvilCraftBlockPlacer = new AnvilCraftBlockPlacerFakePlayer(serverLevel); + } + + /** + * 客户端世界加载事件 + */ + @OnlyIn(Dist.CLIENT) + @SubscribeEvent + public static void onClientLevelLoad(@NotNull LevelEvent.Load event) { if (event.getLevel() instanceof ClientLevel clientLevel) { AnvilRecipeManager.updateRecipes(clientLevel.getRecipeManager(), clientLevel.registryAccess()); } From 275d0b40f73d375b5d41d089f10c9dbc2ffc3888 Mon Sep 17 00:00:00 2001 From: dmzz-yyhyy Date: Sat, 29 Jun 2024 02:04:09 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E6=96=B9=E9=9D=A2=E9=85=8D=E6=96=B9=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=99=A8=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/recipe/AnvilRecipeManager.java | 2 + .../data/recipe/anvil/AnvilRecipe.java | 5 +- .../dubhe/anvilcraft/init/ModNetworks.java | 6 ++ .../network/ClientRecipeManagerSyncPack.java | 83 +++++++++++++++++++ .../event/fabric/PlayerEventListener.java | 12 +++ .../event/forge/LevelEventListener.java | 15 ---- .../event/forge/PlayerEventListener.java | 11 +++ 7 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/network/ClientRecipeManagerSyncPack.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/recipe/AnvilRecipeManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/recipe/AnvilRecipeManager.java index cb8f96d61..38b88c066 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/recipe/AnvilRecipeManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/recipe/AnvilRecipeManager.java @@ -5,6 +5,7 @@ import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe; import dev.dubhe.anvilcraft.init.ModRecipeTypes; import lombok.Getter; +import lombok.Setter; import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.BlastingRecipe; @@ -22,6 +23,7 @@ import java.util.List; public class AnvilRecipeManager { + @Setter @Getter private static List anvilRecipeList = List.of(); public static List externalRecipeList = new ArrayList<>(); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipe.java b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipe.java index 415baed0f..ada5be229 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipe.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipe.java @@ -76,16 +76,15 @@ import static dev.dubhe.anvilcraft.api.power.IPowerComponent.OVERLOAD; + +@Getter @SuppressWarnings("unused") public class AnvilRecipe implements Recipe { private final ResourceLocation id; - @Getter private final List predicates = new ArrayList<>(); - @Getter private final List outcomes = new ArrayList<>(); private final ItemStack icon; private final Map data = new HashMap<>(); - @Getter private AnvilRecipeType anvilRecipeType = AnvilRecipeType.GENERIC; public AnvilRecipe(ResourceLocation id, ItemStack icon) { diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModNetworks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModNetworks.java index 94182ac11..ed91e8459 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModNetworks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModNetworks.java @@ -2,6 +2,7 @@ import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.network.Network; +import dev.dubhe.anvilcraft.network.ClientRecipeManagerSyncPack; import dev.dubhe.anvilcraft.network.ClientboundMutedSoundSyncPacket; import dev.dubhe.anvilcraft.network.HammerUsePack; import dev.dubhe.anvilcraft.network.HeliostatsIrradiationPack; @@ -91,6 +92,11 @@ public class ModNetworks { HeliostatsIrradiationPack.class, HeliostatsIrradiationPack::new ); + public static final ResourceLocation CLIENT_RECIPE_MANAGER_SYNC = Network.register( + AnvilCraft.of("client_recipe_manager_sync"), + ClientRecipeManagerSyncPack.class, ClientRecipeManagerSyncPack::new + ); + public static void register() { } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/network/ClientRecipeManagerSyncPack.java b/common/src/main/java/dev/dubhe/anvilcraft/network/ClientRecipeManagerSyncPack.java new file mode 100644 index 000000000..ca7b5c071 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/network/ClientRecipeManagerSyncPack.java @@ -0,0 +1,83 @@ +package dev.dubhe.anvilcraft.network; + +import dev.dubhe.anvilcraft.api.network.Packet; +import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; +import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipe; +import dev.dubhe.anvilcraft.data.recipe.anvil.AnvilRecipeType; +import dev.dubhe.anvilcraft.data.recipe.anvil.RecipeOutcome; +import dev.dubhe.anvilcraft.data.recipe.anvil.RecipePredicate; +import dev.dubhe.anvilcraft.init.ModNetworks; +import lombok.Getter; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +@Getter +public class ClientRecipeManagerSyncPack implements Packet { + private final List anvilRecipes; + + /** + * 电网同步 + */ + public ClientRecipeManagerSyncPack(List anvilRecipeList) { + this.anvilRecipes = anvilRecipeList; + } + + /** + * @param buf 缓冲区 + */ + public ClientRecipeManagerSyncPack(@NotNull FriendlyByteBuf buf) { + int index = buf.readInt(); + ArrayList anvilRecipes = new ArrayList<>(); + for (int i = 0; i < index; i++) { + AnvilRecipe recipe = new AnvilRecipe(buf.readResourceLocation(), buf.readItem()); + recipe.setAnvilRecipeType(AnvilRecipeType.valueOf(buf.readUtf().toUpperCase())); + int size; + size = buf.readVarInt(); + for (int j = 0; j < size; j++) { + recipe.addPredicates(RecipePredicate.fromNetwork(buf)); + } + size = buf.readVarInt(); + for (int j = 0; j < size; j++) { + recipe.addOutcomes(RecipeOutcome.fromNetwork(buf)); + } + anvilRecipes.add(recipe); + } + this.anvilRecipes = anvilRecipes; + } + + @Override + public ResourceLocation getType() { + return ModNetworks.CLIENT_RECIPE_MANAGER_SYNC; + } + + @Override + public void encode(@NotNull FriendlyByteBuf buf) { + buf.writeInt(anvilRecipes.size()); + for (AnvilRecipe recipe : anvilRecipes) { + buf.writeResourceLocation(recipe.getId()); + buf.writeItem(recipe.getIcon()); + buf.writeUtf(recipe.getAnvilRecipeType().toString()); + buf.writeVarInt(recipe.getPredicates().size()); + for (RecipePredicate predicate : recipe.getPredicates()) { + predicate.toNetwork(buf); + } + buf.writeVarInt(recipe.getOutcomes().size()); + for (RecipeOutcome outcome : recipe.getOutcomes()) { + outcome.toNetwork(buf); + } + } + } + + @Override + @Environment(EnvType.CLIENT) + public void handler() { + Minecraft.getInstance().execute(() -> AnvilRecipeManager.setAnvilRecipeList(this.anvilRecipes)); + } +} diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/PlayerEventListener.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/PlayerEventListener.java index b833fb007..ff8ff03a0 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/PlayerEventListener.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/PlayerEventListener.java @@ -2,7 +2,12 @@ import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.event.entity.PlayerEvent; +import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; +import dev.dubhe.anvilcraft.network.ClientRecipeManagerSyncPack; import net.fabricmc.fabric.api.event.player.UseEntityCallback; +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; @@ -17,6 +22,7 @@ public class PlayerEventListener { */ public static void init() { UseEntityCallback.EVENT.register(PlayerEventListener::useEntity); + ServerPlayConnectionEvents.INIT.register(PlayerEventListener::serverPlayConnectionEvent); } private static InteractionResult useEntity( @@ -28,4 +34,10 @@ private static InteractionResult useEntity( AnvilCraft.EVENT_BUS.post(playerEvent); return playerEvent.getResult(); } + + private static void serverPlayConnectionEvent( + ServerGamePacketListenerImpl handler, MinecraftServer server + ) { + new ClientRecipeManagerSyncPack(AnvilRecipeManager.getAnvilRecipeList()).send(handler.player); + } } diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java index d231fc77e..e3e9cecb1 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/LevelEventListener.java @@ -3,12 +3,8 @@ import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.entity.fakeplayer.forge.AnvilCraftBlockPlacerFakePlayer; import dev.dubhe.anvilcraft.api.entity.player.AnvilCraftBlockPlacer; -import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; -import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.server.level.ServerLevel; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.event.level.LevelEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -27,17 +23,6 @@ public static void onLevelLoad(@NotNull LevelEvent.Load event) { new AnvilCraftBlockPlacerFakePlayer(serverLevel); } - /** - * 客户端世界加载事件 - */ - @OnlyIn(Dist.CLIENT) - @SubscribeEvent - public static void onClientLevelLoad(@NotNull LevelEvent.Load event) { - if (event.getLevel() instanceof ClientLevel clientLevel) { - AnvilRecipeManager.updateRecipes(clientLevel.getRecipeManager(), clientLevel.registryAccess()); - } - } - /** * 世界卸载事件 */ diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/PlayerEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/PlayerEventListener.java index 4c57ee3c6..0e987fec8 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/PlayerEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/PlayerEventListener.java @@ -2,12 +2,15 @@ import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.event.entity.PlayerEvent; +import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.event.TooltipEventListener; +import dev.dubhe.anvilcraft.network.ClientRecipeManagerSyncPack; import net.minecraft.world.InteractionResult; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.network.NetworkEvent; import org.jetbrains.annotations.NotNull; @@ -33,4 +36,12 @@ public static void useEntity(@NotNull PlayerInteractEvent.EntityInteract event) public static void itemTooltip(@NotNull ItemTooltipEvent event) { TooltipEventListener.addTooltip(event.getItemStack(), event.getToolTip()); } + + @SubscribeEvent + public static void serverCustomPayloadEvent( + @NotNull NetworkEvent.LoginPayloadEvent event + ) { + new ClientRecipeManagerSyncPack(AnvilRecipeManager.getAnvilRecipeList()) + .send(event.getSource().get().getSender()); + } }