Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Mar 9, 2024
2 parents c46bd41 + 5799b0e commit f89dfa2
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 142 deletions.
2 changes: 1 addition & 1 deletion src/main/java/eu/ha3/presencefootsteps/PFDebugHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void render(HitResult blockHit, HitResult fluidHit, List<String> finalLis
: hasRain ? Formatting.GRAY + "SHELTERED" : Formatting.GRAY + "DRY"
));
renderSoundList("Step Sounds[B]", engine.getIsolator().blocks().getAssociations(state), list);
renderSoundList("Step Sounds[P]", engine.getIsolator().primitives().getAssociations(state.getSoundGroup()), list);
renderSoundList("Step Sounds[P]", engine.getIsolator().primitives().getAssociations(state.getSoundGroup().getStepSound()), list);
list.add("");

insertAt(list, finalList, "Targeted Block: ", 1);
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/eu/ha3/presencefootsteps/sound/Isolator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import eu.ha3.presencefootsteps.sound.acoustics.AcousticsFile;
import eu.ha3.presencefootsteps.sound.acoustics.AcousticsPlayer;
import eu.ha3.presencefootsteps.sound.generator.Locomotion;
import eu.ha3.presencefootsteps.sound.player.PFSoundPlayer;
import eu.ha3.presencefootsteps.sound.player.SoundPlayer;
import eu.ha3.presencefootsteps.sound.player.StepSoundPlayer;
import eu.ha3.presencefootsteps.sound.player.DelayedSoundPlayer;
import eu.ha3.presencefootsteps.util.JsonObjectWriter;
import eu.ha3.presencefootsteps.util.ResourceUtils;
import eu.ha3.presencefootsteps.util.BlockReport.Reportable;
Expand All @@ -26,6 +24,7 @@
import net.minecraft.entity.EntityType;
import net.minecraft.resource.ResourceManager;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;

