diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/recipe/StampingRecipesLoader.java b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/recipe/StampingRecipesLoader.java index 405e371c2..82a7325e0 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/recipe/StampingRecipesLoader.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/recipe/StampingRecipesLoader.java @@ -13,9 +13,12 @@ import net.minecraft.world.phys.Vec3; public class StampingRecipesLoader { - - - public static void init(RegistrateRecipeProvider provider) { + /** + * 初始化配方 + * + * @param provider 配方提供器 + */ + public static void init(RegistrateRecipeProvider provider) { stamping(Items.IRON_INGOT, Items.HEAVY_WEIGHTED_PRESSURE_PLATE, provider); stamping(Items.GOLD_INGOT, Items.LIGHT_WEIGHTED_PRESSURE_PLATE, provider); stamping(Items.SUGAR_CANE, Items.PAPER, provider); @@ -32,23 +35,39 @@ public static void init(RegistrateRecipeProvider provider) { AnvilRecipe.Builder.create(RecipeCategory.MISC) .hasBlock(ModBlocks.STAMPING_PLATFORM.get()) .hasItemIngredient(new Vec3(0.0, -0.75, 0.0), Items.HEART_OF_THE_SEA) - .spawnItem(new Vec3(0.0, -0.75, 0.0), ModItems.SEA_HEART_SHELL_SHARD,3) - .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5,ModItems.SEA_HEART_SHELL_SHARD) - .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5,ModItems.SEA_HEART_SHELL_SHARD) + .spawnItem(new Vec3(0.0, -0.75, 0.0), ModItems.SEA_HEART_SHELL_SHARD, 3) + .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5, ModItems.SEA_HEART_SHELL_SHARD) + .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5, ModItems.SEA_HEART_SHELL_SHARD) .spawnItem(new Vec3(0.0, -0.75, 0.0), ModItems.SAPPHIRE) .unlockedBy(AnvilCraftDatagen.hasItem(Items.HEART_OF_THE_SEA), AnvilCraftDatagen.has(Items.HEART_OF_THE_SEA)) .save(provider, AnvilCraft.of("stamping/sea_heart_shell_shard")); AnvilRecipe.Builder.create(RecipeCategory.MISC) .hasBlock(ModBlocks.STAMPING_PLATFORM.get()) .hasItemIngredient(new Vec3(0.0, -0.75, 0.0), ModItems.PRISMARINE_CLUSTER) - .spawnItem(new Vec3(0.0, -0.75, 0.0),0.15, ModItems.PRISMARINE_BLADE) - .spawnItem(new Vec3(0.0, -0.75, 0.0), Items.PRISMARINE_CRYSTALS,2) + .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.15, ModItems.PRISMARINE_BLADE) + .spawnItem(new Vec3(0.0, -0.75, 0.0), Items.PRISMARINE_CRYSTALS, 2) .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.5, Items.PRISMARINE_CRYSTALS) .spawnItem(new Vec3(0.0, -0.75, 0.0), Items.PRISMARINE_SHARD) .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.PRISMARINE_CLUSTER.get()), AnvilCraftDatagen.has(ModItems.PRISMARINE_CLUSTER)) .save(provider, AnvilCraft.of("stamping/prismarine_blade")); + AnvilRecipe.Builder.create(RecipeCategory.MISC) + .hasBlock(ModBlocks.STAMPING_PLATFORM.get()) + .hasItemIngredient(new Vec3(0.0, -0.75, 0.0), ModItems.GEODE) + .spawnItem(new Vec3(0.0, -0.75, 0.0), Items.AMETHYST_SHARD, 2) + .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.25, ModItems.TOPAZ) + .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.25, ModItems.SAPPHIRE) + .spawnItem(new Vec3(0.0, -0.75, 0.0), 0.25, ModItems.RUBY) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.PRISMARINE_CLUSTER.get()), AnvilCraftDatagen.has(ModItems.PRISMARINE_CLUSTER)) + .save(provider, AnvilCraft.of("stamping/geode_2_jewel")); } + /** + * 生成简单冲压配方 + * + * @param item 原料 + * @param item1 产物 + * @param provider 配方提供器 + */ public static void stamping(Item item, Item item1, RegistrateRecipeProvider provider) { AnvilRecipe.Builder.create(RecipeCategory.MISC) .hasBlock(ModBlocks.STAMPING_PLATFORM.get()) diff --git a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/stamping/geode_2_jewel.json b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/stamping/geode_2_jewel.json new file mode 100644 index 000000000..008c9ce2f --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/stamping/geode_2_jewel.json @@ -0,0 +1,35 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_prismarine_cluster": { + "conditions": { + "items": [ + { + "items": [ + "anvilcraft:prismarine_cluster" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "anvilcraft:stamping/geode_2_jewel" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_prismarine_cluster", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "anvilcraft:stamping/geode_2_jewel" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/stamping/geode_2_jewel.json b/fabric/src/generated/resources/data/anvilcraft/recipes/stamping/geode_2_jewel.json new file mode 100644 index 000000000..08ed0bde3 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/stamping/geode_2_jewel.json @@ -0,0 +1,89 @@ +{ + "type": "anvilcraft:anvil_processing", + "icon": { + "count": 2, + "item": "minecraft:amethyst_shard" + }, + "outcomes": [ + { + "type": "spawn_item", + "chance": 1.0, + "offset": [ + 0.0, + -0.75, + 0.0 + ], + "result": { + "count": 2, + "item": "minecraft:amethyst_shard" + } + }, + { + "type": "spawn_item", + "chance": 0.25, + "offset": [ + 0.0, + -0.75, + 0.0 + ], + "result": { + "item": "anvilcraft:topaz" + } + }, + { + "type": "spawn_item", + "chance": 0.25, + "offset": [ + 0.0, + -0.75, + 0.0 + ], + "result": { + "item": "anvilcraft:sapphire" + } + }, + { + "type": "spawn_item", + "chance": 0.25, + "offset": [ + 0.0, + -0.75, + 0.0 + ], + "result": { + "item": "anvilcraft:ruby" + } + } + ], + "predicates": [ + { + "type": "has_block", + "match_block": { + "blocks": [ + "anvilcraft:stamping_platform" + ] + }, + "offset": [ + 0.0, + -1.0, + 0.0 + ] + }, + { + "type": "has_item_ingredient", + "match_item": { + "count": { + "min": 1 + }, + "items": [ + "anvilcraft:geode" + ] + }, + "offset": [ + 0.0, + -0.75, + 0.0 + ] + } + ] +} \ No newline at end of file diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/fabric/AnvilCraftFabric.java b/fabric/src/main/java/dev/dubhe/anvilcraft/fabric/AnvilCraftFabric.java index faffa8b53..99f928abc 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/fabric/AnvilCraftFabric.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/fabric/AnvilCraftFabric.java @@ -4,6 +4,7 @@ import dev.dubhe.anvilcraft.init.ModCommands; import dev.dubhe.anvilcraft.init.fabric.ModRecipeTypesFabric; import dev.dubhe.anvilcraft.listener.fabric.AnvilHammerListener; +import dev.dubhe.anvilcraft.listener.fabric.LootTableListener; import dev.dubhe.anvilcraft.utils.fabric.ServerHooks; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; @@ -15,6 +16,7 @@ public void onInitialize() { ServerHooks.init(); ModRecipeTypesFabric.register(); AnvilHammerListener.register(); + LootTableListener.register(); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ModCommands.register(dispatcher)); } } \ No newline at end of file diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/listener/fabric/LootTableListener.java b/fabric/src/main/java/dev/dubhe/anvilcraft/listener/fabric/LootTableListener.java new file mode 100644 index 000000000..084c2c876 --- /dev/null +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/listener/fabric/LootTableListener.java @@ -0,0 +1,34 @@ +package dev.dubhe.anvilcraft.listener.fabric; + +import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.init.ModItems; +import net.fabricmc.fabric.api.loot.v2.LootTableEvents; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.storage.loot.BuiltInLootTables; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction; +import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; +import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator; + +public class LootTableListener { + /** + * 修改战利品表 + */ + public static void register() { + LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> { + if (Blocks.BUDDING_AMETHYST.getLootTable().equals(id)) { + tableBuilder.withPool(new LootPool.Builder() + .add(LootItem.lootTableItem(ModItems.GEODE)) + .apply(SetItemCountFunction.setCount(ConstantValue.exactly(1))) + ); + } + if (BuiltInLootTables.SPAWN_BONUS_CHEST.equals(id)) { + tableBuilder.withPool(new LootPool.Builder() + .add(LootItem.lootTableItem(ModItems.GEODE)) + .apply(SetItemCountFunction.setCount(UniformGenerator.between(3, 6))) + ); + } + }); + } +} diff --git a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/stamping/geode_2_jewel.json b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/stamping/geode_2_jewel.json new file mode 100644 index 000000000..008c9ce2f --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/stamping/geode_2_jewel.json @@ -0,0 +1,35 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_prismarine_cluster": { + "conditions": { + "items": [ + { + "items": [ + "anvilcraft:prismarine_cluster" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "anvilcraft:stamping/geode_2_jewel" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_prismarine_cluster", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "anvilcraft:stamping/geode_2_jewel" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/stamping/geode_2_jewel.json b/forge/src/generated/resources/data/anvilcraft/recipes/stamping/geode_2_jewel.json new file mode 100644 index 000000000..08ed0bde3 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/recipes/stamping/geode_2_jewel.json @@ -0,0 +1,89 @@ +{ + "type": "anvilcraft:anvil_processing", + "icon": { + "count": 2, + "item": "minecraft:amethyst_shard" + }, + "outcomes": [ + { + "type": "spawn_item", + "chance": 1.0, + "offset": [ + 0.0, + -0.75, + 0.0 + ], + "result": { + "count": 2, + "item": "minecraft:amethyst_shard" + } + }, + { + "type": "spawn_item", + "chance": 0.25, + "offset": [ + 0.0, + -0.75, + 0.0 + ], + "result": { + "item": "anvilcraft:topaz" + } + }, + { + "type": "spawn_item", + "chance": 0.25, + "offset": [ + 0.0, + -0.75, + 0.0 + ], + "result": { + "item": "anvilcraft:sapphire" + } + }, + { + "type": "spawn_item", + "chance": 0.25, + "offset": [ + 0.0, + -0.75, + 0.0 + ], + "result": { + "item": "anvilcraft:ruby" + } + } + ], + "predicates": [ + { + "type": "has_block", + "match_block": { + "blocks": [ + "anvilcraft:stamping_platform" + ] + }, + "offset": [ + 0.0, + -1.0, + 0.0 + ] + }, + { + "type": "has_item_ingredient", + "match_item": { + "count": { + "min": 1 + }, + "items": [ + "anvilcraft:geode" + ] + }, + "offset": [ + 0.0, + -0.75, + 0.0 + ] + } + ] +} \ No newline at end of file diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/forge/AnvilCraftForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/forge/AnvilCraftForge.java index 0e2d0819b..be719cbfa 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/forge/AnvilCraftForge.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/forge/AnvilCraftForge.java @@ -22,7 +22,6 @@ public AnvilCraftForge() { AnvilCraft.init(); bus.register(new ModRecipeTypesForge()); MinecraftForge.EVENT_BUS.addListener(AnvilCraftForge::registerCommand); - MinecraftForge.EVENT_BUS.register(new AnvilHammerListener()); ModLoadingContext.get().registerExtensionPoint( ConfigScreenHandler.ConfigScreenFactory.class, diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/listener/AnvilHammerListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/listener/AnvilHammerListener.java index 92ff0a858..bedba4066 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/listener/AnvilHammerListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/listener/AnvilHammerListener.java @@ -1,13 +1,18 @@ package dev.dubhe.anvilcraft.listener; +import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.item.AnvilHammerItem; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.jetbrains.annotations.NotNull; +@Mod.EventBusSubscriber(modid = AnvilCraft.MOD_ID) public class AnvilHammerListener { @SubscribeEvent - public void anvilHammer(PlayerInteractEvent.LeftClickBlock leftClickBlock) { - if (leftClickBlock.getEntity().getItemInHand(leftClickBlock.getEntity().getUsedItemHand()).getItem() instanceof AnvilHammerItem anvilHammer) { + public static void anvilHammer(@NotNull PlayerInteractEvent.LeftClickBlock leftClickBlock) { + if (leftClickBlock.getEntity().getItemInHand(leftClickBlock.getEntity().getUsedItemHand()).getItem() + instanceof AnvilHammerItem anvilHammer) { anvilHammer.useAttackBlock(leftClickBlock.getEntity(), leftClickBlock.getPos(), leftClickBlock.getLevel()); } } diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/listener/LootTableListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/listener/LootTableListener.java new file mode 100644 index 000000000..836c0f353 --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/listener/LootTableListener.java @@ -0,0 +1,41 @@ +package dev.dubhe.anvilcraft.listener; + +import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.init.ModItems; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.storage.loot.BuiltInLootTables; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction; +import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; +import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator; +import net.minecraftforge.event.LootTableLoadEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.jetbrains.annotations.NotNull; + +@Mod.EventBusSubscriber(modid = AnvilCraft.MOD_ID) +public class LootTableListener { + @SubscribeEvent + public static void lootTable(@NotNull LootTableLoadEvent event) { + ResourceLocation id = event.getName(); + LootTable table = event.getTable(); + if (Blocks.BUDDING_AMETHYST.getLootTable().equals(id)) { + table.addPool(new LootPool.Builder() + .add(LootItem.lootTableItem(ModItems.GEODE)) + .apply(SetItemCountFunction.setCount(ConstantValue.exactly(1))) + .build() + ); + } + if (BuiltInLootTables.SPAWN_BONUS_CHEST.equals(id)) { + table.addPool(new LootPool.Builder() + .add(LootItem.lootTableItem(ModItems.GEODE)) + .apply(SetItemCountFunction.setCount(UniformGenerator.between(3, 6))) + .build() + ); + } + event.setTable(table); + } +}