From 67f331bcb076f704f75dde3c3a65160886bde0c8 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 May 2024 16:14:03 +0100 Subject: [PATCH 01/11] Fixed fallback handling producing stone walking sounds for air blocks. Fixes #303 --- .../ha3/presencefootsteps/world/AssociationPool.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/world/AssociationPool.java b/src/main/java/eu/ha3/presencefootsteps/world/AssociationPool.java index c0da0eb0..3136538c 100644 --- a/src/main/java/eu/ha3/presencefootsteps/world/AssociationPool.java +++ b/src/main/java/eu/ha3/presencefootsteps/world/AssociationPool.java @@ -74,15 +74,19 @@ public SoundsKey get(BlockPos pos, BlockState state, String substrate) { } BlockState baseState = DerivedBlock.getBaseOf(state); - if (!state.isAir() && ( - getForState(state, substrate) + + if (state.isAir()) { + return SoundsKey.NON_EMITTER; + } + + if (getForState(state, substrate) || (!baseState.isAir() && ( getForState(baseState, substrate) || (!Substrates.isDefault(substrate) && getForState(baseState, Substrates.DEFAULT)) || (getForPrimitive(baseState, substrate)) )) || getForPrimitive(state, substrate) - )) { + ) { return association; } From edcd831c7723f66a04f58744d603cd13fedc7388 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 May 2024 17:26:04 +0100 Subject: [PATCH 02/11] Fix edge detection and only look at fences if the player's bounding box is touching them --- .../world/AssociationPool.java | 2 +- .../ha3/presencefootsteps/world/PFSolver.java | 89 ++++++++----------- 2 files changed, 36 insertions(+), 55 deletions(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/world/AssociationPool.java b/src/main/java/eu/ha3/presencefootsteps/world/AssociationPool.java index 3136538c..a123621f 100644 --- a/src/main/java/eu/ha3/presencefootsteps/world/AssociationPool.java +++ b/src/main/java/eu/ha3/presencefootsteps/world/AssociationPool.java @@ -76,7 +76,7 @@ public SoundsKey get(BlockPos pos, BlockState state, String substrate) { BlockState baseState = DerivedBlock.getBaseOf(state); if (state.isAir()) { - return SoundsKey.NON_EMITTER; + return SoundsKey.UNASSIGNED; } if (getForState(state, substrate) diff --git a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java index 8f3e0976..e9eda72e 100644 --- a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java +++ b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java @@ -1,5 +1,6 @@ package eu.ha3.presencefootsteps.world; +import eu.ha3.presencefootsteps.PresenceFootsteps; import eu.ha3.presencefootsteps.compat.ContraptionCollidable; import eu.ha3.presencefootsteps.sound.SoundEngine; import eu.ha3.presencefootsteps.util.PlayerUtil; @@ -9,6 +10,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; +import net.minecraft.particle.ParticleTypes; import net.minecraft.registry.tag.FluidTags; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; @@ -143,59 +145,35 @@ public Association findAssociation(AssociationPool associations, LivingEntity pl private Association findAssociation(AssociationPool associations, LivingEntity player, Box collider, BlockPos originalFootPos, BlockPos.Mutable pos) { Association association; - // If it didn't work, the player has walked over the air on the border of a block. - // ------ ------ --> z - // | o | < player is here - // wool | air | - // ------ ------ - // | - // V z if ((association = findAssociation(associations, player, pos, collider)).isResult()) { return association; } - pos.set(originalFootPos); - // Create a trigo. mark contained inside the block the player is over - double xdang = (player.getX() - pos.getX()) * 2 - 1; - double zdang = (player.getZ() - pos.getZ()) * 2 - 1; - // -1 0 1 - // ------- -1 - // | o | - // | + | 0 --> x - // | | - // ------- 1 - // | - // V z - - // If the player is at the edge of that - if (Math.max(Math.abs(xdang), Math.abs(zdang)) <= 0.2f) { - return association; - } - // Find the maximum absolute value of X or Z - boolean isXdangMax = Math.abs(xdang) > Math.abs(zdang); - // --------------------- ^ maxofZ- - // | . . | - // | . . | - // | o . . | - // | . . | - // | . | - // < maxofX- maxofX+ > - // Take the maximum border to produce the sound - // If we are in the positive border, add 1, else subtract 1 - if ((association = findAssociation(associations, player, isXdangMax - ? pos.move(Direction.EAST, xdang > 0 ? 1 : -1) - : pos.move(Direction.SOUTH, zdang > 0 ? 1 : -1), collider)).isResult()) { - return association; + double radius = 0.4; + int[] xValues = new int[] { + MathHelper.floor(collider.getMin(Axis.X) - radius), + pos.getX(), + MathHelper.floor(collider.getMax(Axis.X) + radius) + }; + int[] zValues = new int[] { + MathHelper.floor(collider.getMin(Axis.Z) - radius), + pos.getZ(), + MathHelper.floor(collider.getMax(Axis.Z) + radius) + }; + + for (int x : xValues) { + for (int z : zValues) { + if (x != originalFootPos.getX() || z != originalFootPos.getZ()) { + pos.set(x, originalFootPos.getY(), z); + if ((association = findAssociation(associations, player, pos, collider)).isResult()) { + return association; + } + } + } } - - // If that didn't work, then maybe the footstep hit in the - // direction of walking - // Try with the other closest block pos.set(originalFootPos); - // Take the maximum direction and try with the orthogonal direction of it - return findAssociation(associations, player, isXdangMax - ? pos.move(Direction.SOUTH, zdang > 0 ? 1 : -1) - : pos.move(Direction.EAST, xdang > 0 ? 1 : -1), collider); + + return Association.NOT_EMITTER; } private Association findAssociation(AssociationPool associations, LivingEntity entity, BlockPos.Mutable pos, Box collider) { @@ -223,12 +201,15 @@ private Association findAssociation(AssociationPool associations, LivingEntity e pos.move(Direction.DOWN); BlockState fence = getBlockStateAt(entity, pos); - if ((association = associations.get(pos, fence, Substrates.FENCE)).isResult()) { - carpet = target; - target = fence; - // reference frame moved down by 1 - } else { - pos.move(Direction.UP); + // Only check fences if we're actually touching them + if (checkCollision(entity.getWorld(), fence, pos, collider)) { + if ((association = associations.get(pos, fence, Substrates.FENCE)).isResult()) { + carpet = target; + target = fence; + // reference frame moved down by 1 + } else { + pos.move(Direction.UP); + } } } @@ -251,7 +232,7 @@ private Association findAssociation(AssociationPool associations, LivingEntity e // Check collision against small blocks if (association.isResult() && !checkCollision(entity.getWorld(), target, pos, collider)) { - association = SoundsKey.NON_EMITTER; + association = SoundsKey.UNASSIGNED; } if (association.isEmitter() && (hasRain From 8b606ba4fe73ca52a2a6154869e8288ffeb91169 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 May 2024 17:55:20 +0100 Subject: [PATCH 03/11] Add a visualisation of which blocks are producing sounds for debugging --- .../eu/ha3/presencefootsteps/PFConfig.java | 5 ++++ .../ha3/presencefootsteps/world/PFSolver.java | 30 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/PFConfig.java b/src/main/java/eu/ha3/presencefootsteps/PFConfig.java index 468582c1..47a28ab2 100644 --- a/src/main/java/eu/ha3/presencefootsteps/PFConfig.java +++ b/src/main/java/eu/ha3/presencefootsteps/PFConfig.java @@ -28,6 +28,7 @@ public class PFConfig extends JsonFile { private boolean multiplayer = true; private boolean global = true; private boolean footwear = true; + private boolean visualiser = false; private Locomotion stance = Locomotion.NONE; private EntitySelector targetEntities = EntitySelector.ALL; @@ -65,6 +66,10 @@ public Locomotion setLocomotion(Locomotion loco) { return loco; } + public boolean isVisualiserRunning() { + return visualiser; + } + public boolean isFirstRun() { return firstRun; } diff --git a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java index e9eda72e..78cd614c 100644 --- a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java +++ b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java @@ -1,6 +1,5 @@ package eu.ha3.presencefootsteps.world; -import eu.ha3.presencefootsteps.PresenceFootsteps; import eu.ha3.presencefootsteps.compat.ContraptionCollidable; import eu.ha3.presencefootsteps.sound.SoundEngine; import eu.ha3.presencefootsteps.util.PlayerUtil; @@ -145,7 +144,22 @@ public Association findAssociation(AssociationPool associations, LivingEntity pl private Association findAssociation(AssociationPool associations, LivingEntity player, Box collider, BlockPos originalFootPos, BlockPos.Mutable pos) { Association association; + if (engine.getConfig().isVisualiserRunning()) { + for (int i = 0; i < 10; i++) { + player.getWorld().addParticle(ParticleTypes.DOLPHIN, + pos.getX() + 0.5, + pos.getY() + 1, + pos.getZ() + 0.5, 0, 0, 0); + } + } + if ((association = findAssociation(associations, player, pos, collider)).isResult()) { + if (engine.getConfig().isVisualiserRunning()) { + player.getWorld().addParticle(ParticleTypes.DUST_PLUME, + association.pos().getX() + 0.5, + association.pos().getY() + 0.9, + association.pos().getZ() + 0.5, 0, 0, 0); + } return association; } @@ -165,7 +179,21 @@ private Association findAssociation(AssociationPool associations, LivingEntity p for (int z : zValues) { if (x != originalFootPos.getX() || z != originalFootPos.getZ()) { pos.set(x, originalFootPos.getY(), z); + if (engine.getConfig().isVisualiserRunning()) { + for (int i = 0; i < 10; i++) { + player.getWorld().addParticle(ParticleTypes.DOLPHIN, + pos.getX() + 0.5, + pos.getY() + 1, + pos.getZ() + 0.5, 0, 0, 0); + } + } if ((association = findAssociation(associations, player, pos, collider)).isResult()) { + if (engine.getConfig().isVisualiserRunning()) { + player.getWorld().addParticle(ParticleTypes.DUST_PLUME, + association.pos().getX() + 0.5, + association.pos().getY() + 0.9, + association.pos().getZ() + 0.5, 0, 0, 0); + } return association; } } From 67a0934e76db92b2ebe808f53883b684ca28e79c Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 May 2024 17:55:43 +0100 Subject: [PATCH 04/11] Fixed fire sounds and give it a proper subtitle. Fixes #300 --- .../ha3/presencefootsteps/world/PFSolver.java | 3 ++- .../assets/presencefootsteps/lang/en_us.json | 1 + .../presencefootsteps/config/acoustics.json | 6 +++--- .../presencefootsteps/config/blockmap.json | 7 +++---- .../assets/presencefootsteps/sounds.json | 17 +++++++++++++++++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java index 78cd614c..ac6fdfd1 100644 --- a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java +++ b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java @@ -218,10 +218,11 @@ private Association findAssociation(AssociationPool associations, LivingEntity e SoundsKey foliage = SoundsKey.UNASSIGNED; SoundsKey wetAssociation = SoundsKey.UNASSIGNED; - if (isValidCarpet && (association = associations.get(pos, carpet, Substrates.CARPET)).isEmitter()) { + if (isValidCarpet && (association = associations.get(pos, carpet, Substrates.CARPET)).isEmitter() && !association.isSilent()) { target = carpet; // reference frame moved up by 1 } else { + association = SoundsKey.UNASSIGNED; pos.move(Direction.DOWN); // This condition implies that if the carpet is NOT_EMITTER, solving will // CONTINUE with the actual block surface the player is walking on diff --git a/src/main/resources/assets/presencefootsteps/lang/en_us.json b/src/main/resources/assets/presencefootsteps/lang/en_us.json index 26ee4221..6381e9a5 100644 --- a/src/main/resources/assets/presencefootsteps/lang/en_us.json +++ b/src/main/resources/assets/presencefootsteps/lang/en_us.json @@ -67,6 +67,7 @@ "subtitles.pf.wings_flap": "Wings flap", "subtitles.pf.leaves_rustle": "Leaves rustles", "subtitles.pf.grass_rustles": "Grass rustles", + "subtitles.pf.fire_flames": "Fire Hisses", "subtitles.pf.land": "Wings folding", "subtitles.pf.metal_clink": "Metal clinking", "subtitles.pf.snow_crunch": "Snow crunches", diff --git a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json index 02a5dfc1..b0a7f69d 100644 --- a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json +++ b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json @@ -541,7 +541,7 @@ "type": "events", "land": { "type": "basic", - "name": "brush.brush_through", + "name": "fire_flames", "pitch": { "min": 70.0, "max": 80.0 @@ -549,7 +549,7 @@ }, "jump": { "type": "basic", - "name": "brush.brush_through", + "name": "fire.flames", "pitch": { "min": 70.0, "max": 80.0 @@ -557,7 +557,7 @@ }, "walk": { "type": "basic", - "name": "brush.brush_through", + "name": "fire.flames", "pitch": { "min": 70.0, "max": 80.0 diff --git a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/blockmap.json b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/blockmap.json index 65c2f6fc..0648dfeb 100644 --- a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/blockmap.json +++ b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/blockmap.json @@ -138,10 +138,9 @@ "minecraft:cobweb": "NOT_EMITTER", "minecraft:redstone_wire": "NOT_EMITTER", - "minecraft:fire": "NOT_EMITTER", - "minecraft:fire.foliage": "fire", - "minecraft:soul_fire": "NOT_EMITTER", - "minecraft:soul_fire.foliage": "fire", + "#minecraft:fire": "NOT_EMITTER", + "#minecraft:fire.carpet": "NOT_EMITTER", + "#minecraft:fire.foliage": "fire", "minecraft:spawner": "metalbar", "minecraft:grass": "NOT_EMITTER", diff --git a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/sounds.json b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/sounds.json index c4af89d5..f6f69793 100644 --- a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/sounds.json +++ b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/sounds.json @@ -43,6 +43,23 @@ "presencefootsteps:bluntwood/bluntwood_wander5" ] }, + "pf_presence.fire.flames": { + "category": "master", + "subtitle": "subtitles.pf.fire_flames", + "sounds": [ + "presencefootsteps:brush/brush_through1", + "presencefootsteps:brush/brush_through10", + "presencefootsteps:brush/brush_through11", + "presencefootsteps:brush/brush_through2", + "presencefootsteps:brush/brush_through3", + "presencefootsteps:brush/brush_through4", + "presencefootsteps:brush/brush_through5", + "presencefootsteps:brush/brush_through6", + "presencefootsteps:brush/brush_through7", + "presencefootsteps:brush/brush_through8", + "presencefootsteps:brush/brush_through9" + ] + }, "pf_presence.brush.brush_through": { "category": "master", "subtitle": "subtitles.pf.grass_rustles", From be1746668b2a592e9c05d6c7a4c1e34f464e08dd Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 May 2024 18:00:43 +0100 Subject: [PATCH 05/11] Step sounds are no longer blocked for entities with locomotion type = none --- .../java/eu/ha3/presencefootsteps/sound/StepSoundSource.java | 3 ++- .../assets/presencefootsteps/config/locomotionmap.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/sound/StepSoundSource.java b/src/main/java/eu/ha3/presencefootsteps/sound/StepSoundSource.java index 525b9456..4dc7dbe7 100644 --- a/src/main/java/eu/ha3/presencefootsteps/sound/StepSoundSource.java +++ b/src/main/java/eu/ha3/presencefootsteps/sound/StepSoundSource.java @@ -35,7 +35,8 @@ public Optional getStepGenerator(SoundEngine engine) { @Override public boolean isStepBlocked() { - return PresenceFootsteps.getInstance().getEngine().isEnabledFor(entity); + return PresenceFootsteps.getInstance().getEngine().isEnabledFor(entity) + && getStepGenerator(PresenceFootsteps.getInstance().getEngine()).isPresent(); } } } diff --git a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/locomotionmap.json b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/locomotionmap.json index 015013c5..2871e941 100644 --- a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/locomotionmap.json +++ b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/locomotionmap.json @@ -70,7 +70,7 @@ "minecraft:zombie_horse": "QUADRUPED", "minecraft:zombie_villager": "BIPED", "minecraft:ravager": "QUADRUPED", - "minecraft:strider": "BIPED", + "minecraft:strider": "NONE", "minecraft:axolotl": "QUADRUPED", "minecraft:goat": "QUADRUPED", "minecraft:glow_squid": "NONE", From 20f1cf26e889c0e898841fe882f0a98f79fc4465 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 May 2024 18:04:43 +0100 Subject: [PATCH 06/11] Only block network plays for fall and swim sounds (as those are the ones sent from the server, and blocking others has side-effects) --- .../presencefootsteps/sound/SoundEngine.java | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/sound/SoundEngine.java b/src/main/java/eu/ha3/presencefootsteps/sound/SoundEngine.java index d0d75a3a..2ef2ed96 100644 --- a/src/main/java/eu/ha3/presencefootsteps/sound/SoundEngine.java +++ b/src/main/java/eu/ha3/presencefootsteps/sound/SoundEngine.java @@ -12,7 +12,6 @@ import org.jetbrains.annotations.Nullable; import eu.ha3.presencefootsteps.PFConfig; -import eu.ha3.presencefootsteps.config.EntitySelector; import eu.ha3.presencefootsteps.sound.player.ImmediateSoundPlayer; import eu.ha3.presencefootsteps.util.PlayerUtil; import eu.ha3.presencefootsteps.world.Solver; @@ -169,34 +168,11 @@ public void onFrame(MinecraftClient client, Entity cameraEntity) { } public boolean onSoundRecieved(@Nullable RegistryEntry event, SoundCategory category) { - if (event == null || !isRunning(MinecraftClient.getInstance())) { - return false; - } - - if (config.getEntitySelector() == EntitySelector.PLAYERS_ONLY && category != SoundCategory.PLAYERS) { - return false; - } - - if (config.getEntitySelector() == EntitySelector.PLAYERS_AND_HOSTILES && category != SoundCategory.PLAYERS && category != SoundCategory.HOSTILE) { - return false; - } - - if (config.getEntitySelector() == EntitySelector.ALL && category != SoundCategory.PLAYERS && category != SoundCategory.HOSTILE && category != SoundCategory.NEUTRAL) { - return false; - } - - return event.getKeyOrValue().right().filter(sound -> { - if (event == SoundEvents.ENTITY_PLAYER_SWIM + return event != null && isRunning(MinecraftClient.getInstance()) && event.getKeyOrValue().right().filter(sound -> { + return event == SoundEvents.ENTITY_PLAYER_SWIM || event == SoundEvents.ENTITY_PLAYER_SPLASH || event == SoundEvents.ENTITY_PLAYER_BIG_FALL - || event == SoundEvents.ENTITY_PLAYER_SMALL_FALL) { - return true; - } - - String[] name = sound.getId().getPath().split("\\."); - return name.length > 0 - && "block".contentEquals(name[0]) - && "step".contentEquals(name[name.length - 1]); + || event == SoundEvents.ENTITY_PLAYER_SMALL_FALL; }).isPresent(); } From 982f09e1ace35ac965f4a6bf9a59c9e4a306013f Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 May 2024 18:14:33 +0100 Subject: [PATCH 07/11] Revert to the previous behaviour where mobs produced both normal and presence footsteps and add a toggle to re-enable sounds blocking --- src/main/java/eu/ha3/presencefootsteps/PFConfig.java | 11 +++++++++++ .../eu/ha3/presencefootsteps/PFOptionsScreen.java | 5 +++++ .../ha3/presencefootsteps/sound/StepSoundSource.java | 8 ++++++-- .../assets/presencefootsteps/lang/en_us.json | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/PFConfig.java b/src/main/java/eu/ha3/presencefootsteps/PFConfig.java index 47a28ab2..102b03fd 100644 --- a/src/main/java/eu/ha3/presencefootsteps/PFConfig.java +++ b/src/main/java/eu/ha3/presencefootsteps/PFConfig.java @@ -29,6 +29,7 @@ public class PFConfig extends JsonFile { private boolean global = true; private boolean footwear = true; private boolean visualiser = false; + private boolean exclusive = false; private Locomotion stance = Locomotion.NONE; private EntitySelector targetEntities = EntitySelector.ALL; @@ -97,6 +98,16 @@ public boolean toggleFootwear() { return footwear; } + public boolean isExclusiveMode() { + return exclusive; + } + + public boolean toggleExclusiveMode() { + exclusive = !exclusive; + save(); + return exclusive; + } + public boolean getEnabledMP() { return multiplayer; } diff --git a/src/main/java/eu/ha3/presencefootsteps/PFOptionsScreen.java b/src/main/java/eu/ha3/presencefootsteps/PFOptionsScreen.java index 1529ad5c..9f7e8d58 100644 --- a/src/main/java/eu/ha3/presencefootsteps/PFOptionsScreen.java +++ b/src/main/java/eu/ha3/presencefootsteps/PFOptionsScreen.java @@ -130,6 +130,11 @@ private void rebuildContent() { })).getStyle() .setText("menu.pf.footwear." + (config.getEnabledFootwear() ? "on" : "off")); + content.addButton(new Button(wideRight, row, 150, 20).onClick(sender -> { + sender.getStyle().setText("menu.pf.exclusive_mode." + (config.toggleExclusiveMode() ? "on" : "off")); + })).getStyle() + .setText("menu.pf.exclusive_mode." + (config.isExclusiveMode() ? "on" : "off")); + content.addButton(new Label(wideLeft, row += 25)).getStyle().setText("menu.pf.group.sound_packs"); content.addButton(new Button(wideLeft, row += 25, 150, 20).onClick(sender -> { diff --git a/src/main/java/eu/ha3/presencefootsteps/sound/StepSoundSource.java b/src/main/java/eu/ha3/presencefootsteps/sound/StepSoundSource.java index 4dc7dbe7..a43e799b 100644 --- a/src/main/java/eu/ha3/presencefootsteps/sound/StepSoundSource.java +++ b/src/main/java/eu/ha3/presencefootsteps/sound/StepSoundSource.java @@ -6,6 +6,7 @@ import eu.ha3.presencefootsteps.sound.generator.Locomotion; import eu.ha3.presencefootsteps.sound.generator.StepSoundGenerator; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; public interface StepSoundSource { Optional getStepGenerator(SoundEngine engine); @@ -35,8 +36,11 @@ public Optional getStepGenerator(SoundEngine engine) { @Override public boolean isStepBlocked() { - return PresenceFootsteps.getInstance().getEngine().isEnabledFor(entity) - && getStepGenerator(PresenceFootsteps.getInstance().getEngine()).isPresent(); + SoundEngine engine = PresenceFootsteps.getInstance().getEngine(); + if (!engine.getConfig().isExclusiveMode() && !(entity instanceof PlayerEntity)) { + return false; + } + return engine.isEnabledFor(entity) && getStepGenerator(engine).isPresent(); } } } diff --git a/src/main/resources/assets/presencefootsteps/lang/en_us.json b/src/main/resources/assets/presencefootsteps/lang/en_us.json index 6381e9a5..1c442b10 100644 --- a/src/main/resources/assets/presencefootsteps/lang/en_us.json +++ b/src/main/resources/assets/presencefootsteps/lang/en_us.json @@ -22,6 +22,8 @@ "menu.pf.volume.passive_entities": "Passive Entities: %d%%", "menu.pf.footwear.on": "Footwear: ON", "menu.pf.footwear.off": "Footwear: OFF", + "menu.pf.exclusive_mode.on": "Exclusive Mode: ON", + "menu.pf.exclusive_mode.off": "Exclusive Mode: OFF", "menu.pf.volume.passive_entities.tooltip": "Changes the volume of animal' footsteps.", "menu.pf.volume.player": "Client Player: %d%%", "menu.pf.volume.player.tooltip": "Changes the volume of your own footsteps.", From 29aae6a214e128921ce0e2415a955473402afab8 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 May 2024 23:53:32 +0100 Subject: [PATCH 08/11] Added sounds for walking on water and lava, and added sounds for swimming in lava. Fixes #302 # Conflicts: # src/main/java/eu/ha3/presencefootsteps/sound/generator/TerrestrialStepSoundGenerator.java --- .../TerrestrialStepSoundGenerator.java | 15 ++-- .../ha3/presencefootsteps/world/PFSolver.java | 39 ++++++---- .../presencefootsteps/world/SoundsKey.java | 5 +- .../presencefootsteps/config/acoustics.json | 72 ++++++++++++++++++- 4 files changed, 111 insertions(+), 20 deletions(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/sound/generator/TerrestrialStepSoundGenerator.java b/src/main/java/eu/ha3/presencefootsteps/sound/generator/TerrestrialStepSoundGenerator.java index 30a8e880..c7ae48d4 100644 --- a/src/main/java/eu/ha3/presencefootsteps/sound/generator/TerrestrialStepSoundGenerator.java +++ b/src/main/java/eu/ha3/presencefootsteps/sound/generator/TerrestrialStepSoundGenerator.java @@ -6,8 +6,10 @@ import net.minecraft.entity.passive.AbstractHorseEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ArmorItem; +import net.minecraft.registry.tag.FluidTags; import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; +import com.google.common.base.MoreObjects; import eu.ha3.presencefootsteps.config.Variator; import eu.ha3.presencefootsteps.mixins.ILivingEntity; @@ -213,11 +215,12 @@ public final void produceStep(@Nullable State event, double verticalOffsetAsMinu if (hasStoppingConditions()) { float volume = Math.min(1, (float) entity.getVelocity().length() * 0.35F); - Options options = Options.singular("gliding_volume", volume); - State state = entity.isSubmergedInWater() ? State.SWIM : event; - - engine.getIsolator().acoustics().playAcoustic(entity, SoundsKey.SWIM, state, options); + engine.getIsolator().acoustics().playAcoustic(entity, + entity.isTouchingWater() ? SoundsKey.SWIM_WATER : SoundsKey.SWIM_LAVA, + (entity.isSubmergedInWater() || entity.isSubmergedIn(FluidTags.LAVA)) ? State.SWIM : event, + Options.singular("gliding_volume", volume) + ); playStep(associations.findAssociation(entity.getBlockPos().down(), Solver.MESSY_FOLIAGE_STRATEGY), event); } else { if (!entity.isSneaky() || event.isExtraLoud()) { @@ -230,7 +233,7 @@ public final void produceStep(@Nullable State event, double verticalOffsetAsMinu } protected boolean hasStoppingConditions() { - return entity.isTouchingWater(); + return entity.isTouchingWater() || entity.isInLava(); } protected void simulateAirborne() { @@ -310,7 +313,7 @@ private void simulateBrushes() { Association assos = associations.findAssociation(BlockPos.ofFloored( entity.getX(), - entity.getY() - 0.1D - (entity.hasVehicle() ? entity.getHeightOffset() : 0) - (entity.isOnGround() ? 0 : 0.25D), + MoreObjects.firstNonNull(entity.getRootVehicle(), entity).getY() - 0.1D - (entity.isOnGround() ? 0 : 0.25D), entity.getZ() ), Solver.MESSY_FOLIAGE_STRATEGY); diff --git a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java index ac6fdfd1..78c34f1d 100644 --- a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java +++ b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java @@ -72,6 +72,7 @@ public Association findAssociation(AssociationPool associations, LivingEntity pl if (!MESSY_FOLIAGE_STRATEGY.equals(strategy)) { return Association.NOT_EMITTER; } + pos = pos.up(); BlockState above = getBlockStateAt(ply, pos); @@ -141,6 +142,7 @@ public Association findAssociation(AssociationPool associations, LivingEntity pl return assos; } + @SuppressWarnings("deprecation") private Association findAssociation(AssociationPool associations, LivingEntity player, Box collider, BlockPos originalFootPos, BlockPos.Mutable pos) { Association association; @@ -154,13 +156,15 @@ private Association findAssociation(AssociationPool associations, LivingEntity p } if ((association = findAssociation(associations, player, pos, collider)).isResult()) { - if (engine.getConfig().isVisualiserRunning()) { - player.getWorld().addParticle(ParticleTypes.DUST_PLUME, - association.pos().getX() + 0.5, - association.pos().getY() + 0.9, - association.pos().getZ() + 0.5, 0, 0, 0); + if (!association.state().isLiquid()) { + if (engine.getConfig().isVisualiserRunning()) { + player.getWorld().addParticle(ParticleTypes.DUST_PLUME, + association.pos().getX() + 0.5, + association.pos().getY() + 0.9, + association.pos().getZ() + 0.5, 0, 0, 0); + } + return association; } - return association; } double radius = 0.4; @@ -188,19 +192,30 @@ private Association findAssociation(AssociationPool associations, LivingEntity p } } if ((association = findAssociation(associations, player, pos, collider)).isResult()) { - if (engine.getConfig().isVisualiserRunning()) { - player.getWorld().addParticle(ParticleTypes.DUST_PLUME, - association.pos().getX() + 0.5, - association.pos().getY() + 0.9, - association.pos().getZ() + 0.5, 0, 0, 0); + if (!association.state().isLiquid()) { + if (engine.getConfig().isVisualiserRunning()) { + player.getWorld().addParticle(ParticleTypes.DUST_PLUME, + association.pos().getX() + 0.5, + association.pos().getY() + 0.9, + association.pos().getZ() + 0.5, 0, 0, 0); + } + return association; } - return association; } } } } pos.set(originalFootPos); + BlockState state = getBlockStateAt(player, pos); + + if (state.isLiquid()) { + if (state.getFluidState().isIn(FluidTags.LAVA)) { + return Association.of(state, pos.down(), player, SoundsKey.LAVAFINE, SoundsKey.NON_EMITTER, SoundsKey.NON_EMITTER); + } + return Association.of(state, pos.down(), player, SoundsKey.WATERFINE, SoundsKey.NON_EMITTER, SoundsKey.NON_EMITTER); + } + return Association.NOT_EMITTER; } diff --git a/src/main/java/eu/ha3/presencefootsteps/world/SoundsKey.java b/src/main/java/eu/ha3/presencefootsteps/world/SoundsKey.java index c9fed6d5..96e23db9 100644 --- a/src/main/java/eu/ha3/presencefootsteps/world/SoundsKey.java +++ b/src/main/java/eu/ha3/presencefootsteps/world/SoundsKey.java @@ -7,7 +7,10 @@ public record SoundsKey(String raw, String[] names) { static final SoundsKey NON_EMITTER = new SoundsKey("NOT_EMITTER", new String[0]); static final SoundsKey MESSY_GROUND = new SoundsKey("MESSY_GROUND", new String[0]); - public static final SoundsKey SWIM = of("_SWIM"); + public static final SoundsKey SWIM_WATER = of("_SWIM_WATER"); + public static final SoundsKey SWIM_LAVA = of("_SWIM_LAVA"); + public static final SoundsKey WATERFINE = of("waterfine"); + public static final SoundsKey LAVAFINE = of("lavafine"); public static SoundsKey of(String names) { if (MESSY_GROUND.raw().equals(names)) { diff --git a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json index b0a7f69d..bcda66c5 100644 --- a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json +++ b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json @@ -189,7 +189,7 @@ } ] }, - "_SWIM": { + "_SWIM_WATER": { "type": "events", "swim": { "type": "basic", @@ -216,6 +216,33 @@ } } }, + "_SWIM_LAVA": { + "type": "events", + "swim": { + "type": "basic", + "name": "@minecraft:entity.player.swim", + "volume": { + "min": 10.0, + "max": 100.0 + }, + "pitch": { + "min": 9.0, + "max": 11.0 + } + }, + "walk": { + "type": "basic", + "name": "@minecraft:entity.player.swim", + "volume": { + "min": 10.0, + "max": 100.0 + }, + "pitch": { + "min": 9.0, + "max": 11.0 + } + } + }, "_WING": { "type": "events", "swim": { @@ -523,6 +550,49 @@ ] } }, + "lavafine": { + "type": "events", + "walk": { + "type": "probability", + "entries": [ + 1, + { + "name": "water.water_through", + "pitch": 0.25 + }, + 1, + { + "name": "water_stereofix.water_through", + "pitch": 0.25 + } + ] + }, + "wander": { + "type": "probability", + "entries": [ + 1, + { + "name": "water.water_wander", + "pitch": 0.25 + }, + 1, + { + "name": "water_stereofix.water_wander", + "pitch": 0.25 + } + ] + }, + "land": [ + { + "name": "water.water_through", + "pitch": 0.25 + }, + { + "name": "water_stereofix.water_through", + "pitch": 0.25 + } + ] + }, "composite": { "type": "events", "wander": "marble.marble_wander", From bf698f21492646720a0764606d4e8dd4a5838591 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 15 May 2024 19:22:53 +0100 Subject: [PATCH 09/11] Fixed magma acoustics volume being louder than intended. Fixes #299 # Conflicts: # src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json --- .../presencefootsteps/config/acoustics.json | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json index bcda66c5..a26cd0e6 100644 --- a/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json +++ b/src/main/resources/resourcepacks/default_sound_pack/assets/presencefootsteps/config/acoustics.json @@ -276,8 +276,8 @@ "type": "basic", "name": "@minecraft:block.fire.extinguish", "volume": { - "min": 90.0, - "max": 20.0 + "min": 20.0, + "max": 80.0 }, "pitch": { "min": 70.0, @@ -288,8 +288,8 @@ "type": "basic", "name": "@minecraft:block.fire.extinguish", "volume": { - "min": 8.0, - "max": 10.0 + "min": 1.0, + "max": 5.0 }, "pitch": { "min": 60.000004, @@ -299,6 +299,10 @@ "land": { "type": "basic", "name": "@minecraft:block.fire.extinguish", + "volume": { + "min": 20.0, + "max": 80.0 + }, "pitch": { "min": 70.0, "max": 80.0 @@ -307,9 +311,13 @@ "jump": { "type": "basic", "name": "mud.mud_walk", + "volume": { + "min": 1.0, + "max": 5.0 + }, "pitch": { - "min": 60.000004, - "max": 80.0 + "min": 30.0, + "max": 60.0 } }, "walk": [ @@ -317,6 +325,10 @@ { "type": "basic", "name": "@minecraft:block.fire.extinguish", + "volume": { + "min": 8.0, + "max": 15.0 + }, "pitch": { "min": 70.0, "max": 80.0 @@ -2207,4 +2219,4 @@ } } } -} \ No newline at end of file +} From 8e5f0b5b0cb344c5bb1ab73cb1d13c03039fdaba Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 15 May 2024 19:43:51 +0100 Subject: [PATCH 10/11] Fix broken mixin --- .../ha3/presencefootsteps/mixins/MClientPlayNetworkHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/mixins/MClientPlayNetworkHandler.java b/src/main/java/eu/ha3/presencefootsteps/mixins/MClientPlayNetworkHandler.java index bfd9c6c0..4887a669 100644 --- a/src/main/java/eu/ha3/presencefootsteps/mixins/MClientPlayNetworkHandler.java +++ b/src/main/java/eu/ha3/presencefootsteps/mixins/MClientPlayNetworkHandler.java @@ -15,7 +15,7 @@ public abstract class MClientPlayNetworkHandler implements ClientPlayPacketListener { @Inject(method = "onPlaySound(Lnet/minecraft/network/packet/s2c/play/PlaySoundS2CPacket;)V", - at = @At(value = "INVOKE", target = "net/minectaft/client/ClientWorld.playSound(" + at = @At(value = "INVOKE", target = "net/minectaft/client/world/ClientWorld.playSound(" + "Lnet/minecraft/entity/player/PlayerEntity;" + "DDD" + "Lnet/minecraft/registry/entry/RegistryEntry;" From b87cbc66297d97f0c67fac3cc528eb6c73edfb3f Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 15 May 2024 19:43:59 +0100 Subject: [PATCH 11/11] Backport fixes --- src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java index 78c34f1d..420b0883 100644 --- a/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java +++ b/src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java @@ -158,7 +158,7 @@ private Association findAssociation(AssociationPool associations, LivingEntity p if ((association = findAssociation(associations, player, pos, collider)).isResult()) { if (!association.state().isLiquid()) { if (engine.getConfig().isVisualiserRunning()) { - player.getWorld().addParticle(ParticleTypes.DUST_PLUME, + player.getWorld().addParticle(ParticleTypes.CLOUD, association.pos().getX() + 0.5, association.pos().getY() + 0.9, association.pos().getZ() + 0.5, 0, 0, 0); @@ -194,7 +194,7 @@ private Association findAssociation(AssociationPool associations, LivingEntity p if ((association = findAssociation(associations, player, pos, collider)).isResult()) { if (!association.state().isLiquid()) { if (engine.getConfig().isVisualiserRunning()) { - player.getWorld().addParticle(ParticleTypes.DUST_PLUME, + player.getWorld().addParticle(ParticleTypes.CLOUD, association.pos().getX() + 0.5, association.pos().getY() + 0.9, association.pos().getZ() + 0.5, 0, 0, 0);