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
# Conflicts:
#	src/main/java/eu/ha3/presencefootsteps/sound/generator/TerrestrialStepSoundGenerator.java
  • Loading branch information
Sollace committed May 15, 2024
2 parents 97b2d06 + b87cbc6 commit 3dd493f
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 110 deletions.
16 changes: 16 additions & 0 deletions src/main/java/eu/ha3/presencefootsteps/PFConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class PFConfig extends JsonFile {
private boolean multiplayer = true;
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;
Expand Down Expand Up @@ -65,6 +67,10 @@ public Locomotion setLocomotion(Locomotion loco) {
return loco;
}

public boolean isVisualiserRunning() {
return visualiser;
}

public boolean isFirstRun() {
return firstRun;
}
Expand Down Expand Up @@ -92,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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/eu/ha3/presencefootsteps/PFOptionsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand Down
30 changes: 3 additions & 27 deletions src/main/java/eu/ha3/presencefootsteps/sound/SoundEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,34 +168,11 @@ public void onFrame(MinecraftClient client, Entity cameraEntity) {
}

public boolean onSoundRecieved(@Nullable RegistryEntry<SoundEvent> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<StepSoundGenerator> getStepGenerator(SoundEngine engine);
Expand Down Expand Up @@ -35,7 +36,11 @@ public Optional<StepSoundGenerator> getStepGenerator(SoundEngine engine) {

@Override
public boolean isStepBlocked() {
return PresenceFootsteps.getInstance().getEngine().isEnabledFor(entity);
SoundEngine engine = PresenceFootsteps.getInstance().getEngine();
if (!engine.getConfig().isExclusiveMode() && !(entity instanceof PlayerEntity)) {
return false;
}
return engine.isEnabledFor(entity) && getStepGenerator(engine).isPresent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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() {
Expand Down Expand Up @@ -310,7 +313,7 @@ private void simulateBrushes() {

Association assos = associations.findAssociation(BlockPos.ofFloored(
entity.getX(),
entity.getY() - 0.1D - (entity.hasVehicle() ? entity.getRidingOffset(entity.getVehicle()) : 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.UNASSIGNED;
}

if (getForState(state, substrate)
|| (!baseState.isAir() && (
getForState(baseState, substrate)
|| (!Substrates.isDefault(substrate) && getForState(baseState, Substrates.DEFAULT))
|| (getForPrimitive(baseState, substrate))
))
|| getForPrimitive(state, substrate)
)) {
) {
return association;
}

Expand Down
135 changes: 80 additions & 55 deletions src/main/java/eu/ha3/presencefootsteps/world/PFSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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;
Expand Down Expand Up @@ -71,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);

Expand Down Expand Up @@ -140,62 +142,81 @@ 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;

// 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 (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()) {
return association;
if (!association.state().isLiquid()) {
if (engine.getConfig().isVisualiserRunning()) {
player.getWorld().addParticle(ParticleTypes.CLOUD,
association.pos().getX() + 0.5,
association.pos().getY() + 0.9,
association.pos().getZ() + 0.5, 0, 0, 0);
}
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;
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 (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 (!association.state().isLiquid()) {
if (engine.getConfig().isVisualiserRunning()) {
player.getWorld().addParticle(ParticleTypes.CLOUD,
association.pos().getX() + 0.5,
association.pos().getY() + 0.9,
association.pos().getZ() + 0.5, 0, 0, 0);
}
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;
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);
}

// 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) {
Expand All @@ -212,23 +233,27 @@ 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
if (target.isAir()) {
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);
}
}
}

Expand All @@ -251,7 +276,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
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/eu/ha3/presencefootsteps/world/SoundsKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Loading

0 comments on commit 3dd493f

Please sign in to comment.