From 6c94e4f2aba29d9fd6247d2c584f848637f84f02 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Fri, 28 Mar 2025 11:22:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(bukkit):=20=E6=B7=BB=E5=8A=A0=E4=BD=9C?= =?UTF-8?q?=E7=89=A9=E6=96=B9=E5=9D=97=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=92=8C=E9=83=A8=E5=88=86=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/default/configuration/i18n.yml | 2 + .../default/configuration/plants.yml | 126 ++++++++++++++++++ .../bukkit/block/BlockEventListener.java | 4 + .../loot/condition/CropRipeCondition.java | 29 ++++ .../core/loot/condition/LootConditions.java | 2 + .../core/loot/parameter/LootParameters.java | 1 + 6 files changed, 164 insertions(+) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/CropRipeCondition.java diff --git a/bukkit/loader/src/main/resources/resources/default/configuration/i18n.yml b/bukkit/loader/src/main/resources/resources/default/configuration/i18n.yml index dc46c4640..4e3cc366f 100644 --- a/bukkit/loader/src/main/resources/resources/default/configuration/i18n.yml +++ b/bukkit/loader/src/main/resources/resources/default/configuration/i18n.yml @@ -4,6 +4,7 @@ i18n: item.fairy_flower: "Fairy Flower" item.reed: "Reed" item.flame_cane: "Flame Cane" + item.ender_pearl_crop_seed: "Ender Pearl Flower Seeds" item.bench: "Bench" item.table_lamp: "Table Lamp" item.wooden_chair: "Wooden Chair" @@ -43,6 +44,7 @@ i18n: item.fairy_flower: "仙灵花" item.reed: "芦苇" item.flame_cane: "烈焰甘蔗" + item.ender_pearl_crop_seed: "末影珍珠花种子" item.bench: "长椅" item.table_lamp: "台灯" item.wooden_chair: "木椅" diff --git a/bukkit/loader/src/main/resources/resources/default/configuration/plants.yml b/bukkit/loader/src/main/resources/resources/default/configuration/plants.yml index 172600da7..86f223217 100644 --- a/bukkit/loader/src/main/resources/resources/default/configuration/plants.yml +++ b/bukkit/loader/src/main/resources/resources/default/configuration/plants.yml @@ -35,6 +35,18 @@ items: behavior: type: block_item block: default:flame_cane + default:ender_pearl_crop_seed: + material: paper + custom-model-data: 4003 + data: + item-name: "" + model: + template: default:model/simplified_generated + arguments: + path: "minecraft:item/custom/ender_pearl_crop_seed" + behavior: + type: block_item + block: default:ender_pearl_crop blocks: default:fairy_flower: settings: @@ -167,6 +179,120 @@ blocks: age=5: appearance: default id: 7 + default:ender_pearl_crop: + settings: + template: + - default:hardness/none + - default:sound/grass + overrides: + item: default:ender_pearl_crop_seed + push-reaction: DESTROY + map-color: 15 + is-randomly-ticking: true + behavior: + type: crop_block + grow-speed: 1 + min-grow-light: 9 + bottom-blocks: + - minecraft:end_stone + loot: + pools: + - rolls: 1 + entries: + - type: alternatives + children: + - type: item + item: "default:ender_pearl_crop_seed" + conditions: + - type: survives_explosion + - type: item + item: "minecraft:ender_pearl" + conditions: + - type: crop_ripe + functions: + - type: apply_bonus + enchantment: minecraft:fortune + formula: + type: ore_drops + - type: explosion_decay + count: + type: uniform + min: "1" + max: "5" + states: + properties: + age: + type: int + default: 0 + range: 0~5 + appearances: + default: + state: "sugar_cane:3" + models: + - path: "minecraft:block/custom/ender_pearl_crop_stage1" + generation: + parent: "minecraft:block/crop" + textures: + "crop": "minecraft:block/custom/ender_pearl_crop_stage1" + age1: + state: "sugar_cane:4" + models: + - path: "minecraft:block/custom/ender_pearl_crop_stage2" + generation: + parent: "minecraft:block/crop" + textures: + "crop": "minecraft:block/custom/ender_pearl_crop_stage2" + age2: + state: "sugar_cane:5" + models: + - path: "minecraft:block/custom/ender_pearl_crop_stage3" + generation: + parent: "minecraft:block/crop" + textures: + "crop": "minecraft:block/custom/ender_pearl_crop_stage3" + age3: + state: "sugar_cane:6" + models: + - path: "minecraft:block/custom/ender_pearl_crop_stage4" + generation: + parent: "minecraft:block/crop" + textures: + "crop": "minecraft:block/custom/ender_pearl_crop_stage4" + age4: + state: "sugar_cane:7" + models: + - path: "minecraft:block/custom/ender_pearl_crop_stage5" + generation: + parent: "minecraft:block/crop" + textures: + "crop": "minecraft:block/custom/ender_pearl_crop_stage5" + age5: + state: "sugar_cane:8" + models: + - path: "minecraft:block/custom/ender_pearl_crop_stage6" + generation: + parent: "minecraft:block/crop" + textures: + "crop": "minecraft:block/custom/ender_pearl_crop_stage6" + variants: + age=0: + appearance: default + id: 8 + age=1: + appearance: age1 + id: 9 + age=2: + appearance: age2 + id: 10 + age=3: + appearance: age3 + id: 11 + age=4: + appearance: age4 + id: 12 + age=5: + appearance: age5 + id: 13 recipes: default:paper_from_reed: type: shaped diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java index befb9a1e2..ec3b798ec 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java @@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.block; import io.papermc.paper.event.block.BlockBreakBlockEvent; import net.momirealms.craftengine.bukkit.api.event.CustomBlockBreakEvent; +import net.momirealms.craftengine.bukkit.block.behavior.CropBlockBehavior; import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine; import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; import net.momirealms.craftengine.bukkit.util.*; @@ -138,6 +139,9 @@ public class BlockEventListener implements Listener { builder.withParameter(LootParameters.LOCATION, vec3d); builder.withParameter(LootParameters.PLAYER, serverPlayer); builder.withOptionalParameter(LootParameters.TOOL, itemInHand); + if (state.behavior() instanceof CropBlockBehavior) { + builder.withParameter(LootParameters.CROP_BLOCK, true); + } for (Item item : state.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/CropRipeCondition.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/CropRipeCondition.java new file mode 100644 index 000000000..05248b2c0 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/CropRipeCondition.java @@ -0,0 +1,29 @@ +package net.momirealms.craftengine.core.loot.condition; + +import net.momirealms.craftengine.core.loot.LootContext; +import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.util.Key; + +import java.util.Map; + +public class CropRipeCondition implements LootCondition { + public static final Factory FACTORY = new Factory(); + public static final CropRipeCondition INSTANCE = new CropRipeCondition(); + + @Override + public Key type() { + return LootConditions.CROP_RIPE; + } + + @Override + public boolean test(LootContext lootContext) { + return lootContext.getOptionalParameter(LootParameters.CROP_BLOCK).orElse(false); + } + + public static class Factory implements LootConditionFactory { + @Override + public LootCondition create(Map arguments) { + return INSTANCE; + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java index 806172e90..4dd4ffabc 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java @@ -21,6 +21,7 @@ public class LootConditions { public static final Key ENCHANTMENT = Key.from("craftengine:enchantment"); public static final Key INVERTED = Key.from("craftengine:inverted"); public static final Key FALLING_BLOCK = Key.from("craftengine:falling_block"); + public static final Key CROP_RIPE = Key.from("craftengine:crop_ripe"); static { register(MATCH_ITEM, MatchItemCondition.FACTORY); @@ -31,6 +32,7 @@ public class LootConditions { register(ENCHANTMENT, EnchantmentCondition.FACTORY); register(INVERTED, InvertedCondition.FACTORY); register(FALLING_BLOCK, FallingCondition.FACTORY); + register(CROP_RIPE, CropRipeCondition.FACTORY); } public static void register(Key key, LootConditionFactory factory) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/parameter/LootParameters.java b/core/src/main/java/net/momirealms/craftengine/core/loot/parameter/LootParameters.java index ca09453ea..29b531ea2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/parameter/LootParameters.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/parameter/LootParameters.java @@ -18,4 +18,5 @@ public class LootParameters { public static final ContextKey PLAYER = new ContextKey<>(Key.of("craftengine:player")); public static final ContextKey> TOOL = new ContextKey<>(Key.of("craftengine:tool")); public static final ContextKey BLOCK_STATE = new ContextKey<>(Key.of("craftengine:block_state")); + public static final ContextKey CROP_BLOCK = new ContextKey<>(Key.of("craftengine:crop_block")); }