From d06bba416da2069774eaa9371e8263cd2832ea57 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 6 Aug 2024 13:49:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=BA=20AnvilCraftingContext=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E7=94=B1=E6=95=B0=E6=8D=AE=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recipe/anvil/AnvilCraftingContext.java | 47 +++++++++++++++++-- .../event/anvil/AnvilEventListener.java | 2 +- .../GiantAnvilLandingEventListener.java | 6 +-- ...tAnvilMultiblockCraftingEventListener.java | 2 +- .../mixin/plugin/AnvilCraftMixinPlugin.java | 1 - 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilCraftingContext.java b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilCraftingContext.java index 73d2fdf68..2a39c286c 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilCraftingContext.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilCraftingContext.java @@ -1,7 +1,6 @@ package dev.dubhe.anvilcraft.data.recipe.anvil; import lombok.Getter; -import lombok.Setter; import net.minecraft.core.BlockPos; import net.minecraft.world.Container; import net.minecraft.world.entity.item.FallingBlockEntity; @@ -14,6 +13,7 @@ import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -21,24 +21,44 @@ /** * 铁砧合成上下文 */ -@Getter public class AnvilCraftingContext implements Container, StackedContentsCompatible { + private final AnvilCraftingContext parent; + @Getter private final Level level; + @Getter private final BlockPos pos; + @Getter private final FallingBlockEntity entity; - @Setter + @Getter private boolean isAnvilDamage = false; private final Set> outputs = new HashSet<>(); + private final Map data = new HashMap<>(); /** - * 初始化 AnvilCraftingContainer + * 初始化 AnvilCraftingContext * * @param level 世界 * @param pos 位置 * @param entity 铁砧实体 */ public AnvilCraftingContext(Level level, BlockPos pos, FallingBlockEntity entity) { + this.parent = null; + this.level = level; + this.pos = pos; + this.entity = entity; + } + + /** + * 初始化 AnvilCraftingContext + * + * @param parent 父节点 + * @param level 世界 + * @param pos 位置 + * @param entity 铁砧实体 + */ + private AnvilCraftingContext(AnvilCraftingContext parent, Level level, BlockPos pos, FallingBlockEntity entity) { + this.parent = parent; this.level = level; this.pos = pos; this.entity = entity; @@ -98,6 +118,7 @@ public void fillStackedContents(@NotNull StackedContents contents) { * @return 添加是否成功 */ public boolean addOutputsItem(Vec3 pos, ItemStack stack) { + if (parent != null) parent.addOutputsItem(pos, stack); stack = stack.copy(); for (Map.Entry entry : this.outputs) { if (stack.isEmpty()) continue; @@ -113,6 +134,11 @@ public boolean addOutputsItem(Vec3 pos, ItemStack stack) { return this.outputs.add(Map.entry(pos, stack)); } + public void setAnvilDamage(boolean anvilDamage) { + if (parent != null) parent.setAnvilDamage(anvilDamage); + isAnvilDamage = anvilDamage; + } + /** * 向世界中输出物品实体 */ @@ -126,4 +152,17 @@ public void spawnItemEntity() { this.level.addFreshEntity(entity); } } + + public void addData(String key, T value) { + this.data.put(key, value); + } + + @SuppressWarnings("unchecked") + public T getData(String key, Class typeOfT) { + return (T) this.data.get(key); + } + + public AnvilCraftingContext copy() { + return new AnvilCraftingContext(this, this.level, this.pos, this.entity); + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/anvil/AnvilEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/anvil/AnvilEventListener.java index 590b7a8c2..97a891c5c 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/anvil/AnvilEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/anvil/AnvilEventListener.java @@ -283,7 +283,7 @@ private void spawnEntities( private void anvilProcess(AnvilRecipe recipe, AnvilCraftingContext context, AnvilFallOnLandEvent event) { int counts = 0; while (counts < AnvilCraft.config.anvilEfficiency) { - if (!recipe.craft(context)) break; + if (!recipe.craft(context.copy())) break; counts++; } if (context.isAnvilDamage()) event.setAnvilDamage(true); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilLandingEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilLandingEventListener.java index 6b4a616cb..2bff5dbec 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilLandingEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilLandingEventListener.java @@ -186,15 +186,15 @@ public class GiantAnvilLandingEventListener { (blockPosList, level) -> { for (BlockPos pos : blockPosList) { BlockPos pos1 = pos.mutable(); - AnvilCraftingContext container = new AnvilCraftingContext(level, pos1, null); + AnvilCraftingContext context = new AnvilCraftingContext(level, pos1, null); Optional optional = AnvilRecipeManager.getAnvilRecipeList().stream() .filter(recipe -> recipe.getAnvilRecipeType() == AnvilRecipeType.BLOCK_SMASH - && recipe.matches(container, level) + && recipe.matches(context, level) ).findFirst(); if (optional.isPresent()) { AnvilRecipe recipe = optional.get(); - recipe.craft(container); + recipe.craft(context.copy()); level.destroyBlock(pos.below(), true); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilMultiblockCraftingEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilMultiblockCraftingEventListener.java index df3caf907..5f6a138b6 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilMultiblockCraftingEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilMultiblockCraftingEventListener.java @@ -35,7 +35,7 @@ public void onLand(@NotNull GiantAnvilFallOnLandEvent event) { private void anvilProcess(AnvilRecipe recipe, AnvilCraftingContext context) { int counts = 0; while (counts < AnvilCraft.config.anvilEfficiency) { - if (!recipe.craft(context)) break; + if (!recipe.craft(context.copy())) break; counts++; } context.spawnItemEntity(); 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 358e7b2e2..a50024580 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 @@ -22,7 +22,6 @@ private boolean isLoaded(String clazz) { public void onLoad(String mixinPackage) { hasZetaPiston = AnvilCraftMixinPlugin.class.getClassLoader() .getResource("org/violetmoon/zeta/piston/ZetaPistonStructureResolver.class") != null; - 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 fa8ebbc7a43c4dbae51cc507d270606b0f9f1fe6 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 6 Aug 2024 13:54:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=87=AA=E7=94=B1?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8C=BA=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recipe/anvil/AnvilCraftingContext.java | 63 +++++++++++-------- .../event/anvil/AnvilEventListener.java | 2 +- .../GiantAnvilLandingEventListener.java | 2 +- ...tAnvilMultiblockCraftingEventListener.java | 2 +- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilCraftingContext.java b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilCraftingContext.java index 2a39c286c..64673bdf8 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilCraftingContext.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilCraftingContext.java @@ -23,7 +23,6 @@ */ public class AnvilCraftingContext implements Container, StackedContentsCompatible { - private final AnvilCraftingContext parent; @Getter private final Level level; @Getter @@ -43,22 +42,6 @@ public class AnvilCraftingContext * @param entity 铁砧实体 */ public AnvilCraftingContext(Level level, BlockPos pos, FallingBlockEntity entity) { - this.parent = null; - this.level = level; - this.pos = pos; - this.entity = entity; - } - - /** - * 初始化 AnvilCraftingContext - * - * @param parent 父节点 - * @param level 世界 - * @param pos 位置 - * @param entity 铁砧实体 - */ - private AnvilCraftingContext(AnvilCraftingContext parent, Level level, BlockPos pos, FallingBlockEntity entity) { - this.parent = parent; this.level = level; this.pos = pos; this.entity = entity; @@ -118,7 +101,6 @@ public void fillStackedContents(@NotNull StackedContents contents) { * @return 添加是否成功 */ public boolean addOutputsItem(Vec3 pos, ItemStack stack) { - if (parent != null) parent.addOutputsItem(pos, stack); stack = stack.copy(); for (Map.Entry entry : this.outputs) { if (stack.isEmpty()) continue; @@ -134,8 +116,12 @@ public boolean addOutputsItem(Vec3 pos, ItemStack stack) { return this.outputs.add(Map.entry(pos, stack)); } + /** + * 设置是否强制铁砧损坏 + * + * @param anvilDamage true 表示强制铁砧损坏,false 表示不强制铁砧损坏 + */ public void setAnvilDamage(boolean anvilDamage) { - if (parent != null) parent.setAnvilDamage(anvilDamage); isAnvilDamage = anvilDamage; } @@ -153,16 +139,43 @@ public void spawnItemEntity() { } } + /** + * 向数据集合中添加键值对 + * + * @param key 键,用于唯一标识数据项 + * @param value 值,可以是任意类型的数据 + * @param 泛型参数,表示值的类型 + */ public void addData(String key, T value) { this.data.put(key, value); } - @SuppressWarnings("unchecked") - public T getData(String key, Class typeOfT) { - return (T) this.data.get(key); - } - public AnvilCraftingContext copy() { - return new AnvilCraftingContext(this, this.level, this.pos, this.entity); + /** + * 根据键和类型从数据映射中获取数据 + *

+ * 此方法用于从存储对象的映射中安全地检索特定类型的数据 + *

+ * 如果键不存在,或者存储的值不是指定的类型,则返回 null + * + * @param key 要检索的数据项的键 + * @param typeOfT 要检索的数据项的类型 + * @return 如果找到键且其值匹配指定类型,则返回该值;否则返回 null + */ + public T getData(String key, Class typeOfT) { + // 从映射中获取与键关联的对象 + Object o = this.data.get(key); + // 如果对象不存在,则直接返回null + if (o == null) return null; + // 检查对象是否是请求的类型,如果不是,则返回null + if (!typeOfT.isInstance(o)) return null; + // 类型检查通过,安全地将对象转换为请求的类型并返回 + //noinspection unchecked + return (T) o; + } + + public AnvilCraftingContext clearData() { + this.data.clear(); + return this; } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/anvil/AnvilEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/anvil/AnvilEventListener.java index 97a891c5c..764a25d3c 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/anvil/AnvilEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/anvil/AnvilEventListener.java @@ -283,7 +283,7 @@ private void spawnEntities( private void anvilProcess(AnvilRecipe recipe, AnvilCraftingContext context, AnvilFallOnLandEvent event) { int counts = 0; while (counts < AnvilCraft.config.anvilEfficiency) { - if (!recipe.craft(context.copy())) break; + if (!recipe.craft(context.clearData())) break; counts++; } if (context.isAnvilDamage()) event.setAnvilDamage(true); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilLandingEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilLandingEventListener.java index 2bff5dbec..ac9136b34 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilLandingEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilLandingEventListener.java @@ -194,7 +194,7 @@ public class GiantAnvilLandingEventListener { ).findFirst(); if (optional.isPresent()) { AnvilRecipe recipe = optional.get(); - recipe.craft(context.copy()); + recipe.craft(context.clearData()); level.destroyBlock(pos.below(), true); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilMultiblockCraftingEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilMultiblockCraftingEventListener.java index 5f6a138b6..bb86467f2 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilMultiblockCraftingEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/giantanvil/GiantAnvilMultiblockCraftingEventListener.java @@ -35,7 +35,7 @@ public void onLand(@NotNull GiantAnvilFallOnLandEvent event) { private void anvilProcess(AnvilRecipe recipe, AnvilCraftingContext context) { int counts = 0; while (counts < AnvilCraft.config.anvilEfficiency) { - if (!recipe.craft(context.copy())) break; + if (!recipe.craft(context.clearData())) break; counts++; } context.spawnItemEntity(); From 0be4d5e741ea0eef41d682cc1bc0b6448873ea0b Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 6 Aug 2024 14:24:38 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=9F=B9=E7=AC=BC?= =?UTF-8?q?=E6=88=98=E5=88=A9=E5=93=81=E8=A1=A8=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/block/CrabTrapBlock.java | 4 +- .../generator/loot/CrabTrapLootLoader.java | 4 +- .../event/server/ServerEventListener.java | 2 - .../init/ModLootContextParamSet.java | 16 ---- .../LootContextParamSetsAccessor.java | 8 ++ .../gameplay/crab_trap/common.json | 27 +++++++ .../gameplay/crab_trap/jungle.json | 49 ++++++++++++ .../loot_tables/gameplay/crab_trap/ocean.json | 75 +++++++++++++++++++ .../loot_tables/gameplay/crab_trap/river.json | 39 ++++++++++ .../loot_tables/gameplay/crab_trap/swamp.json | 39 ++++++++++ .../gameplay/crab_trap/warm_ocean.json | 53 +++++++++++++ .../gameplay/crab_trap/common.json | 27 +++++++ .../gameplay/crab_trap/jungle.json | 49 ++++++++++++ .../loot_tables/gameplay/crab_trap/ocean.json | 75 +++++++++++++++++++ .../loot_tables/gameplay/crab_trap/river.json | 39 ++++++++++ .../loot_tables/gameplay/crab_trap/swamp.json | 39 ++++++++++ .../gameplay/crab_trap/warm_ocean.json | 53 +++++++++++++ 17 files changed, 576 insertions(+), 22 deletions(-) delete mode 100644 common/src/main/java/dev/dubhe/anvilcraft/init/ModLootContextParamSet.java create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/common.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/jungle.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/ocean.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/river.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/swamp.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/warm_ocean.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/common.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/jungle.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/ocean.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/river.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/swamp.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/warm_ocean.json diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/CrabTrapBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/CrabTrapBlock.java index 0fddb4cf9..f1b0efc6d 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/CrabTrapBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/CrabTrapBlock.java @@ -5,7 +5,6 @@ import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.block.entity.CrabTrapBlockEntity; import dev.dubhe.anvilcraft.init.ModBlockEntities; -import dev.dubhe.anvilcraft.init.ModLootContextParamSet; import dev.dubhe.anvilcraft.init.ModLootTables; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.core.BlockPos; @@ -39,6 +38,7 @@ import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; @@ -159,7 +159,7 @@ private void tryInsertLoot(BlockState state, ServerLevel level, BlockPos pos, Re if (state.hasBlockEntity()) { LootParams lootParams = new LootParams.Builder(level) .withParameter(LootContextParams.ORIGIN, pos.getCenter()) - .create(ModLootContextParamSet.CRAB_TRAP); + .create(LootContextParamSets.CHEST); LootTable lootTable = level.getServer().getLootData().getLootTable(loot); ObjectArrayList items = lootTable.getRandomItems(lootParams); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/loot/CrabTrapLootLoader.java b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/loot/CrabTrapLootLoader.java index 7ddff9532..594f71a93 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/loot/CrabTrapLootLoader.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/loot/CrabTrapLootLoader.java @@ -2,7 +2,6 @@ import com.tterrag.registrate.providers.loot.RegistrateLootTableProvider; import dev.dubhe.anvilcraft.init.ModItems; -import dev.dubhe.anvilcraft.init.ModLootContextParamSet; import dev.dubhe.anvilcraft.init.ModLootTables; import net.minecraft.advancements.critereon.LocationPredicate; import net.minecraft.world.item.Items; @@ -10,6 +9,7 @@ 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.parameters.LootContextParamSets; import net.minecraft.world.level.storage.loot.predicates.LocationCheck; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition; @@ -96,7 +96,7 @@ public class CrabTrapLootLoader { * @param provider 提供器 */ public static void init(RegistrateLootTableProvider provider) { - provider.addLootAction(ModLootContextParamSet.CRAB_TRAP, (bi) -> { + provider.addLootAction(LootContextParamSets.CHEST, (bi) -> { bi.accept(ModLootTables.CRAB_TRAP_COMMON, COMMON); bi.accept(ModLootTables.CRAB_TRAP_RIVER, RIVER); bi.accept(ModLootTables.CRAB_TRAP_OCEAN, OCEAN); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/server/ServerEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/server/ServerEventListener.java index 65029c238..789caa317 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/server/ServerEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/server/ServerEventListener.java @@ -7,7 +7,6 @@ import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.api.world.load.LevelLoadManager; import dev.dubhe.anvilcraft.init.ModHammerInits; -import dev.dubhe.anvilcraft.init.ModLootContextParamSet; import org.jetbrains.annotations.NotNull; public class ServerEventListener { @@ -23,7 +22,6 @@ public void onServerStarted(@NotNull ServerStartedEvent event) { HammerManager.register(); AnvilRecipeManager.updateRecipes(event.getServer().getRecipeManager(), event.getServer().registryAccess()); LevelLoadManager.notifyServerStarted(); - ModLootContextParamSet.register(); } @SuppressWarnings("unused") diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModLootContextParamSet.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModLootContextParamSet.java deleted file mode 100644 index 9337507bd..000000000 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModLootContextParamSet.java +++ /dev/null @@ -1,16 +0,0 @@ -package dev.dubhe.anvilcraft.init; - -import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.mixin.accessor.LootContextParamSetsAccessor; -import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; - -public class ModLootContextParamSet { - public static final LootContextParamSet CRAB_TRAP = LootContextParamSet.builder() - .required(LootContextParams.ORIGIN) - .build(); - - public static void register() { - LootContextParamSetsAccessor.getRegistry().put(AnvilCraft.of("crab_trap"), CRAB_TRAP); - } -} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/mixin/accessor/LootContextParamSetsAccessor.java b/common/src/main/java/dev/dubhe/anvilcraft/mixin/accessor/LootContextParamSetsAccessor.java index 84cdac5cc..a4ff2664a 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/mixin/accessor/LootContextParamSetsAccessor.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/mixin/accessor/LootContextParamSetsAccessor.java @@ -6,6 +6,9 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.function.Consumer; /** * 访问器 @@ -16,4 +19,9 @@ public interface LootContextParamSetsAccessor { static BiMap getRegistry() { throw new UnsupportedOperationException(); } + + @Invoker("register") + static LootContextParamSet register(String registryName, Consumer builderConsumer) { + throw new UnsupportedOperationException(); + } } diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/common.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/common.json new file mode 100644 index 000000000..2b5e7b20d --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/common.json @@ -0,0 +1,27 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "anvilcraft:crab_claw" + }, + { + "type": "minecraft:item", + "name": "minecraft:seagrass", + "weight": 15 + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/common" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/jungle.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/jungle.json new file mode 100644 index 000000000..2960d51c4 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/jungle.json @@ -0,0 +1,49 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:jungle" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:bamboo_jungle" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:sparse_jungle" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:bamboo" + }, + { + "type": "minecraft:item", + "name": "minecraft:cocoa_beans" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/jungle" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/ocean.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/ocean.json new file mode 100644 index 000000000..7411cfa03 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/ocean.json @@ -0,0 +1,75 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:cold_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:deep_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:deep_cold_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:frozen_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:deep_frozen_ocean" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:cod" + }, + { + "type": "minecraft:item", + "name": "minecraft:kelp" + }, + { + "type": "minecraft:item", + "name": "minecraft:nautilus_shell" + }, + { + "type": "minecraft:item", + "name": "minecraft:ink_sac" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/ocean" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/river.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/river.json new file mode 100644 index 000000000..f772b3616 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/river.json @@ -0,0 +1,39 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:river" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:frozen_river" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:salmon" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/river" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/swamp.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/swamp.json new file mode 100644 index 000000000..60971055c --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/swamp.json @@ -0,0 +1,39 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:swamp" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:mangrove_swamp" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:lily_pad" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/swamp" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/warm_ocean.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/warm_ocean.json new file mode 100644 index 000000000..def06b39c --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/warm_ocean.json @@ -0,0 +1,53 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:warm_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:lukewarm_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:deep_lukewarm_ocean" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:tropical_fish" + }, + { + "type": "minecraft:item", + "name": "minecraft:pufferfish" + }, + { + "type": "minecraft:item", + "name": "minecraft:ink_sac" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/warm_ocean" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/common.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/common.json new file mode 100644 index 000000000..2b5e7b20d --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/common.json @@ -0,0 +1,27 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "anvilcraft:crab_claw" + }, + { + "type": "minecraft:item", + "name": "minecraft:seagrass", + "weight": 15 + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/common" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/jungle.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/jungle.json new file mode 100644 index 000000000..2960d51c4 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/jungle.json @@ -0,0 +1,49 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:jungle" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:bamboo_jungle" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:sparse_jungle" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:bamboo" + }, + { + "type": "minecraft:item", + "name": "minecraft:cocoa_beans" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/jungle" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/ocean.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/ocean.json new file mode 100644 index 000000000..7411cfa03 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/ocean.json @@ -0,0 +1,75 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:cold_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:deep_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:deep_cold_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:frozen_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:deep_frozen_ocean" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:cod" + }, + { + "type": "minecraft:item", + "name": "minecraft:kelp" + }, + { + "type": "minecraft:item", + "name": "minecraft:nautilus_shell" + }, + { + "type": "minecraft:item", + "name": "minecraft:ink_sac" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/ocean" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/river.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/river.json new file mode 100644 index 000000000..f772b3616 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/river.json @@ -0,0 +1,39 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:river" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:frozen_river" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:salmon" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/river" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/swamp.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/swamp.json new file mode 100644 index 000000000..60971055c --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/swamp.json @@ -0,0 +1,39 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:swamp" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:mangrove_swamp" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:lily_pad" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/swamp" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/warm_ocean.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/warm_ocean.json new file mode 100644 index 000000000..def06b39c --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/gameplay/crab_trap/warm_ocean.json @@ -0,0 +1,53 @@ +{ + "type": "minecraft:chest", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:any_of", + "terms": [ + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:warm_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:lukewarm_ocean" + } + }, + { + "condition": "minecraft:location_check", + "predicate": { + "biome": "minecraft:deep_lukewarm_ocean" + } + } + ] + }, + { + "chance": 0.1, + "condition": "minecraft:random_chance" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:tropical_fish" + }, + { + "type": "minecraft:item", + "name": "minecraft:pufferfish" + }, + { + "type": "minecraft:item", + "name": "minecraft:ink_sac" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:gameplay/crab_trap/warm_ocean" +} \ No newline at end of file