From 8e0adaa6e10043eb7a3ae5d6d1a6d7489d4795bb Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Mon, 24 Mar 2025 22:01:09 +0800 Subject: [PATCH] improve sounds --- .../main/resources/additional-real-blocks.yml | 4 +- bukkit/loader/src/main/resources/mappings.yml | 4 + .../default/configuration/blocks.yml | 86 +++++++++++++++++- .../default/configuration/categories.yml | 1 + .../resources/default/configuration/i18n.yml | 2 + .../default/configuration/plants.yml | 4 +- .../textures/block/custom/netherite_anvil.png | Bin 0 -> 1060 bytes .../block/custom/netherite_anvil_top.png | Bin 0 -> 1079 bytes .../bukkit/api/CraftEngineBlocks.java | 4 +- .../bukkit/block/BlockEventListener.java | 8 +- .../block/behavior/FallingBlockBehavior.java | 18 ++++ .../item/behavior/BlockItemBehavior.java | 8 +- .../craftengine/bukkit/util/Reflections.java | 43 +++++++++ .../craftengine/bukkit/util/SoundUtils.java | 10 +- .../fabric/CraftEngineFabricMod.java | 2 +- .../config/additional-real-blocks.yml | 4 +- .../config/mappings.yml | 4 + .../craftengine/core/block/BlockSounds.java | 44 +++++---- .../core/block/properties/Property.java | 8 ++ .../core/pack/AbstractPackManager.java | 2 + .../craftengine/core/sound/SoundData.java | 23 +++++ .../craftengine/core/world/World.java | 5 + 22 files changed, 246 insertions(+), 38 deletions(-) create mode 100644 bukkit/loader/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/netherite_anvil.png create mode 100644 bukkit/loader/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/netherite_anvil_top.png create mode 100644 core/src/main/java/net/momirealms/craftengine/core/sound/SoundData.java diff --git a/bukkit/loader/src/main/resources/additional-real-blocks.yml b/bukkit/loader/src/main/resources/additional-real-blocks.yml index ec4cfa011..91993a87d 100644 --- a/bukkit/loader/src/main/resources/additional-real-blocks.yml +++ b/bukkit/loader/src/main/resources/additional-real-blocks.yml @@ -23,4 +23,6 @@ minecraft:spruce_sapling: 1 minecraft:jungle_sapling: 1 minecraft:dark_oak_sapling: 1 minecraft:acacia_sapling: 1 -minecraft:cherry_sapling: 1 \ No newline at end of file +minecraft:cherry_sapling: 1 + +minecraft:anvil: 2 \ No newline at end of file diff --git a/bukkit/loader/src/main/resources/mappings.yml b/bukkit/loader/src/main/resources/mappings.yml index fc43ff532..b21e18b19 100644 --- a/bukkit/loader/src/main/resources/mappings.yml +++ b/bukkit/loader/src/main/resources/mappings.yml @@ -1,4 +1,8 @@ ######################################################################################################################################################################################################################## +# Anvil Block +minecraft:anvil[facing=north]: minecraft:anvil[facing=south] +minecraft:anvil[facing=east]: minecraft:anvil[facing=west] +######################################################################################################################################################################################################################## # Sapling Block minecraft:oak_sapling[stage=1]: minecraft:oak_sapling[stage=0] minecraft:birch_sapling[stage=1]: minecraft:birch_sapling[stage=0] diff --git a/bukkit/loader/src/main/resources/resources/default/configuration/blocks.yml b/bukkit/loader/src/main/resources/resources/default/configuration/blocks.yml index 5475b6e3f..f1568cfb1 100644 --- a/bukkit/loader/src/main/resources/resources/default/configuration/blocks.yml +++ b/bukkit/loader/src/main/resources/resources/default/configuration/blocks.yml @@ -40,7 +40,77 @@ items: textures: "end": "minecraft:block/custom/chinese_lantern_top" "side": "minecraft:block/custom/chinese_lantern" - + default:netherite_anvil: + material: paper + custom-model-data: 3001 + data: + item-name: "" + model: + type: "minecraft:model" + path: "minecraft:item/custom/netherite_anvil" + generation: + parent: "minecraft:block/custom/netherite_anvil" + behavior: + type: block_item + block: + loot: + template: "default:loot_table/basic" + arguments: + item: default:netherite_anvil + behavior: + type: falling_block + hurt-amount: 4 + max-hurt: 80 + settings: + template: + - default:pickaxe_power/level_4 + overrides: + sounds: + break: minecraft:block.anvil.break + step: minecraft:block.anvil.step + place: minecraft:block.anvil.place + hit: minecraft:block.anvil.hit + fall: minecraft:block.anvil.fall + land: minecraft:block.anvil.land + item: default:netherite_anvil + map-color: 29 + hardness: 10.0 + resistance: 1200 + push-reaction: BLOCK + states: + properties: + facing_clockwise: + type: 4-direction + default: north + appearances: + axisX: + state: "minecraft:anvil[facing=east]" + model: + path: "minecraft:block/custom/netherite_anvil" + y: 90 + generation: + parent: "minecraft:block/anvil" + textures: + "top": "minecraft:block/custom/netherite_anvil_top" + "body": "minecraft:block/custom/netherite_anvil" + "particle": "minecraft:block/custom/netherite_anvil" + axisZ: + state: "minecraft:anvil[facing=north]" + model: + path: "minecraft:block/custom/netherite_anvil" + variants: + facing_clockwise=east: + appearance: axisX + id: 0 + facing_clockwise=west: + appearance: axisX + id: 1 + facing_clockwise=north: + appearance: axisZ + id: 2 + facing_clockwise=south: + appearance: axisZ + id: 3 recipes: default:chinese_lantern: type: shaped @@ -63,4 +133,16 @@ recipes: A: "default:reed" result: id: minecraft:paper - count: 3 \ No newline at end of file + count: 3 + default:netherite_anvil: + type: shaped + pattern: + - " B " + - "BAB" + - " B " + ingredients: + A: "minecraft:anvil" + B: "minecraft:netherite_ingot" + result: + id: default:netherite_anvil + count: 1 \ No newline at end of file diff --git a/bukkit/loader/src/main/resources/resources/default/configuration/categories.yml b/bukkit/loader/src/main/resources/resources/default/configuration/categories.yml index 4834bf38d..da8c4c458 100644 --- a/bukkit/loader/src/main/resources/resources/default/configuration/categories.yml +++ b/bukkit/loader/src/main/resources/resources/default/configuration/categories.yml @@ -56,5 +56,6 @@ categories: icon: default:chinese_lantern list: - default:chinese_lantern + - default:netherite_anvil - default:fairy_flower - default:reed \ No newline at end of file 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 456f15b57..a4f86bb33 100644 --- a/bukkit/loader/src/main/resources/resources/default/configuration/i18n.yml +++ b/bukkit/loader/src/main/resources/resources/default/configuration/i18n.yml @@ -28,6 +28,7 @@ i18n: item.palm_planks: "Palm Planks" item.palm_sapling: "Palm Sapling" item.palm_leaves: "Palm Leaves" + item.netherite_anvil: "Netherite Anvil" category.default.name: "Default Assets" category.default.lore: "Contains the default configuration of CraftEngine" category.palm_tree: "Palm Tree" @@ -63,6 +64,7 @@ i18n: item.palm_planks: "棕榈木板" item.palm_sapling: "棕榈树苗" item.palm_leaves: "棕榈树叶" + item.netherite_anvil: "下界合金砧" category.default.name: "默认资产" category.default.lore: "包含了CraftEngine的默认配置" category.palm_tree: "棕榈树" 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 328001802..41ccd6499 100644 --- a/bukkit/loader/src/main/resources/resources/default/configuration/plants.yml +++ b/bukkit/loader/src/main/resources/resources/default/configuration/plants.yml @@ -1,7 +1,7 @@ items: default:fairy_flower: material: paper - custom-model-data: 3001 + custom-model-data: 4000 data: item-name: "" model: @@ -13,7 +13,7 @@ items: block: default:fairy_flower default:reed: material: paper - custom-model-data: 3002 + custom-model-data: 4001 data: item-name: "" model: diff --git a/bukkit/loader/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/netherite_anvil.png b/bukkit/loader/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/netherite_anvil.png new file mode 100644 index 0000000000000000000000000000000000000000..a977ea20ff06b0fbb500ae3ee14419fdb1f99517 GIT binary patch literal 1060 zcmaJ=&rj1}7;caQAwg84Q8ZeML71+;#s+ORaIBj&&}EJpmK_YG{n#qBUui#F!3!}l z5o0{*K@#sq6a51)Atqe7$;HH<7fFmE0mFfic=79C!-KQQ*Y8K3=Xsy^{oZdelfK^4 z+}=zOM2kEmW$}E>A5BN_zbn`}il;LunMb2=5|vd45OEz&08%#9BFF+&pPN|&QGz&f z*~sNlUKtTJXws^Wp*_>aY=Vdmc($rd0YpxKqG83T?d27UH1rrX7FJlrPJogzH1B}X z`E*X3pV9=K8t5mZo`?lZfK<{mr!80XVpK&}#B2YUp~wmZO~t5vQ+XvrCZGdIf#!l5 z%kpHeK&ufo5)vYP>Q$0w`5uN1F>EBrablPk*)VzVQ8=KZPl{P7br25kVpItsTV$AW zxlETsG<1p#CkO(=@(j-hF(T;BSxEJQmfKNPkbtW>hK&qpk-nlj0cTN+!e;lgFzuSG zb9bvxat2799Hhr?8uwvjLL@E}V5Ve0P%_ekfZ^I6y_v z$w4?>Eo7zy5p+w?CiyVUab(w+Vd=2!c2^jRBFdJFR7(T06r->PZ5X=9N~sW=jPPt< zT;RAAJIF>NaY5n}A)&W7oJ>}^64Yi*V4*5kKjen$a{YcVZ5&wwj&TR*DF>QlC27&9 z?}e?acfi%_d*SMG8El5}ulBF2t{&n3@t3vU#hY690}HpjgL`}X<)!=hU7XB}kbsg3W}_Z#1m1Te{_Cl69XJsis!sfJ&$jkA}%&Hw7mO$VJ`W#Kj3}O<>Zac zr}E9@;;YHjCCpx&K6Va3rE-b1Mg1+#P#&*#?H653p0D^Wn-fK`O=SHPqs96 zXZZHR#aFvmu7y7Deta|D`DLrrc6a7h!^(%_dyS_FsH2NMN?UcAV`_!nrzc<_Q#*j+uiPSVc2m+$-Dd-LAhnM_@5 ztZ%O;2%=FLm(zGZ8GOg;@V_h6G=;Y|l*pnfm_sGa1w`C{bAVJVEf3N_GnN+KfgysZ z>ohZ2lvO809a^*&U})cRFqxAaB|+>g$UQiZqQFH62k|)saBK9A9?9 z)N(4LFBf&ephkwtAz#D-7C;*5Tl2Oj`Z4N2SH$PQ%~0e41Qlb{VNzLjl9ZqeNP*@; zI?M88zd&nIEgBZ016nW1vwR=Jh8Z>*;y5wFi)@4}FA4{AjhvX4ljU&OictlG9Fbv4 zr4n5V)6mT`oFE7c%QHM5!ibQ!WFyTF*(3MYG5h2>Ob zZLfS&_|6z#a~O_hgQ_Y(RsBEIvZ`ngrNN(k|0(QcmK?yOfd>~|9rrHR5rlF?$pspM zZU(~n%0*5VAc9^2IwT*VIgad_Hf;lzyzT>rs)~y3AjheaiC2DdRoD37R_ODh~TzGzhV|8}1QJsEZi+)z>Sq62jI2lL)D$)k7qPzG`yP99iX6}Q zpRVj&ZeAf9>ONdmT7GVP*&XQd_g**L8on)bc0XxaXS7#NJA8c4d3a`LVRZK8snzTB z$KAPCC*1GHKey4Nc5&q?sB8XpZY}!&Z5_G0y_OCA7`eZ9X)E=7^IOX-@uv0Y>0Im0 PJdQ{xiIn_oZ1%=)S>0M* literal 0 HcmV?d00001 diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineBlocks.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineBlocks.java index b92732599..a48dbd85c 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineBlocks.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineBlocks.java @@ -115,7 +115,7 @@ public final class CraftEngineBlocks { if (success) { Reflections.method$BlockStateBase$onPlace.invoke(blockState, worldServer, blockPos, oldBlockState, true); if (playSound) { - location.getWorld().playSound(location, block.sounds().placeSound().toString(), SoundCategory.BLOCKS, 1, 0.8f); + location.getWorld().playSound(location, block.sounds().placeSound().toString(), SoundCategory.BLOCKS, block.sounds().placeSound().volume(), block.sounds().placeSound().pitch()); } } } catch (ReflectiveOperationException e) { @@ -185,7 +185,7 @@ public final class CraftEngineBlocks { } } if (playSound) { - world.playBlockSound(vec3d, state.sounds().breakSound(), 1, 0.8f); + world.playBlockSound(vec3d, state.sounds().breakSound()); } if (sendParticles) { // TODO Particles 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 b9c370a51..ec1436b9d 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 @@ -121,7 +121,7 @@ public class BlockEventListener implements Listener { } // play sound Vec3d vec3d = new Vec3d(location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5); - world.playBlockSound(vec3d, state.sounds().breakSound(), 1f, 0.8f); + world.playBlockSound(vec3d, state.sounds().breakSound()); if (player.getGameMode() == GameMode.CREATIVE) { return; } @@ -226,7 +226,7 @@ public class BlockEventListener implements Listener { int stateId = BlockStateUtils.blockStateToId(blockState); if (!BlockStateUtils.isVanillaBlock(stateId)) { ImmutableBlockState state = manager.getImmutableBlockStateUnsafe(stateId); - player.playSound(playerLocation, state.sounds().stepSound().toString(), SoundCategory.BLOCKS, 0.15f, 1f); + player.playSound(playerLocation, state.sounds().stepSound().id().toString(), SoundCategory.BLOCKS, state.sounds().stepSound().volume(), state.sounds().stepSound().pitch()); } else if (ConfigManager.enableSoundSystem()) { Object ownerBlock = BlockStateUtils.getBlockOwner(blockState); if (manager.isBlockSoundRemoved(ownerBlock)) { @@ -268,7 +268,7 @@ public class BlockEventListener implements Listener { for (Item item : blockState.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } - world.playBlockSound(vec3d, blockState.sounds().breakSound(),1f, 0.8f); + world.playBlockSound(vec3d, blockState.sounds().breakSound()); } } } @@ -300,7 +300,7 @@ public class BlockEventListener implements Listener { for (Item item : state.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } - world.playBlockSound(vec3d, state.sounds().breakSound(), 1f, 0.8f); + world.playBlockSound(vec3d, state.sounds().breakSound()); } } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/FallingBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/FallingBlockBehavior.java index fa0e9a2e6..bd316aa36 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/FallingBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/FallingBlockBehavior.java @@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.block.behavior; import net.momirealms.craftengine.bukkit.block.BukkitBlockManager; import net.momirealms.craftengine.bukkit.util.BlockStateUtils; +import net.momirealms.craftengine.bukkit.util.LocationUtils; import net.momirealms.craftengine.bukkit.util.Reflections; import net.momirealms.craftengine.bukkit.world.BukkitWorld; import net.momirealms.craftengine.core.block.CustomBlock; @@ -102,6 +103,23 @@ public class FallingBlockBehavior extends BlockBehavior { } } + @Override + public void onLand(Object thisBlock, Object[] args) throws Exception { + Object fallingBlock = args[4]; + Object entityData = Reflections.field$Entity$entityData.get(fallingBlock); + boolean isSilent = (boolean) Reflections.method$SynchedEntityData$get.invoke(entityData, Reflections.instance$Entity$DATA_SILENT); + if (!isSilent) { + Object blockState = args[2]; + int stateId = BlockStateUtils.blockStateToId(blockState); + ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(stateId); + if (immutableBlockState == null || immutableBlockState.isEmpty()) return; + Object level = args[0]; + Object pos = args[1]; + net.momirealms.craftengine.core.world.World world = new BukkitWorld((World) Reflections.method$Level$getCraftWorld.invoke(level)); + world.playBlockSound(Vec3d.atCenterOf(LocationUtils.fromBlockPos(pos)), immutableBlockState.sounds().landSound()); + } + } + public static class Factory implements BlockBehaviorFactory { @Override public BlockBehavior create(CustomBlock block, Map arguments) { diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/BlockItemBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/BlockItemBehavior.java index 1add69fe2..e83945789 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/BlockItemBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/BlockItemBehavior.java @@ -24,7 +24,11 @@ import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.world.BlockPos; -import org.bukkit.*; +import net.momirealms.craftengine.core.world.Vec3d; +import org.bukkit.Bukkit; +import org.bukkit.GameEvent; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; @@ -120,7 +124,7 @@ public class BlockItemBehavior extends ItemBehavior { } player.swingHand(placeContext.getHand()); - world.playSound(new Location(world, pos.x(), pos.y(), pos.z()), blockStateToPlace.sounds().placeSound().toString(), SoundCategory.BLOCKS, 1f, 0.8f); + placeContext.getLevel().playBlockSound(new Vec3d(pos.x() + 0.5, pos.y() + 0.5, pos.z() + 0.5), blockStateToPlace.sounds().placeSound()); world.sendGameEvent(bukkitPlayer, GameEvent.BLOCK_PLACE, new Vector(pos.x(), pos.y(), pos.z())); return InteractionResult.SUCCESS; } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java index 95eb2c69c..ac175461c 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java @@ -707,6 +707,19 @@ public class Reflections { ) ); + public static final Class clazz$SynchedEntityData = requireNonNull( + ReflectionUtils.getClazz( + BukkitReflectionUtils.assembleMCClass("network.syncher.SynchedEntityData"), + BukkitReflectionUtils.assembleMCClass("network.syncher.DataWatcher") + ) + ); + + public static final Method method$SynchedEntityData$get = requireNonNull( + ReflectionUtils.getMethod( + clazz$SynchedEntityData, Object.class, clazz$EntityDataAccessor + ) + ); + public static final Class clazz$SynchedEntityData$DataValue = requireNonNull( ReflectionUtils.getClazz( BukkitReflectionUtils.assembleMCClass("network.syncher.SynchedEntityData$DataValue"), @@ -5428,4 +5441,34 @@ public class Reflections { clazz$LinearPalette, Object.class.arrayType(), 0 ) ); + + public static final Object instance$Entity$DATA_SILENT; + + static { + int i = 0; + Field targetField = null; + for (Field field : clazz$Entity.getDeclaredFields()) { + Type fieldType = field.getGenericType(); + if (field.getType() == clazz$EntityDataAccessor && fieldType instanceof ParameterizedType paramType) { + if (paramType.getActualTypeArguments()[0] == Boolean.class) { + i++; + if (i == 2) { + targetField = field; + break; + } + } + } + } + try { + instance$Entity$DATA_SILENT = ReflectionUtils.setAccessible(requireNonNull(targetField)).get(null); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + public static final Field field$Entity$entityData = requireNonNull( + ReflectionUtils.getDeclaredField( + clazz$Entity, clazz$SynchedEntityData, 0 + ) + ); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/SoundUtils.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/SoundUtils.java index b5fca65a4..25d00d02e 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/SoundUtils.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/SoundUtils.java @@ -10,11 +10,11 @@ public class SoundUtils { public static Object toSoundType(BlockSounds sounds) throws ReflectiveOperationException { return Reflections.constructor$SoundType.newInstance( 1f, 1f, - getOrRegisterSoundEvent(sounds.breakSound()), - getOrRegisterSoundEvent(sounds.stepSound()), - getOrRegisterSoundEvent(sounds.placeSound()), - getOrRegisterSoundEvent(sounds.hitSound()), - getOrRegisterSoundEvent(sounds.fallSound()) + getOrRegisterSoundEvent(sounds.breakSound().id()), + getOrRegisterSoundEvent(sounds.stepSound().id()), + getOrRegisterSoundEvent(sounds.placeSound().id()), + getOrRegisterSoundEvent(sounds.hitSound().id()), + getOrRegisterSoundEvent(sounds.fallSound().id()) ); } diff --git a/client-mod/src/main/java/net/momirealms/craftengine/fabric/CraftEngineFabricMod.java b/client-mod/src/main/java/net/momirealms/craftengine/fabric/CraftEngineFabricMod.java index 9050e2434..d73898587 100644 --- a/client-mod/src/main/java/net/momirealms/craftengine/fabric/CraftEngineFabricMod.java +++ b/client-mod/src/main/java/net/momirealms/craftengine/fabric/CraftEngineFabricMod.java @@ -4,11 +4,11 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.BlockState; import net.minecraft.util.Identifier; +import net.momirealms.craftengine.fabric.client.config.ModConfig; import net.momirealms.craftengine.fabric.util.BlockUtils; import net.momirealms.craftengine.fabric.util.LoggerFilter; import net.momirealms.craftengine.fabric.util.RegisterBlocks; import net.momirealms.craftengine.fabric.util.YamlUtils; -import net.momirealms.craftengine.fabric.client.config.ModConfig; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; diff --git a/client-mod/src/main/resources/assets/craft-engine-fabric-mod/config/additional-real-blocks.yml b/client-mod/src/main/resources/assets/craft-engine-fabric-mod/config/additional-real-blocks.yml index ec4cfa011..91993a87d 100644 --- a/client-mod/src/main/resources/assets/craft-engine-fabric-mod/config/additional-real-blocks.yml +++ b/client-mod/src/main/resources/assets/craft-engine-fabric-mod/config/additional-real-blocks.yml @@ -23,4 +23,6 @@ minecraft:spruce_sapling: 1 minecraft:jungle_sapling: 1 minecraft:dark_oak_sapling: 1 minecraft:acacia_sapling: 1 -minecraft:cherry_sapling: 1 \ No newline at end of file +minecraft:cherry_sapling: 1 + +minecraft:anvil: 2 \ No newline at end of file diff --git a/client-mod/src/main/resources/assets/craft-engine-fabric-mod/config/mappings.yml b/client-mod/src/main/resources/assets/craft-engine-fabric-mod/config/mappings.yml index fc43ff532..b21e18b19 100644 --- a/client-mod/src/main/resources/assets/craft-engine-fabric-mod/config/mappings.yml +++ b/client-mod/src/main/resources/assets/craft-engine-fabric-mod/config/mappings.yml @@ -1,4 +1,8 @@ ######################################################################################################################################################################################################################## +# Anvil Block +minecraft:anvil[facing=north]: minecraft:anvil[facing=south] +minecraft:anvil[facing=east]: minecraft:anvil[facing=west] +######################################################################################################################################################################################################################## # Sapling Block minecraft:oak_sapling[stage=1]: minecraft:oak_sapling[stage=0] minecraft:birch_sapling[stage=1]: minecraft:birch_sapling[stage=0] diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/BlockSounds.java b/core/src/main/java/net/momirealms/craftengine/core/block/BlockSounds.java index bc6e95247..1dc49796f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/BlockSounds.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/BlockSounds.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.block; +import net.momirealms.craftengine.core.sound.SoundData; import net.momirealms.craftengine.core.util.Key; import java.util.Map; @@ -12,51 +13,58 @@ public class BlockSounds { Hit 0.5 0.5 Break 1 0.8 */ - public static final Key EMPTY_SOUND = Key.of("minecraft:intentionally_empty"); - public static final BlockSounds EMPTY = new BlockSounds(EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND); + public static final SoundData EMPTY_SOUND = new SoundData(Key.of("minecraft:intentionally_empty"), 1, 1); + public static final BlockSounds EMPTY = new BlockSounds(EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND); - private final Key breakSound; - private final Key stepSound; - private final Key placeSound; - private final Key hitSound; - private final Key fallSound; + private final SoundData breakSound; + private final SoundData stepSound; + private final SoundData placeSound; + private final SoundData hitSound; + private final SoundData fallSound; + private final SoundData landSound; - public BlockSounds(Key breakSound, Key stepSound, Key placeSound, Key hitSound, Key fallSound) { + public BlockSounds(SoundData breakSound, SoundData stepSound, SoundData placeSound, SoundData hitSound, SoundData fallSound, SoundData landSound) { this.breakSound = breakSound; this.stepSound = stepSound; this.placeSound = placeSound; this.hitSound = hitSound; this.fallSound = fallSound; + this.landSound = landSound; } public static BlockSounds fromMap(Map map) { if (map == null) return EMPTY; return new BlockSounds( - Key.of(map.getOrDefault("break", "minecraft:intentionally_empty").toString()), - Key.of(map.getOrDefault("step", "minecraft:intentionally_empty").toString()), - Key.of(map.getOrDefault("place", "minecraft:intentionally_empty").toString()), - Key.of(map.getOrDefault("hit", "minecraft:intentionally_empty").toString()), - Key.of(map.getOrDefault("fall", "minecraft:intentionally_empty").toString()) + SoundData.create(map.getOrDefault("break", "minecraft:intentionally_empty"), 1f, 0.8f), + SoundData.create(map.getOrDefault("step", "minecraft:intentionally_empty"), 0.15f, 1f), + SoundData.create(map.getOrDefault("place", "minecraft:intentionally_empty"), 0f, 0.8f), // todo 0? + SoundData.create(map.getOrDefault("hit", "minecraft:intentionally_empty"), 0.5f, 0.5f), + SoundData.create(map.getOrDefault("fall", "minecraft:intentionally_empty"), 0.5f, 0.75f), + SoundData.create(map.getOrDefault("land", "minecraft:intentionally_empty"), 0.3f, 1f) ); } - public Key breakSound() { + public SoundData breakSound() { return breakSound; } - public Key stepSound() { + public SoundData stepSound() { return stepSound; } - public Key placeSound() { + public SoundData placeSound() { return placeSound; } - public Key hitSound() { + public SoundData hitSound() { return hitSound; } - public Key fallSound() { + public SoundData landSound() { + return landSound; + } + + public SoundData fallSound() { return fallSound; } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/properties/Property.java b/core/src/main/java/net/momirealms/craftengine/core/block/properties/Property.java index 78391ee8c..83b45f7fb 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/properties/Property.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/properties/Property.java @@ -35,6 +35,14 @@ public abstract class Property> { throw new IllegalArgumentException("Unsupported property type used in hard-coded `facing` property: " + property.valueClass()); } })); + HARD_CODED_PLACEMENTS.put("facing_clockwise", (property -> { + if (property.valueClass() == HorizontalDirection.class) { + Property directionProperty = (Property) property; + return (context, state) -> state.with(directionProperty, context.getHorizontalDirection().clockWise().toHorizontalDirection()); + } else { + throw new IllegalArgumentException("Unsupported property type used in hard-coded `facing_clockwise` property: " + property.valueClass()); + } + })); HARD_CODED_PLACEMENTS.put("waterlogged", (property -> { Property waterloggedProperty = (Property) property; return (context, state) -> state.with(waterloggedProperty, context.isWaterSource()); diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java index 081653629..b40ec0909 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java @@ -282,6 +282,8 @@ public abstract class AbstractPackManager implements PackManager { plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/chinese_lantern.png.mcmeta"); plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/chinese_lantern_top.png"); plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/chinese_lantern_top.png.mcmeta"); + plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/netherite_anvil.png"); + plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/netherite_anvil_top.png"); // items plugin.saveResource("resources/default/configuration/items.yml"); plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/item/custom/topaz_rod.png"); diff --git a/core/src/main/java/net/momirealms/craftengine/core/sound/SoundData.java b/core/src/main/java/net/momirealms/craftengine/core/sound/SoundData.java new file mode 100644 index 000000000..5cdd8d198 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/sound/SoundData.java @@ -0,0 +1,23 @@ +package net.momirealms.craftengine.core.sound; + +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.MiscUtils; + +import java.util.Map; + +public record SoundData(Key id, float volume, float pitch) { + + public static SoundData create(Object obj, float volume, float pitch) { + if (obj instanceof String key) { + return new SoundData(Key.of(key), volume, pitch); + } else if (obj instanceof Map map) { + Map data = MiscUtils.castToMap(map, false); + Key id = Key.of((String) data.get("id")); + float volumeFloat = MiscUtils.getAsFloat(data.getOrDefault("volume", volume)); + float pitchFloat = MiscUtils.getAsFloat(data.getOrDefault("pitch", pitch)); + return new SoundData(id, volumeFloat, pitchFloat); + } else { + throw new IllegalArgumentException("Illegal object type for sound data: " + obj.getClass()); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/world/World.java b/core/src/main/java/net/momirealms/craftengine/core/world/World.java index 3b1cc134e..36979368c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/world/World.java +++ b/core/src/main/java/net/momirealms/craftengine/core/world/World.java @@ -1,6 +1,7 @@ package net.momirealms.craftengine.core.world; import net.momirealms.craftengine.core.item.Item; +import net.momirealms.craftengine.core.sound.SoundData; import net.momirealms.craftengine.core.util.Key; import java.nio.file.Path; @@ -31,4 +32,8 @@ public interface World { void dropExp(Vec3d location, int amount); void playBlockSound(Vec3d location, Key sound, float volume, float pitch); + + default void playBlockSound(Vec3d location, SoundData data) { + playBlockSound(location, data.id(), data.volume(), data.pitch()); + } }