public record Isolator (
Expand All @@ -34,9 +33,7 @@ public record Isolator (
HeuristicStateLookup heuristics,
Lookup<EntityType<?>> golems,
Lookup<BlockState> blocks,
PrimitiveLookup primitives,
SoundPlayer soundPlayer,
StepSoundPlayer stepPlayer,
Lookup<SoundEvent> primitives,
AcousticLibrary acoustics
) implements Reportable {
private static final Identifier BLOCK_MAP = new Identifier("presencefootsteps", "config/blockmap.json");
Expand All @@ -47,15 +44,14 @@ public record Isolator (
private static final Identifier VARIATOR = new Identifier("presencefootsteps", "config/variator.json");

public Isolator(SoundEngine engine) {
this(engine, new PFSoundPlayer(engine));
}

public Isolator(SoundEngine engine, SoundPlayer player) {
this(engine, player, (StepSoundPlayer)player);
}

public Isolator(SoundEngine engine, SoundPlayer player, StepSoundPlayer stepPlayer) {
this(new Variator(), new LocomotionLookup(engine), new HeuristicStateLookup(), new GolemLookup(), new StateLookup(), new PrimitiveLookup(), player, stepPlayer, new AcousticsPlayer(player));
this(new Variator(),
new LocomotionLookup(engine.getConfig()),
new HeuristicStateLookup(),
new GolemLookup(),
new StateLookup(),
new PrimitiveLookup(),
new AcousticsPlayer(new DelayedSoundPlayer(engine.soundPlayer))
);
}

public boolean load(ResourceManager manager) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/eu/ha3/presencefootsteps/sound/SoundEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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;
import eu.ha3.presencefootsteps.world.PFSolver;
Expand Down Expand Up @@ -43,7 +44,8 @@ public class SoundEngine implements IdentifiableResourceReloadListener {
private static final Identifier ID = new Identifier("presencefootsteps", "sounds");

private Isolator isolator = new Isolator(this);
private Solver solver = new PFSolver(this);
private final Solver solver = new PFSolver(this);
final ImmediateSoundPlayer soundPlayer = new ImmediateSoundPlayer(this);

private final PFConfig config;

Expand Down Expand Up @@ -162,7 +164,7 @@ public void onFrame(MinecraftClient client, Entity cameraEntity) {
}
});

isolator.soundPlayer().think(); // Delayed sounds
isolator.acoustics().think(); // Delayed sounds
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import eu.ha3.presencefootsteps.sound.Options;
import eu.ha3.presencefootsteps.sound.State;
import eu.ha3.presencefootsteps.world.Association;
import eu.ha3.presencefootsteps.world.SoundsKey;
import net.minecraft.entity.LivingEntity;

Expand All @@ -11,5 +12,9 @@ public interface AcousticLibrary {
*/
void addAcoustic(String name, Acoustic acoustic);

void playStep(Association assos, State eventType, Options options);

void playAcoustic(LivingEntity location, SoundsKey acousticName, State event, Options options);

void think();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
import eu.ha3.presencefootsteps.sound.State;
import eu.ha3.presencefootsteps.sound.player.SoundPlayer;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import eu.ha3.presencefootsteps.world.Association;
import eu.ha3.presencefootsteps.world.SoundsKey;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity;
import net.minecraft.sound.BlockSoundGroup;

import java.util.Map;

public class AcousticsPlayer implements AcousticLibrary {
private final Map<String, Acoustic> acoustics = new Object2ObjectOpenHashMap<>();

private final SoundPlayer player;
private final SoundPlayer soundPlayer;

public AcousticsPlayer(SoundPlayer player) {
this.player = player;
public AcousticsPlayer(SoundPlayer soundPlayer) {
this.soundPlayer = soundPlayer;
}

@Override
Expand All @@ -26,15 +30,54 @@ public void addAcoustic(String name, Acoustic acoustic) {
}
}

@SuppressWarnings("deprecation")
@Override
public void playStep(Association association, State event, Options options) {
if (association.isSilent()) {
return;
}

if (association.dry().isResult()) {
playAcoustic(association.source(), association.dry(), event, options);
} else if (!association.state().isLiquid()) {
BlockSoundGroup soundType = association.state().getSoundGroup();
BlockState above = association.source().getWorld().getBlockState(association.pos().up());

if (above.isOf(Blocks.SNOW)) {
soundType = above.getSoundGroup();
}

soundPlayer.playSound(association.source(),
soundType.getStepSound().getId().toString(),
soundType.getVolume() * 0.15F,
soundType.getPitch(),
options
);
}

if (association.wet().isEmitter() && Options.WET_VOLUME_OPTIONS.get("volume_percentage") > 0.1F) {
playAcoustic(association.source(), association.wet(), event, options.and(Options.WET_VOLUME_OPTIONS));
}

if (association.foliage().isEmitter() && Options.FOLIAGE_VOLUME_OPTIONS.get("volume_percentage") > 0.1F) {
playAcoustic(association.source(), association.foliage(), event, options.and(Options.FOLIAGE_VOLUME_OPTIONS));
}
}

@Override
public void playAcoustic(LivingEntity location, SoundsKey sounds, State event, Options inputOptions) {
for (String acousticName : sounds.names()) {
Acoustic acoustic = acoustics.get(acousticName);
if (acoustic == null) {
PresenceFootsteps.logger.warn("Tried to play a missing acoustic: " + acousticName);
} else {
acoustic.playSound(player, location, event, inputOptions);
acoustic.playSound(soundPlayer, location, event, inputOptions);
}
}
}

@Override
public void think() {
soundPlayer.think();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ record ChanceAcoustic(

@Override
public void playSound(SoundPlayer player, LivingEntity location, State event, Options inputOptions) {
final float rand = player.getRNG().nextFloat();
if (rand * 100 <= probability) {
if (player.getRNG().nextFloat() * 100 <= probability) {
acoustic.playSound(player, location, event, inputOptions);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,19 @@ private void simulateBrushes() {
}

protected void playStep(Association association, State eventType) {

if (engine.getConfig().getEnabledFootwear()) {
if (entity.getEquippedStack(EquipmentSlot.FEET).getItem() instanceof ArmorItem bootItem) {
SoundsKey bootSound = engine.getIsolator().primitives().getAssociation(bootItem.getEquipSound(), Substrates.DEFAULT);
if (bootSound.isEmitter()) {
engine.getIsolator().stepPlayer().playStep(association, eventType, Options.singular("volume_percentage", 0.5F));
engine.getIsolator().acoustics().playStep(association, eventType, Options.singular("volume_percentage", 0.5F));
engine.getIsolator().acoustics().playAcoustic(entity, bootSound, eventType, Options.EMPTY);

return;
}
}
}

engine.getIsolator().stepPlayer().playStep(association, eventType, Options.EMPTY);
engine.getIsolator().acoustics().playStep(association, eventType, Options.EMPTY);
}

protected void playSinglefoot(double verticalOffsetAsMinus, State eventType, boolean foot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.entity.LivingEntity;

class DelayedSoundPlayer implements SoundPlayer {
public class DelayedSoundPlayer implements SoundPlayer {
private static final boolean USING_LATENESS = true;
private static final boolean USING_EARLYNESS = true;

Expand All @@ -35,10 +35,13 @@ public Random getRNG() {

@Override
public void playSound(LivingEntity location, String soundName, float volume, float pitch, Options options) {
if (!options.containsKey("delay_min") || !options.containsKey("delay_max")) {
immediate.playSound(location, soundName, volume, pitch, options);
return;
}
pending.add(new PendingSound(location, soundName, volume, pitch, options));
}

@Override
public void think() {
currentTime = System.currentTimeMillis();

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ private boolean getForState(BlockState state, String substrate) {

private boolean getForPrimitive(BlockState state) {
BlockSoundGroup sounds = state.getSoundGroup();
return (association = engine.getIsolator().primitives().getAssociation(sounds, PrimitiveLookup.getSubstrate(sounds))).isResult();
return (association = engine.getIsolator().primitives().getAssociation(sounds.getStepSound(), PrimitiveLookup.getSubstrate(sounds))).isResult();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.ha3.presencefootsteps.world;

import eu.ha3.presencefootsteps.PFConfig;
import eu.ha3.presencefootsteps.PresenceFootsteps;
import eu.ha3.presencefootsteps.sound.SoundEngine;
import eu.ha3.presencefootsteps.sound.generator.Locomotion;
import eu.ha3.presencefootsteps.util.JsonObjectWriter;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
Expand All @@ -20,16 +20,16 @@
public class LocomotionLookup implements Index<Entity, Locomotion> {
private final Map<Identifier, Locomotion> values = new Object2ObjectLinkedOpenHashMap<>();

private final SoundEngine engine;
private final PFConfig config;

public LocomotionLookup(SoundEngine engine) {
this.engine = engine;
public LocomotionLookup(PFConfig config) {
this.config = config;
}

@Override
public Locomotion lookup(Entity key) {
if (key instanceof PlayerEntity) {
return Locomotion.forPlayer((PlayerEntity)key, engine.getConfig().getLocomotion());
if (key instanceof PlayerEntity player) {
return Locomotion.forPlayer(player, config.getLocomotion());
}
return Locomotion.forLiving(key, values.getOrDefault(EntityType.getId(key.getType()), Locomotion.BIPED));
}
Expand Down
Loading

0 comments on commit f89dfa2

Please sign in to comment.