From c0c2183cef6ea7c9a73fd4ecf2d2dc56f8b75ea4 Mon Sep 17 00:00:00 2001 From: CoolLoong <1542536763@qq.com> Date: Mon, 12 Feb 2024 00:11:07 +0800 Subject: [PATCH] fix: customblock and item --- src/main/java/cn/nukkit/block/Block.java | 17 ++--- .../nukkit/block/customblock/CustomBlock.java | 7 +- .../customblock/CustomBlockDefinition.java | 66 ++++++++++++------- .../block/customblock/data/Geometry.java | 21 ++++-- .../item/customitem/CustomItemDefinition.java | 37 ++++------- 5 files changed, 78 insertions(+), 70 deletions(-) diff --git a/src/main/java/cn/nukkit/block/Block.java b/src/main/java/cn/nukkit/block/Block.java index 0434d01bc..497bf7124 100644 --- a/src/main/java/cn/nukkit/block/Block.java +++ b/src/main/java/cn/nukkit/block/Block.java @@ -1288,10 +1288,6 @@ public static void registerBlockImplementation(int blockId, @NotNull Class SORTED_CUSTOM_BLOCK = new TreeMap<>(MinecraftNamespaceComparator::compareFNV); @@ -1354,10 +1350,10 @@ public static OK registerCustomBlock(@NotNull Map自定义方块id - ID_TO_CUSTOM_BLOCK.put(nextBlockId, entry.getValue());//自定义方块id->自定义方块 + int runtimeId = CustomBlockDefinition.getRuntimeId(entry.getKey()); + CUSTOM_BLOCK_ID_MAP.put(entry.getKey(), runtimeId);//自定义方块标识符->自定义方块id + ID_TO_CUSTOM_BLOCK.put(runtimeId, entry.getValue());//自定义方块id->自定义方块 CUSTOM_BLOCK_DEFINITIONS.add(entry.getValue().getDefinition());//行为包数据 - ++nextBlockId; } var blocks = ID_TO_CUSTOM_BLOCK.values().stream().toList(); var result = BlockStateRegistry.registerCustomBlockState(blocks);//注册方块state @@ -1365,8 +1361,8 @@ public static void initCustomBlock() { throw new CustomBlockStateRegisterException("Register CustomBlock state error, please check all your CustomBlock plugins,contact the plugin author! Error:", result.getError()); } RuntimeItems.getRuntimeMapping().registerCustomBlock(blocks);//注册物品 - blocks.stream().filter( CustomBlock::shouldBeRegisteredInCreative ).forEach( - b -> Item.addCreativeItem(b.toItem()) + blocks.stream().filter(CustomBlock::shouldBeRegisteredInCreative).forEach( + b -> Item.addCreativeItem(b.toItem()) );//注册创造栏物品 } } @@ -1383,7 +1379,7 @@ public static void deleteAllCustomBlock() { ID_TO_CUSTOM_BLOCK.clear(); CUSTOM_BLOCK_ID_MAP.clear(); CUSTOM_BLOCK_DEFINITIONS.clear(); - nextBlockId = 1000; + CustomBlockDefinition.deleteAllCustomBlock(); } @PowerNukkitXOnly @@ -3080,6 +3076,7 @@ public int hashCode() { public long computeUnsignedBlockStateHash() { return Integer.toUnsignedLong(computeBlockStateHash()); } + @PowerNukkitXOnly @Since("1.20.10-r2") public boolean isFertilizable() { diff --git a/src/main/java/cn/nukkit/block/customblock/CustomBlock.java b/src/main/java/cn/nukkit/block/customblock/CustomBlock.java index ae40da34d..dcdfde630 100644 --- a/src/main/java/cn/nukkit/block/customblock/CustomBlock.java +++ b/src/main/java/cn/nukkit/block/customblock/CustomBlock.java @@ -21,12 +21,9 @@ @Since("1.6.0.0-PNX") public interface CustomBlock { /** - * 覆写该方法设置自定义方块的摩擦因数。
- * 警告:如果你想要让玩家在你的自定义方块上的摩擦不同,请覆写{@link CustomBlockDefinition.Builder#clientFriction(float)}方法。 + * 覆写该方法设置自定义方块的摩擦因数。 *

- * {@code @Override} this method to set the friction factor of the custom block.
- * Warning: If you want to make the friction of the player on your custom block different, - * please override the {@link CustomBlockDefinition.Builder#clientFriction(float)} method. + * {@code @Override} this method to set the friction factor of the custom block. */ double getFrictionFactor(); diff --git a/src/main/java/cn/nukkit/block/customblock/CustomBlockDefinition.java b/src/main/java/cn/nukkit/block/customblock/CustomBlockDefinition.java index 7e5880d7d..47cb30550 100644 --- a/src/main/java/cn/nukkit/block/customblock/CustomBlockDefinition.java +++ b/src/main/java/cn/nukkit/block/customblock/CustomBlockDefinition.java @@ -10,12 +10,14 @@ import cn.nukkit.math.Vector3f; import cn.nukkit.nbt.tag.*; import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.Locale; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; /** @@ -26,7 +28,20 @@ @PowerNukkitXOnly @Since("1.19.31-r1") public record CustomBlockDefinition(String identifier, CompoundTag nbt) { + private static final Object2IntOpenHashMap INTERNAL_ALLOCATION_ID_MAP = new Object2IntOpenHashMap<>(); + private static final AtomicInteger CUSTOM_BLOCK_RUNTIMEID = new AtomicInteger(10000); + public int getRuntimeId() { + return CustomBlockDefinition.INTERNAL_ALLOCATION_ID_MAP.getInt(identifier); + } + + public static int getRuntimeId(String identifier) { + return CustomBlockDefinition.INTERNAL_ALLOCATION_ID_MAP.getInt(identifier); + } + + public static void deleteAllCustomBlock() { + CustomBlockDefinition.INTERNAL_ALLOCATION_ID_MAP.clear(); + } public static CustomBlockDefinition.Builder builder(CustomBlock customBlock, String texture) { return builder(customBlock, Materials.builder().any(Materials.RenderMethod.OPAQUE, texture), BlockCreativeCategory.CONSTRUCTION); @@ -62,12 +77,12 @@ public static class Builder { protected Builder(CustomBlock customBlock, Materials materials, BlockCreativeCategory blockCreativeCategory) { this.identifier = customBlock.getNamespaceId(); this.customBlock = customBlock; - + var b = (Block) customBlock; var components = this.nbt.getCompound("components"); //设置一些与PNX内部对应的方块属性 components.putCompound("minecraft:friction", new CompoundTag() - .putFloat("value", (float) (1 - Block.DEFAULT_FRICTION_FACTOR))) + .putFloat("value", (float) Math.min(0.9, Math.max(0, b.getFrictionFactor())))) .putCompound("minecraft:destructible_by_explosion", new CompoundTag() .putInt("explosion_resistance", (int) customBlock.getResistance())) .putCompound("minecraft:light_dampening", new CompoundTag() @@ -79,22 +94,40 @@ protected Builder(CustomBlock customBlock, Materials materials, BlockCreativeCat //设置材质 components.putCompound("minecraft:material_instances", new CompoundTag() .putCompound("mappings", new CompoundTag()) - .putCompound("materials", materials.toCompoundTag())); + .putCompound("materials", new CompoundTag())); + //默认单位立方体方块 components.putCompound("minecraft:unit_cube", new CompoundTag()); + //设置默认单位立方体方块的几何模型 + components.putCompound("minecraft:geometry", new CompoundTag() + .putString("identifier", "minecraft:geometry.full_block") + .putString("culling", "") + .putCompound("bone_visibility", new CompoundTag()) + ); + //设置方块在创造栏的分类 this.nbt.putCompound("menu_category", new CompoundTag() .putString("category", blockCreativeCategory.name().toLowerCase(Locale.ENGLISH)) .putString("group", ItemCreativeGroup.NONE.getGroupName())); //molang版本 - this.nbt.putInt("molangVersion", 6); + this.nbt.putInt("molangVersion", 9); //设置方块的properties var propertiesNBT = getPropertiesNBT(); if (propertiesNBT != null) { - propertiesNBT.setName("properties"); - nbt.putList(propertiesNBT); + nbt.putList("properties", propertiesNBT); } + + int block_id; + if (!INTERNAL_ALLOCATION_ID_MAP.containsKey(identifier)) { + while (INTERNAL_ALLOCATION_ID_MAP.containsValue(block_id = CUSTOM_BLOCK_RUNTIMEID.getAndIncrement())) { + } + INTERNAL_ALLOCATION_ID_MAP.put(identifier, block_id); + } else { + block_id = INTERNAL_ALLOCATION_ID_MAP.getInt(identifier); + } + nbt.putCompound("vanilla_block_data", new CompoundTag().putInt("block_id", block_id) + /*.putString("material", "")*/); //todo Figure what is dirt, maybe that corresponds to https://wiki.bedrock.dev/documentation/materials.html } /** @@ -282,19 +315,6 @@ public Builder blockTags(String... tag) { return this; } - /** - * 客户端摩擦系数,用于控制玩家在自定义方块上行走的速度,值越大,移动越快。 - *

- * the client friction, which is used to control the speed at which the player walks on the custom block.The larger the value, the faster the movement. - */ - @Since("1.20.0-r2") - public Builder clientFriction(float friction) { - this.nbt.getCompound("components") - .putCompound("minecraft:friction", new CompoundTag() - .putFloat("value", friction)); - return this; - } - /** * PNX无法准确提供三个以上属性方块的属性解析,如果出现地图异常,请制作一个该方块相同属性的行为包,利用proxypass和bds抓包获取准确的属性解析。 *

@@ -318,8 +338,8 @@ private ListTag getPropertiesNBT() { if (each.getProperty() instanceof BooleanBlockProperty booleanBlockProperty) { nbtList.add(new CompoundTag().putString("name", booleanBlockProperty.getName()) .putList(new ListTag<>("enum") - .add(new IntTag("", 0)) - .add(new IntTag("", 1)))); + .add(new ByteTag("", 0)) + .add(new ByteTag("", 1)))); } else if (each.getProperty() instanceof IntBlockProperty intBlockProperty) { var enumList = new ListTag("enum"); for (int i = intBlockProperty.getMinValue(); i <= intBlockProperty.getMaxValue(); i++) { @@ -344,8 +364,8 @@ private ListTag getPropertiesNBT() { } else { nbtList.add(new CompoundTag().putString("name", arrayBlockProperty.getName()) .putList(new ListTag<>("enum") - .add(new IntTag("", 0)) - .add(new IntTag("", 1)))); + .add(new ByteTag("", 0)) + .add(new ByteTag("", 1)))); } } else { var enumList = new ListTag("enum"); diff --git a/src/main/java/cn/nukkit/block/customblock/data/Geometry.java b/src/main/java/cn/nukkit/block/customblock/data/Geometry.java index fcb9c1721..f2e5cf466 100644 --- a/src/main/java/cn/nukkit/block/customblock/data/Geometry.java +++ b/src/main/java/cn/nukkit/block/customblock/data/Geometry.java @@ -13,6 +13,7 @@ @Since("1.19.80-r1") public class Geometry implements NBTData { private final String geometryName; + private String culling = ""; private final Map boneVisibilities = new LinkedHashMap<>(); public Geometry(@NotNull String name) { @@ -29,7 +30,7 @@ public Geometry(@NotNull String name) { public Geometry boneVisibility(@NotNull String boneName, boolean isVisibility) { Preconditions.checkNotNull(boneName); Preconditions.checkArgument(!boneName.isBlank()); - this.boneVisibilities.put(boneName, isVisibility ? "true" : "false"); + this.boneVisibilities.put(boneName, isVisibility ? "1.000000" : "0.000000"); return this; } @@ -45,18 +46,26 @@ public Geometry boneVisibility(@NotNull String boneName, String condition) { return this; } + public Geometry culling(@NotNull String cullingName) { + Preconditions.checkNotNull(cullingName); + this.culling = cullingName; + return this; + } + @Override public CompoundTag toCompoundTag() { var boneVisibility = new CompoundTag(); for (var entry : boneVisibilities.entrySet()) { - boneVisibility.putString(entry.getKey(), entry.getValue()); + boneVisibility.putCompound(entry.getKey(), new CompoundTag() + .putString("expression", entry.getValue()) + .putInt("version", 1) + ); } - CompoundTag compoundTag = new CompoundTag("minecraft:geometry") + CompoundTag compoundTag = new CompoundTag() .putString("identifier", geometryName) - .putByte("legacyBlockLightAbsorption", 0) - .putByte("legacyTopRotation", 0); - if (boneVisibilities.size() > 0) { + .putString("culling", culling); + if (!boneVisibilities.isEmpty()) { compoundTag.putCompound("bone_visibility", boneVisibility); } return compoundTag; diff --git a/src/main/java/cn/nukkit/item/customitem/CustomItemDefinition.java b/src/main/java/cn/nukkit/item/customitem/CustomItemDefinition.java index 3a8918a1f..d310b3ee7 100644 --- a/src/main/java/cn/nukkit/item/customitem/CustomItemDefinition.java +++ b/src/main/java/cn/nukkit/item/customitem/CustomItemDefinition.java @@ -363,12 +363,12 @@ public static class ToolBuilder extends SimpleBuilder { var shovelBlocks = new Object2ObjectOpenHashMap(); var hoeBlocks = new Object2ObjectOpenHashMap(); var swordBlocks = new Object2ObjectOpenHashMap(); - for (var name : List.of("minecraft:ice", "minecraft:undyed_shulker_box", "minecraft:shulker_box", "minecraft:prismarine", "minecraft:stone_slab4", "minecraft:prismarine_bricks_stairs", "minecraft:prismarine_stairs", "minecraft:dark_prismarine_stairs", "minecraft:anvil", "minecraft:bone_block", "minecraft:iron_trapdoor", "minecraft:nether_brick_fence", "minecraft:crying_obsidian", "minecraft:magma", "minecraft:smoker", "minecraft:lit_smoker", "minecraft:hopper", "minecraft:redstone_block", "minecraft:mob_spawner", "minecraft:netherite_block", "minecraft:smooth_stone", "minecraft:diamond_block", "minecraft:lapis_block", "minecraft:emerald_block", "minecraft:enchanting_table", "minecraft:end_bricks", "minecraft:cracked_polished_blackstone_bricks", "minecraft:nether_brick", "minecraft:cracked_nether_bricks", "minecraft:purpur_block", "minecraft:purpur_stairs", "minecraft:end_brick_stairs", "minecraft:stone_slab", "minecraft:stone_slab2", "minecraft:stone_slab3", "minecraft:stone_brick_stairs", "minecraft:mossy_stone_brick_stairs", "minecraft:polished_blackstone_bricks", "minecraft:polished_blackstone_stairs", "minecraft:blackstone_wall", "minecraft:blackstone_wall", "minecraft:polished_blackstone_wall", "minecraft:sandstone", "minecraft:grindstone", "minecraft:smooth_stone", "minecraft:brewing_stand", "minecraft:chain", "minecraft:lantern", "minecraft:soul_lantern", "minecraft:ancient_debris", "minecraft:quartz_ore", "minecraft:netherrack", "minecraft:basalt", "minecraft:polished_basalt", "minecraft:stonebrick", "minecraft:warped_nylium", "minecraft:crimson_nylium", "minecraft:end_stone", "minecraft:ender_chest", "minecraft:quartz_block", "minecraft:quartz_stairs", "minecraft:quartz_bricks", "minecraft:quartz_stairs", "minecraft:nether_gold_ore", "minecraft:furnace", "minecraft:blast_furnace", "minecraft:lit_furnace", "minecraft:blast_furnace", "minecraft:blackstone", "minecraft:concrete", "minecraft:deepslate_copper_ore", "minecraft:deepslate_lapis_ore", "minecraft:chiseled_deepslate", "minecraft:cobbled_deepslate", "minecraft:cobbled_deepslate_double_slab", "minecraft:cobbled_deepslate_slab", "minecraft:cobbled_deepslate_stairs", "minecraft:cobbled_deepslate_wall", "minecraft:cracked_deepslate_bricks", "minecraft:cracked_deepslate_tiles", "minecraft:deepslate", "minecraft:deepslate_brick_double_slab", "minecraft:deepslate_brick_slab", "minecraft:deepslate_brick_stairs", "minecraft:deepslate_brick_wall", "minecraft:deepslate_bricks", "minecraft:deepslate_tile_double_slab", "minecraft:deepslate_tile_slab", "minecraft:deepslate_tile_stairs", "minecraft:deepslate_tile_wall", "minecraft:deepslate_tiles", "minecraft:infested_deepslate", "minecraft:polished_deepslate", "minecraft:polished_deepslate_double_slab", "minecraft:polished_deepslate_slab", "minecraft:polished_deepslate_stairs", "minecraft:polished_deepslate_wall", "minecraft:calcite", "minecraft:amethyst_block", "minecraft:amethyst_cluster", "minecraft:budding_amethyst", "minecraft:raw_copper_block", "minecraft:raw_gold_block", "minecraft:raw_iron_block", "minecraft:copper_ore", "minecraft:copper_block", "minecraft:cut_copper", "minecraft:cut_copper_slab", "minecraft:cut_copper_stairs", "minecraft:double_cut_copper_slab", "minecraft:exposed_copper", "minecraft:exposed_cut_copper", "minecraft:exposed_cut_copper_slab", "minecraft:exposed_cut_copper_stairs", "minecraft:exposed_double_cut_copper_slab", "minecraft:oxidized_copper", "minecraft:oxidized_cut_copper", "minecraft:oxidized_cut_copper_slab", "minecraft:oxidized_cut_copper_stairs", "minecraft:oxidized_double_cut_copper_slab", "minecraft:weathered_copper", "minecraft:weathered_cut_copper", "minecraft:weathered_cut_copper_slab", "minecraft:weathered_cut_copper_stairs", "minecraft:weathered_double_cut_copper_slab", "minecraft:waxed_copper", "minecraft:waxed_cut_copper", "minecraft:waxed_cut_copper_slab", "minecraft:waxed_cut_copper_stairs", "minecraft:waxed_double_cut_copper_slab", "minecraft:waxed_exposed_copper", "minecraft:waxed_exposed_cut_copper", "minecraft:waxed_exposed_cut_copper_slab", "minecraft:waxed_exposed_cut_copper_stairs", "minecraft:waxed_exposed_double_cut_copper_slab", "minecraft:waxed_oxidized_copper", "minecraft:waxed_oxidized_cut_copper", "minecraft:waxed_oxidized_cut_copper_slab", "minecraft:waxed_oxidized_cut_copper_stairs", "minecraft:waxed_oxidized_double_cut_copper_slab", "minecraft:waxed_weathered_copper", "minecraft:waxed_weathered_cut_copper", "minecraft:waxed_weathered_cut_copper_slab", "minecraft:waxed_weathered_cut_copper_stairs", "minecraft:waxed_weathered_double_cut_copper_slab", "minecraft:dripstone_block", "minecraft:pointed_dripstone", "minecraft:lightning_rod", "minecraft:basalt", "minecraft:tuff", "minecraft:double_stone_slab", "minecraft:double_stone_slab2", "minecraft:double_stone_slab3", "minecraft:double_stone_slab4", "minecraft:blackstone_double_slab", "minecraft:polished_blackstone_brick_double_slab", "minecraft:polished_blackstone_double_slab", "minecraft:mossy_cobblestone_stairs", "minecraft:stonecutter", "minecraft:stonecutter_block", "minecraft:red_nether_brick", "minecraft:red_nether_brick_stairs", "minecraft:normal_stone_stairs", "minecraft:smooth_basalt", "minecraft:stone", "minecraft:cobblestone", "minecraft:mossy_cobblestone", "minecraft:dripstone_block", "minecraft:brick_block", "minecraft:stone_stairs", "minecraft:stone_block_slab", "minecraft:stone_block_slab2", "minecraft:stone_block_slab3", "minecraft:stone_block_slab4", "minecraft:cobblestone_wall", "minecraft:gold_block", "minecraft:iron_block", "minecraft:cauldron", "minecraft:iron_bars", "minecraft:obsidian", "minecraft:coal_ore", "minecraft:deepslate_coal_ore", "minecraft:deepslate_diamond_ore", "minecraft:deepslate_emerald_ore", "minecraft:deepslate_gold_ore", "minecraft:deepslate_iron_ore", "minecraft:deepslate_redstone_ore", "minecraft:lit_deepslate_redstone_ore", "minecraft:diamond_ore", "minecraft:emerald_ore", "minecraft:gold_ore", "minecraft:iron_ore", "minecraft:lapis_ore", "minecraft:redstone_ore", "minecraft:lit_redstone_ore", "minecraft:raw_iron_block", "minecraft:raw_gold_block", "minecraft:raw_copper_block", "minecraft:mud_brick_double_slab", "minecraft:mud_brick_slab", "minecraft:mud_brick_stairs", "minecraft:mud_brick_wall", "minecraft:mud_bricks", "minecraft:hardened_clay", "minecraft:stained_hardened_clay", "minecraft:polished_diorite_stairs", "minecraft:andesite_stairs", "minecraft:polished_andesite_stairs", "minecraft:granite_stairs", "minecraft:polished_granite_stairs", "minecraft:polished_blackstone", "minecraft:chiseled_polished_blackstone", "minecraft:polished_blackstone_brick_stairs", "minecraft:blackstone_stairs", "minecraft:polished_blackstone_brick_wall", "minecraft:gilded_blackstone", "minecraft:coal_block")) { + for (var name : List.of("minecraft:ice", "minecraft:blue_ice", "minecraft:undyed_shulker_box", "minecraft:blue_shulker_box", "minecraft:red_shulker_box", "minecraft:black_shulker_box", "minecraft:cyan_shulker_box", "minecraft:brown_shulker_box", "minecraft:lime_shulker_box", "minecraft:gray_shulker_box", "minecraft:green_shulker_box", "minecraft:light_blue_shulker_box", "minecraft:light_gray_shulker_box", "minecraft:magenta_shulker_box", "minecraft:orange_shulker_box", "minecraft:white_shulker_box", "minecraft:yellow_shulker_box", "minecraft:pink_shulker_box", "minecraft:purple_shulker_box", "minecraft:prismarine", "minecraft:prismarine_bricks_stairs", "minecraft:prismarine_stairs", "minecraft:stone_block_slab4", "minecraft:dark_prismarine_stairs", "minecraft:anvil", "minecraft:bone_block", "minecraft:iron_trapdoor", "minecraft:nether_brick_fence", "minecraft:crying_obsidian", "minecraft:magma", "minecraft:smoker", "minecraft:lit_smoker", "minecraft:hopper", "minecraft:redstone_block", "minecraft:mob_spawner", "minecraft:netherite_block", "minecraft:smooth_stone", "minecraft:diamond_block", "minecraft:lapis_block", "minecraft:emerald_block", "minecraft:enchanting_table", "minecraft:end_bricks", "minecraft:cracked_polished_blackstone_bricks", "minecraft:nether_brick", "minecraft:cracked_nether_bricks", "minecraft:purpur_block", "minecraft:purpur_stairs", "minecraft:end_brick_stairs", "minecraft:stone_block_slab", "minecraft:stone_block_slab2", "minecraft:stone_block_slab3", "minecraft:stone_brick_stairs", "minecraft:mossy_stone_brick_stairs", "minecraft:polished_blackstone_bricks", "minecraft:polished_blackstone_stairs", "minecraft:blackstone_wall", "minecraft:blackstone_wall", "minecraft:polished_blackstone_wall", "minecraft:sandstone", "minecraft:grindstone", "minecraft:smooth_stone", "minecraft:brewing_stand", "minecraft:chain", "minecraft:lantern", "minecraft:soul_lantern", "minecraft:ancient_debris", "minecraft:quartz_ore", "minecraft:netherrack", "minecraft:basalt", "minecraft:polished_basalt", "minecraft:stonebrick", "minecraft:warped_nylium", "minecraft:crimson_nylium", "minecraft:end_stone", "minecraft:ender_chest", "minecraft:quartz_block", "minecraft:quartz_stairs", "minecraft:quartz_bricks", "minecraft:quartz_stairs", "minecraft:nether_gold_ore", "minecraft:furnace", "minecraft:blast_furnace", "minecraft:lit_furnace", "minecraft:blast_furnace", "minecraft:blackstone", "minecraft:black_concrete", "minecraft:blue_concrete", "minecraft:brown_concrete", "minecraft:cyan_concrete", "minecraft:gray_concrete", "minecraft:green_concrete", "minecraft:light_blue_concrete", "minecraft:lime_concrete", "minecraft:magenta_concrete", "minecraft:orange_concrete", "minecraft:pink_concrete", "minecraft:purple_concrete", "minecraft:red_concrete", "minecraft:light_gray_concrete", "minecraft:white_concrete", "minecraft:yellow_concrete", "minecraft:deepslate_copper_ore", "minecraft:deepslate_lapis_ore", "minecraft:chiseled_deepslate", "minecraft:cobbled_deepslate", "minecraft:cobbled_deepslate_double_slab", "minecraft:cobbled_deepslate_slab", "minecraft:cobbled_deepslate_stairs", "minecraft:cobbled_deepslate_wall", "minecraft:cracked_deepslate_bricks", "minecraft:cracked_deepslate_tiles", "minecraft:deepslate", "minecraft:deepslate_brick_double_slab", "minecraft:deepslate_brick_slab", "minecraft:deepslate_brick_stairs", "minecraft:deepslate_brick_wall", "minecraft:deepslate_bricks", "minecraft:deepslate_tile_double_slab", "minecraft:deepslate_tile_slab", "minecraft:deepslate_tile_stairs", "minecraft:deepslate_tile_wall", "minecraft:deepslate_tiles", "minecraft:infested_deepslate", "minecraft:polished_deepslate", "minecraft:polished_deepslate_double_slab", "minecraft:polished_deepslate_slab", "minecraft:polished_deepslate_stairs", "minecraft:polished_deepslate_wall", "minecraft:calcite", "minecraft:amethyst_block", "minecraft:amethyst_cluster", "minecraft:budding_amethyst", "minecraft:raw_copper_block", "minecraft:raw_gold_block", "minecraft:raw_iron_block", "minecraft:copper_ore", "minecraft:copper_block", "minecraft:cut_copper", "minecraft:cut_copper_slab", "minecraft:cut_copper_stairs", "minecraft:double_cut_copper_slab", "minecraft:exposed_copper", "minecraft:exposed_cut_copper", "minecraft:exposed_cut_copper_slab", "minecraft:exposed_cut_copper_stairs", "minecraft:exposed_double_cut_copper_slab", "minecraft:oxidized_copper", "minecraft:oxidized_cut_copper", "minecraft:oxidized_cut_copper_slab", "minecraft:oxidized_cut_copper_stairs", "minecraft:oxidized_double_cut_copper_slab", "minecraft:weathered_copper", "minecraft:weathered_cut_copper", "minecraft:weathered_cut_copper_slab", "minecraft:weathered_cut_copper_stairs", "minecraft:weathered_double_cut_copper_slab", "minecraft:waxed_copper", "minecraft:waxed_cut_copper", "minecraft:waxed_cut_copper_slab", "minecraft:waxed_cut_copper_stairs", "minecraft:waxed_double_cut_copper_slab", "minecraft:waxed_exposed_copper", "minecraft:waxed_exposed_cut_copper", "minecraft:waxed_exposed_cut_copper_slab", "minecraft:waxed_exposed_cut_copper_stairs", "minecraft:waxed_exposed_double_cut_copper_slab", "minecraft:waxed_oxidized_copper", "minecraft:waxed_oxidized_cut_copper", "minecraft:waxed_oxidized_cut_copper_slab", "minecraft:waxed_oxidized_cut_copper_stairs", "minecraft:waxed_oxidized_double_cut_copper_slab", "minecraft:waxed_weathered_copper", "minecraft:waxed_weathered_cut_copper", "minecraft:waxed_weathered_cut_copper_slab", "minecraft:waxed_weathered_cut_copper_stairs", "minecraft:waxed_weathered_double_cut_copper_slab", "minecraft:dripstone_block", "minecraft:pointed_dripstone", "minecraft:lightning_rod", "minecraft:basalt", "minecraft:tuff", "minecraft:double_stone_block_slab", "minecraft:double_stone_block_slab2", "minecraft:double_stone_block_slab3", "minecraft:double_stone_block_slab4", "minecraft:blackstone_double_slab", "minecraft:polished_blackstone_brick_double_slab", "minecraft:polished_blackstone_double_slab", "minecraft:mossy_cobblestone_stairs", "minecraft:stonecutter", "minecraft:stonecutter_block", "minecraft:red_nether_brick", "minecraft:red_nether_brick_stairs", "minecraft:normal_stone_stairs", "minecraft:smooth_basalt", "minecraft:stone", "minecraft:cobblestone", "minecraft:mossy_cobblestone", "minecraft:dripstone_block", "minecraft:brick_block", "minecraft:stone_stairs", "minecraft:stone_block_slab", "minecraft:stone_block_slab2", "minecraft:stone_block_slab3", "minecraft:stone_block_slab4", "minecraft:cobblestone_wall", "minecraft:gold_block", "minecraft:iron_block", "minecraft:cauldron", "minecraft:iron_bars", "minecraft:obsidian", "minecraft:coal_ore", "minecraft:deepslate_coal_ore", "minecraft:deepslate_diamond_ore", "minecraft:deepslate_emerald_ore", "minecraft:deepslate_gold_ore", "minecraft:deepslate_iron_ore", "minecraft:deepslate_redstone_ore", "minecraft:lit_deepslate_redstone_ore", "minecraft:diamond_ore", "minecraft:emerald_ore", "minecraft:gold_ore", "minecraft:iron_ore", "minecraft:lapis_ore", "minecraft:redstone_ore", "minecraft:lit_redstone_ore", "minecraft:raw_iron_block", "minecraft:raw_gold_block", "minecraft:raw_copper_block", "minecraft:mud_brick_double_slab", "minecraft:mud_brick_slab", "minecraft:mud_brick_stairs", "minecraft:mud_brick_wall", "minecraft:mud_bricks", "minecraft:hardened_clay", "minecraft:black_terracotta", "minecraft:blue_terracotta", "minecraft:brown_terracotta", "minecraft:cyan_terracotta", "minecraft:gray_terracotta", "minecraft:green_terracotta", "minecraft:light_blue_terracotta", "minecraft:lime_terracotta", "minecraft:magenta_terracotta", "minecraft:orange_terracotta", "minecraft:pink_terracotta", "minecraft:purple_terracotta", "minecraft:red_terracotta", "minecraft:light_gray_terracotta", "minecraft:white_terracotta", "minecraft:yellow_terracotta", "minecraft:polished_diorite_stairs", "minecraft:andesite_stairs", "minecraft:polished_andesite_stairs", "minecraft:granite_stairs", "minecraft:polished_granite_stairs", "minecraft:polished_blackstone", "minecraft:chiseled_polished_blackstone", "minecraft:polished_blackstone_brick_stairs", "minecraft:blackstone_stairs", "minecraft:polished_blackstone_brick_wall", "minecraft:gilded_blackstone", "minecraft:coal_block")) { pickaxeBlocks.put(name, new DigProperty()); } toolBlocks.put(ItemTag.IS_PICKAXE, pickaxeBlocks); - for (var name : List.of("minecraft:chest", "minecraft:bookshelf", "minecraft:melon_block", "minecraft:warped_stem", "minecraft:crimson_stem", "minecraft:warped_stem", "minecraft:crimson_stem", "minecraft:crafting_table", "minecraft:crimson_planks", "minecraft:warped_planks", "minecraft:warped_stairs", "minecraft:warped_trapdoor", "minecraft:crimson_stairs", "minecraft:crimson_trapdoor", "minecraft:crimson_door", "minecraft:crimson_double_slab", "minecraft:warped_door", "minecraft:warped_double_slab", "minecraft:crafting_table", "minecraft:composter", "minecraft:cartography_table", "minecraft:lectern", "minecraft:stripped_crimson_stem", "minecraft:stripped_warped_stem", "minecraft:trapdoor", "minecraft:spruce_trapdoor", "minecraft:birch_trapdoor", "minecraft:jungle_trapdoor", "minecraft:acacia_trapdoor", "minecraft:dark_oak_trapdoor", "minecraft:wooden_door", "minecraft:spruce_door", "minecraft:birch_door", "minecraft:jungle_door", "minecraft:acacia_door", "minecraft:dark_oak_door", "minecraft:fence", "minecraft:fence_gate", "minecraft:spruce_fence_gate", "minecraft:birch_fence_gate", "minecraft:jungle_fence_gate", "minecraft:acacia_fence_gate", "minecraft:dark_oak_fence_gate", "minecraft:log", "minecraft:log2", "minecraft:wood", "minecraft:planks", "minecraft:wooden_slab", "minecraft:double_wooden_slab", "minecraft:oak_stairs", "minecraft:spruce_stairs", "minecraft:birch_stairs", "minecraft:jungle_stairs", "minecraft:acacia_stairs", "minecraft:dark_oak_stairs", "minecraft:wall_sign", "minecraft:spruce_wall_sign", "minecraft:birch_wall_sign", "minecraft:jungle_wall_sign", "minecraft:acacia_wall_sign", "minecraft:darkoak_wall_sign", "minecraft:wooden_pressure_plate", "minecraft:spruce_pressure_plate", "minecraft:birch_pressure_plate", "minecraft:jungle_pressure_plate", "minecraft:acacia_pressure_plate", "minecraft:dark_oak_pressure_plate", "minecraft:smithing_table", "minecraft:fletching_table", "minecraft:barrel", "minecraft:beehive", "minecraft:bee_nest", "minecraft:ladder", "minecraft:pumpkin", "minecraft:carved_pumpkin", "minecraft:lit_pumpkin", "minecraft:mangrove_door", "minecraft:mangrove_double_slab", "minecraft:mangrove_fence", "minecraft:mangrove_fence_gate", "minecraft:mangrove_log", "minecraft:mangrove_planks", "minecraft:mangrove_pressure_plate", "minecraft:mangrove_slab", "minecraft:mangrove_stairs", "minecraft:mangrove_wall_sign", "minecraft:mangrove_wood", "minecraft:wooden_button", "minecraft:spruce_button", "minecraft:birch_button", "minecraft:jungle_button", "minecraft:acacia_button", "minecraft:dark_oak_button", "minecraft:mangrove_button", "minecraft:stripped_oak_wood", "minecraft:stripped_spruce_wood", "minecraft:stripped_birch_wood", "minecraft:stripped_jungle_wood", "minecraft:stripped_acacia_wood", "minecraft:stripped_dark_oak_wood", "minecraft:stripped_mangrove_wood", "minecraft:stripped_oak_log", "minecraft:stripped_spruce_log", "minecraft:stripped_birch_log", "minecraft:stripped_jungle_log", "minecraft:stripped_acacia_log", "minecraft:stripped_dark_oak_log", "minecraft:stripped_mangrove_log", "minecraft:standing_sign", "minecraft:spruce_standing_sign", "minecraft:birch_standing_sign", "minecraft:jungle_standing_sign", "minecraft:acacia_standing_sign", "minecraft:darkoak_standing_sign", "minecraft:mangrove_standing_sign", "minecraft:mangrove_trapdoor", "minecraft:warped_standing_sign", "minecraft:warped_wall_sign", "minecraft:crimson_standing_sign", "minecraft:crimson_wall_sign", "minecraft:mangrove_roots")) { + for (var name : List.of("minecraft:chest", "minecraft:bookshelf", "minecraft:melon_block", "minecraft:warped_stem", "minecraft:crimson_stem", "minecraft:warped_stem", "minecraft:crimson_stem", "minecraft:crafting_table", "minecraft:crimson_planks", "minecraft:warped_planks", "minecraft:warped_stairs", "minecraft:warped_trapdoor", "minecraft:crimson_stairs", "minecraft:crimson_trapdoor", "minecraft:crimson_door", "minecraft:crimson_double_slab", "minecraft:warped_door", "minecraft:warped_double_slab", "minecraft:crafting_table", "minecraft:composter", "minecraft:cartography_table", "minecraft:lectern", "minecraft:stripped_crimson_stem", "minecraft:stripped_warped_stem", "minecraft:trapdoor", "minecraft:spruce_trapdoor", "minecraft:birch_trapdoor", "minecraft:jungle_trapdoor", "minecraft:acacia_trapdoor", "minecraft:dark_oak_trapdoor", "minecraft:wooden_door", "minecraft:spruce_door", "minecraft:birch_door", "minecraft:jungle_door", "minecraft:acacia_door", "minecraft:dark_oak_door", "minecraft:acacia_fence", "minecraft:dark_oak_fence", "minecraft:bamboo_fence", "minecraft:mangrove_fence", "minecraft:nether_brick_fence", "minecraft:oak_fence", "minecraft:crimson_fence", "minecraft:jungle_fence", "minecraft:cherry_fence", "minecraft:birch_fence", "minecraft:warped_fence", "minecraft:spruce_fence", "minecraft:fence_gate", "minecraft:spruce_fence_gate", "minecraft:birch_fence_gate", "minecraft:jungle_fence_gate", "minecraft:acacia_fence_gate", "minecraft:dark_oak_fence_gate", "minecraft:mangrove_log", "minecraft:oak_log", "minecraft:jungle_log", "minecraft:spruce_log", "minecraft:dark_oak_log", "minecraft:cherry_log", "minecraft:acacia_log", "minecraft:birch_log", "minecraft:wood", "minecraft:acacia_planks", "minecraft:bamboo_planks", "minecraft:crimson_planks", "minecraft:birch_planks", "minecraft:dark_oak_planks", "minecraft:cherry_planks", "minecraft:warped_planks", "minecraft:oak_planks", "minecraft:spruce_planks", "minecraft:mangrove_planks", "minecraft:jungle_planks", "minecraft:wooden_slab", "minecraft:double_wooden_slab", "minecraft:oak_stairs", "minecraft:spruce_stairs", "minecraft:birch_stairs", "minecraft:jungle_stairs", "minecraft:acacia_stairs", "minecraft:dark_oak_stairs", "minecraft:wall_sign", "minecraft:spruce_wall_sign", "minecraft:birch_wall_sign", "minecraft:jungle_wall_sign", "minecraft:acacia_wall_sign", "minecraft:darkoak_wall_sign", "minecraft:wooden_pressure_plate", "minecraft:spruce_pressure_plate", "minecraft:birch_pressure_plate", "minecraft:jungle_pressure_plate", "minecraft:acacia_pressure_plate", "minecraft:dark_oak_pressure_plate", "minecraft:smithing_table", "minecraft:fletching_table", "minecraft:barrel", "minecraft:beehive", "minecraft:bee_nest", "minecraft:ladder", "minecraft:pumpkin", "minecraft:carved_pumpkin", "minecraft:lit_pumpkin", "minecraft:mangrove_door", "minecraft:mangrove_double_slab", "minecraft:mangrove_fence", "minecraft:mangrove_fence_gate", "minecraft:mangrove_log", "minecraft:mangrove_planks", "minecraft:mangrove_pressure_plate", "minecraft:mangrove_slab", "minecraft:mangrove_stairs", "minecraft:mangrove_wall_sign", "minecraft:mangrove_wood", "minecraft:wooden_button", "minecraft:spruce_button", "minecraft:birch_button", "minecraft:jungle_button", "minecraft:acacia_button", "minecraft:dark_oak_button", "minecraft:mangrove_button", "minecraft:stripped_oak_log", "minecraft:stripped_spruce_log", "minecraft:stripped_birch_log", "minecraft:stripped_jungle_log", "minecraft:stripped_acacia_log", "minecraft:stripped_dark_oak_log", "minecraft:stripped_mangrove_wood", "minecraft:stripped_oak_log", "minecraft:stripped_spruce_log", "minecraft:stripped_birch_log", "minecraft:stripped_jungle_log", "minecraft:stripped_acacia_log", "minecraft:stripped_dark_oak_log", "minecraft:stripped_mangrove_log", "minecraft:standing_sign", "minecraft:spruce_standing_sign", "minecraft:birch_standing_sign", "minecraft:jungle_standing_sign", "minecraft:acacia_standing_sign", "minecraft:darkoak_standing_sign", "minecraft:mangrove_standing_sign", "minecraft:mangrove_trapdoor", "minecraft:warped_standing_sign", "minecraft:warped_wall_sign", "minecraft:crimson_standing_sign", "minecraft:crimson_wall_sign", "minecraft:mangrove_roots")) { axeBlocks.put(name, new DigProperty()); } toolBlocks.put(ItemTag.IS_AXE, axeBlocks); @@ -518,21 +518,6 @@ public ToolBuilder addExtraBlocks(@NotNull String blockName, DigProperty propert return this; } - /** - * 物品的攻击力必须大于0才能生效

- * 标记这个物品是否为武器,如果是,会在物品描述中提示{@code "+X 攻击伤害"}的信息 - *

- * The item's attack damage must be greater than 0

- * define the item is a weapon or not, and if so, it will prompt {@code "+X attack damage"} in the item description - */ - @Since("1.19.80-r3") - public ToolBuilder isWeapon() { - if (this.item.getAttackDamage() > 0 && !this.nbt.getCompound("components").containsCompound("minecraft:weapon")) { - this.nbt.getCompound("components").putCompound(new CompoundTag("minecraft:weapon")); - } - return this; - } - /** * 给工具添加可挖掘的一类方块,用blockTag描述,挖掘它们的速度为{@link #speed(int)}的速度,如果没定义则为工具TIER对应的速度 *

@@ -578,32 +563,27 @@ public CustomItemDefinition build() { this.nbt.getCompound("components").getCompound("item_properties") .putString("enchantable_slot", "pickaxe"); this.tag("minecraft:is_pickaxe"); - this.isWeapon(); } else if (item.isAxe()) { this.blockTags.addAll(List.of("'wood'", "'pumpkin'", "'plant'")); type = ItemTag.IS_AXE; this.nbt.getCompound("components").getCompound("item_properties") .putString("enchantable_slot", "axe"); this.tag("minecraft:is_axe"); - this.isWeapon(); } else if (item.isShovel()) { this.blockTags.addAll(List.of("'sand'", "'dirt'", "'gravel'", "'grass'", "'snow'")); type = ItemTag.IS_SHOVEL; this.nbt.getCompound("components").getCompound("item_properties") .putString("enchantable_slot", "shovel"); this.tag("minecraft:is_shovel"); - this.isWeapon(); } else if (item.isHoe()) { this.nbt.getCompound("components").getCompound("item_properties") .putString("enchantable_slot", "hoe"); type = ItemTag.IS_HOE; this.tag("minecraft:is_hoe"); - this.isWeapon(); } else if (item.isSword()) { this.nbt.getCompound("components").getCompound("item_properties") .putString("enchantable_slot", "sword"); type = ItemTag.IS_SWORD; - this.isWeapon(); } else { if (this.nbt.getCompound("components").contains("item_tags")) { var list = this.nbt.getCompound("components").getList("item_tags", StringTag.class).getAll(); @@ -643,10 +623,15 @@ public CustomItemDefinition build() { this.nbt.getCompound("components") .putCompound("minecraft:digger", this.diggerRoot); } - - //添加可挖掘的方块 - for (var k : this.blocks) { - this.diggerRoot.getList("destroy_speeds", CompoundTag.class).add(k); + if (!this.blocks.isEmpty()) { + //添加可挖掘的方块 + for (var k : this.blocks) { + this.diggerRoot.getList("destroy_speeds", CompoundTag.class).add(k); + } + if (!this.nbt.getCompound("components").containsCompound("minecraft:digger")) { + this.nbt.getCompound("components") + .putCompound("minecraft:digger", this.diggerRoot); + } } return calculateID(); }