Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Mar 9, 2024
2 parents 5b64ab2 + 2ec37b4 commit 1980bb5
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 175 deletions.
10 changes: 5 additions & 5 deletions src/main/java/eu/ha3/presencefootsteps/PFDebugHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import eu.ha3.presencefootsteps.api.DerivedBlock;
import eu.ha3.presencefootsteps.sound.SoundEngine;
import eu.ha3.presencefootsteps.sound.generator.Locomotion;
import eu.ha3.presencefootsteps.world.Emitter;
import eu.ha3.presencefootsteps.world.PrimitiveLookup;
import eu.ha3.presencefootsteps.world.SoundsKey;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -109,7 +109,7 @@ private static void insertAt(List<String> values, List<String> destination, Stri
values.clear();
}

private void renderSoundList(String title, Map<String, String> sounds, List<String> list) {
private void renderSoundList(String title, Map<String, SoundsKey> sounds, List<String> list) {
if (sounds.isEmpty()) {
return;
}
Expand All @@ -124,7 +124,7 @@ private void renderSoundList(String title, Map<String, String> sounds, List<Stri
if (!entry.getKey().isEmpty()) {
combinedList.append(entry.getKey()).append(":");
}
combinedList.append(entry.getValue());
combinedList.append(entry.getValue().raw());
}
combinedList.append(" ]");
list.add(combinedList.toString());
Expand All @@ -134,10 +134,10 @@ private void renderSoundList(String title, Map<String, String> sounds, List<Stri
}

if (sounds.isEmpty()) {
list.add(Emitter.UNASSIGNED);
list.add(SoundsKey.UNASSIGNED.raw());
} else {
sounds.forEach((key, value) -> {
list.add((key.isEmpty() ? "default" : key) + ": " + value);
list.add((key.isEmpty() ? "default" : key) + ": " + value.raw());
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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;

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

/**
* Plays an acoustic with additional options.
*/
default void playAcoustic(Association association, State event, Options options) {
playAcoustic(association.source(), association.acousticNames(), event, options);
if (Options.WET_VOLUME_OPTIONS.get("volume_percentage") > 0.1F) {
playAcoustic(association.source(), association.wetAcousticNames(), event, options.and(Options.WET_VOLUME_OPTIONS));
}
if (Options.FOLIAGE_VOLUME_OPTIONS.get("volume_percentage") > 0.1F) {
playAcoustic(association.source(), association.foliageAcousticNames(), event, options.and(Options.FOLIAGE_VOLUME_OPTIONS));
}
}

void playAcoustic(LivingEntity location, String acousticName, State event, Options options);
void playAcoustic(LivingEntity location, SoundsKey acousticName, State event, Options options);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package eu.ha3.presencefootsteps.sound.acoustics;

import com.google.common.base.Strings;
import eu.ha3.presencefootsteps.PresenceFootsteps;
import eu.ha3.presencefootsteps.sound.Options;
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.Emitter;
import eu.ha3.presencefootsteps.world.SoundsKey;
import net.minecraft.entity.LivingEntity;

import java.util.Map;
import java.util.stream.Stream;

public class AcousticsPlayer implements AcousticLibrary {
private final Map<String, Acoustic> acoustics = new Object2ObjectOpenHashMap<>();
Expand All @@ -23,25 +21,20 @@ public AcousticsPlayer(SoundPlayer player) {

@Override
public void addAcoustic(String name, Acoustic acoustic) {
acoustics.put(name, acoustic);
if (acoustics.put(name, acoustic) != null) {
PresenceFootsteps.logger.info("Duplicate acoustic: " + name);
}
}

@Override
public void playAcoustic(LivingEntity location, String acousticName, State event, Options inputOptions) {
if (!Emitter.isEmitter(acousticName)) {
return;
}

if (acousticName.contains(",")) {
Stream.of(acousticName.split(","))
.map(Strings::nullToEmpty)
.filter(s -> !s.isEmpty())
.distinct()
.forEach(fragment -> playAcoustic(location, fragment, event, inputOptions));
} else if (!acoustics.containsKey(acousticName)) {
PresenceFootsteps.logger.warn("Tried to play a missing acoustic: " + acousticName);
} else {
acoustics.get(acousticName).playSound(player, location, event, inputOptions);
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import eu.ha3.presencefootsteps.sound.SoundEngine;
import eu.ha3.presencefootsteps.world.Association;
import eu.ha3.presencefootsteps.world.AssociationPool;
import eu.ha3.presencefootsteps.world.Emitter;
import eu.ha3.presencefootsteps.world.Solver;
import eu.ha3.presencefootsteps.world.SoundsKey;
import eu.ha3.presencefootsteps.world.Substrates;

class TerrestrialStepSoundGenerator implements StepSoundGenerator {
Expand Down Expand Up @@ -80,7 +80,7 @@ protected void simulateStationary() {
if (isImmobile && (entity.isOnGround() || !entity.isSubmergedInWater()) && playbackImmobile()) {
Association assos = associations.findAssociation(0d, isRightFoot);

if (assos.hasAssociation() || !isImmobile) {
if (!assos.isSilent() || !isImmobile) {
playStep(assos, State.STAND);
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public final void produceStep(@Nullable State event, double verticalOffsetAsMinu
Options options = Options.singular("gliding_volume", volume);
State state = entity.isSubmergedInWater() ? State.SWIM : event;

engine.getIsolator().acoustics().playAcoustic(entity, "_SWIM", state, options);
engine.getIsolator().acoustics().playAcoustic(entity, SoundsKey.SWIM, state, options);

playStep(associations.findAssociation(entity.getBlockPos().down(), Solver.MESSY_FOLIAGE_STRATEGY), event);
} else {
Expand Down Expand Up @@ -313,7 +313,7 @@ private void simulateBrushes() {
entity.getZ()
), Solver.MESSY_FOLIAGE_STRATEGY);

if (!assos.isNull()) {
if (!assos.isSilent()) {
if (!isMessyFoliage) {
isMessyFoliage = true;
playStep(assos, State.WALK);
Expand All @@ -327,8 +327,8 @@ protected void playStep(Association association, State eventType) {

if (engine.getConfig().getEnabledFootwear()) {
if (entity.getEquippedStack(EquipmentSlot.FEET).getItem() instanceof ArmorItem bootItem) {
String bootSound = engine.getIsolator().primitives().getAssociation(bootItem.getEquipSound(), Substrates.DEFAULT);
if (Emitter.isEmitter(bootSound)) {
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().playAcoustic(entity, bootSound, eventType, Options.EMPTY);

Expand All @@ -343,7 +343,7 @@ protected void playStep(Association association, State eventType) {
protected void playSinglefoot(double verticalOffsetAsMinus, State eventType, boolean foot) {
Association assos = associations.findAssociation(verticalOffsetAsMinus, isRightFoot);

if (assos.isNotEmitter()) {
if (!assos.isResult()) {
assos = associations.findAssociation(verticalOffsetAsMinus + 1, isRightFoot);
}

Expand All @@ -355,7 +355,7 @@ protected void playMultifoot(double verticalOffsetAsMinus, State eventType) {
Association leftFoot = associations.findAssociation(verticalOffsetAsMinus, false);
Association rightFoot = associations.findAssociation(verticalOffsetAsMinus, true);

if (leftFoot.dataEquals(rightFoot)) {
if (leftFoot.isResult() && leftFoot.dataEquals(rightFoot)) {
// If the two feet solve to the same sound, except NO_ASSOCIATION, only play the sound once
if (isRightFoot) {
leftFoot = Association.NOT_EMITTER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import eu.ha3.presencefootsteps.sound.State;
import eu.ha3.presencefootsteps.util.MathUtil;
import eu.ha3.presencefootsteps.world.SoundsKey;
import eu.ha3.presencefootsteps.config.Variator;
import eu.ha3.presencefootsteps.sound.Options;
import eu.ha3.presencefootsteps.sound.SoundEngine;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.Vec3d;

class WingedStepSoundGenerator extends TerrestrialStepSoundGenerator {

private static final SoundsKey SWIFT = SoundsKey.of("_SWIFT");
private static final SoundsKey WING = SoundsKey.of("_WING");
protected boolean isFalling = false;

protected FlightState state = FlightState.IDLE;
Expand Down Expand Up @@ -93,9 +95,9 @@ protected void simulateJumpingLanding() {
if (!isAirborne) {
float volume = speedingJumpStateChange ? 2
: MathUtil.scalex(lastFallDistance, variator.HUGEFALL_LANDING_DISTANCE_MIN, variator.HUGEFALL_LANDING_DISTANCE_MAX);
engine.getIsolator().acoustics().playAcoustic(entity, "_SWIFT", State.LAND, Options.singular("gliding_volume", volume));
engine.getIsolator().acoustics().playAcoustic(entity, SWIFT, State.LAND, Options.singular("gliding_volume", volume));
} else {
engine.getIsolator().acoustics().playAcoustic(entity, "_SWIFT", State.JUMP, Options.EMPTY);
engine.getIsolator().acoustics().playAcoustic(entity, SWIFT, State.JUMP, Options.EMPTY);
}
}

Expand Down Expand Up @@ -127,7 +129,7 @@ protected void simulateFlying() {
variator.WING_IMMOBILE_FADE_START + variator.WING_IMMOBILE_FADE_DURATION);
}

engine.getIsolator().acoustics().playAcoustic(entity, "_WING", State.WALK, Options.singular("gliding_volume", volume));
engine.getIsolator().acoustics().playAcoustic(entity, WING, State.WALK, Options.singular("gliding_volume", volume));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import eu.ha3.presencefootsteps.sound.Options;
import eu.ha3.presencefootsteps.sound.SoundEngine;
import eu.ha3.presencefootsteps.sound.State;
import eu.ha3.presencefootsteps.sound.acoustics.AcousticLibrary;
import eu.ha3.presencefootsteps.world.Association;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -35,22 +36,37 @@ public Random getRNG() {

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

if (assos.hasAssociation()) {
engine.getIsolator().acoustics().playAcoustic(assos, eventType, options);
} else if (!assos.state().isLiquid()) {
BlockSoundGroup soundType = assos.soundGroup();
BlockState above = assos.source().getWorld().getBlockState(assos.pos().up());
AcousticLibrary library = engine.getIsolator().acoustics();

if (association.dry().isResult()) {
library.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();
}

immediatePlayer.playSound(assos.source(), soundType.getStepSound().getId().toString(), soundType.getVolume() * 0.15F, soundType.getPitch(), options);
immediatePlayer.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) {
library.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) {
library.playAcoustic(association.source(), association.foliage(), event, options.and(Options.FOLIAGE_VOLUME_OPTIONS));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import net.minecraft.util.Identifier;

abstract class AbstractSubstrateLookup<T> implements Lookup<T> {
private final Map<String, Map<Identifier, String>> substrates = new Object2ObjectLinkedOpenHashMap<>();
private final Map<String, Map<Identifier, SoundsKey>> substrates = new Object2ObjectLinkedOpenHashMap<>();

protected abstract Identifier getId(T key);

@Override
public String getAssociation(T key, String substrate) {
public SoundsKey getAssociation(T key, String substrate) {
final Identifier id = getId(key);
return getSubstrateMap(id, substrate).getOrDefault(id, Emitter.UNASSIGNED);
return getSubstrateMap(id, substrate).getOrDefault(id, SoundsKey.UNASSIGNED);
}

@Nullable
protected Map<Identifier, String> getSubstrateMap(Identifier id, String substrate) {
Map<Identifier, String> primitives = substrates.get(substrate);
protected Map<Identifier, SoundsKey> getSubstrateMap(Identifier id, String substrate) {
Map<Identifier, SoundsKey> primitives = substrates.get(substrate);
if (primitives != null) {
return primitives;
}
Expand Down Expand Up @@ -50,7 +50,7 @@ public void add(String key, String value) {

substrates
.computeIfAbsent(substrate, s -> new Object2ObjectLinkedOpenHashMap<>())
.put(new Identifier(primitive), value);
.put(new Identifier(primitive), SoundsKey.of(value));
}

@Override
Expand Down
43 changes: 16 additions & 27 deletions src/main/java/eu/ha3/presencefootsteps/world/Association.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,40 @@

import java.util.Objects;

import org.jetbrains.annotations.Nullable;

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.BlockPos;

public record Association (
BlockState state,
BlockPos pos,
LivingEntity source,
@Nullable LivingEntity source,

String acousticNames,
String wetAcousticNames,
String foliageAcousticNames
SoundsKey dry,
SoundsKey wet,
SoundsKey foliage
) {
public static final Association NOT_EMITTER = new Association(Blocks.AIR.getDefaultState(), BlockPos.ORIGIN, null, Emitter.NOT_EMITTER, Emitter.NOT_EMITTER, Emitter.NOT_EMITTER);
public static final Association NOT_EMITTER = new Association(Blocks.AIR.getDefaultState(), BlockPos.ORIGIN, null, SoundsKey.NON_EMITTER, SoundsKey.NON_EMITTER, SoundsKey.NON_EMITTER);

public static Association of(BlockState state, BlockPos pos, LivingEntity source, String dry, String wet, String foliage) {
if (Emitter.isResult(dry) || Emitter.isResult(wet) || Emitter.isResult(foliage)) {
return new Association(state, pos.toImmutable(), source, dry, wet, foliage);
public static Association of(BlockState state, BlockPos pos, LivingEntity source, SoundsKey dry, SoundsKey wet, SoundsKey foliage) {
if (dry.isSilent() && wet.isSilent() && foliage.isSilent()) {
return NOT_EMITTER;
}
return NOT_EMITTER;
}

public boolean isNull() {
return this == NOT_EMITTER;
return new Association(state, pos.toImmutable(), source, dry, wet, foliage);
}

public boolean isNotEmitter() {
return isNull() || (
Emitter.isNonEmitter(acousticNames)
&& Emitter.isNonEmitter(wetAcousticNames)
&& Emitter.isNonEmitter(foliageAcousticNames)
);
public boolean isResult() {
return dry.isResult() || wet.isResult() || foliage.isResult();
}

public boolean hasAssociation() {
return !isNotEmitter();
}

public BlockSoundGroup soundGroup() {
return state.getSoundGroup();
public boolean isSilent() {
return this == NOT_EMITTER;
}

public boolean dataEquals(Association other) {
return hasAssociation() && Objects.equals(acousticNames, other.acousticNames);
return Objects.equals(dry, other.dry);
}
}
Loading

0 comments on commit 1980bb5

Please sign in to comment.