9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-29 03:49:15 +00:00

add destroy sound

This commit is contained in:
XiaoMoMi
2025-03-25 00:55:35 +08:00
parent 2aad938393
commit 5b90106f97
9 changed files with 39 additions and 17 deletions

View File

@@ -254,7 +254,7 @@ public class CraftEngineFurniture {
}
}
if (playSound) {
world.playBlockSound(vec3d, loadedFurniture.furniture().settings().sounds().breakSound(), 1f, 0.8f);
world.playBlockSound(vec3d, loadedFurniture.furniture().settings().sounds().breakSound());
}
}
}

View File

@@ -43,6 +43,11 @@ public class FallingBlockRemoveListener implements Listener {
for (Item<Object> item : immutableBlockState.getDrops(builder, world)) {
world.dropItemNaturally(vec3d, item);
}
Object entityData = Reflections.field$Entity$entityData.get(fallingBlockEntity);
boolean isSilent = (boolean) Reflections.method$SynchedEntityData$get.invoke(entityData, Reflections.instance$Entity$DATA_SILENT);
if (!isSilent) {
world.playBlockSound(vec3d, immutableBlockState.sounds().destroySound());
}
} catch (ReflectiveOperationException e) {
CraftEngine.instance().logger().warn("Failed to handle EntityRemoveEvent", e);
}

View File

@@ -101,6 +101,11 @@ public class FallingBlockBehavior extends BlockBehavior {
for (Item<Object> item : immutableBlockState.getDrops(builder, world)) {
world.dropItemNaturally(vec3d, item);
}
Object entityData = Reflections.field$Entity$entityData.get(fallingBlockEntity);
boolean isSilent = (boolean) Reflections.method$SynchedEntityData$get.invoke(entityData, Reflections.instance$Entity$DATA_SILENT);
if (!isSilent) {
world.playBlockSound(vec3d, immutableBlockState.sounds().destroySound());
}
}
@Override

View File

@@ -7,6 +7,7 @@ import net.momirealms.craftengine.core.loot.LootTable;
import net.momirealms.craftengine.core.pack.Pack;
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
import net.momirealms.craftengine.core.plugin.scheduler.SchedulerTask;
import net.momirealms.craftengine.core.sound.SoundData;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
@@ -60,7 +61,8 @@ public class BukkitFurnitureManager implements FurnitureManager {
handleEntityLoadEarly(display);
});
if (playSound) {
location.getWorld().playSound(location, furniture.settings().sounds().placeSound().toString(), SoundCategory.BLOCKS,1f, 1f);
SoundData data = furniture.settings().sounds().placeSound();
location.getWorld().playSound(location, data.id().toString(), SoundCategory.BLOCKS, data.volume(), data.pitch());
}
return getLoadedFurnitureByBaseEntityId(furnitureEntity.getEntityId());
}

View File

@@ -126,7 +126,7 @@ public class FurnitureItemBehavior extends ItemBehavior {
item.load();
}
furnitureLocation.getWorld().playSound(furnitureLocation, customFurniture.settings().sounds().placeSound().toString(), SoundCategory.BLOCKS,1f, 1f);
context.getLevel().playBlockSound(finalPlacePosition, customFurniture.settings().sounds().placeSound());
player.swingHand(context.getHand());
return InteractionResult.SUCCESS;
}