Skip to content

Commit

Permalink
the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Nov 12, 2024
1 parent 2255eb8 commit 1b64a71
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class LevitaMovingMinecartSoundInstance extends MovingSoundInstance {
private final AbstractMinecartEntity minecart;
private float distance = 0.0F;

public LevitaMovingMinecartSoundInstance(AbstractMinecartEntity minecart) {
super(ParadiseLostSoundEvents.ENTITY_MINECART_ROLLING_LEVITATING, SoundCategory.NEUTRAL, SoundInstance.createRandom());
public LevitaMovingMinecartSoundInstance(AbstractMinecartEntity minecart, boolean inside) {
super(inside ? ParadiseLostSoundEvents.ENTITY_MINECART_INSIDE_LEVITATING : ParadiseLostSoundEvents.ENTITY_MINECART_ROLLING_LEVITATING, SoundCategory.NEUTRAL, SoundInstance.createRandom());
this.minecart = minecart;
this.repeat = true;
this.repeatDelay = 0;
Expand Down Expand Up @@ -43,7 +43,7 @@ public void tick() {
this.z = this.minecart.getZ();
float f = (float) this.minecart.getVelocity().horizontalLength();
var floatingComponent = ParadiseLostComponents.FLOATING_KEY.get(minecart);
if (f >= 0.01F && this.minecart.getWorld().getTickManager().shouldTick() && floatingComponent.getFloating()) {
if (f >= 0.01F && this.minecart.getWorld().getTickManager().shouldTick() && floatingComponent.getFloating() && !floatingComponent.isCartOnRail(this.minecart)) {
this.distance = MathHelper.clamp(this.distance + 0.0025F, 0.0F, 1.0F);
this.volume = MathHelper.lerp(MathHelper.clamp(f, 0.0F, 0.5F), 0.0F, 0.7F);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ClientPlayNetworkHandlerMixin(MinecraftClient client, ClientConnection co
@Inject(method = "playSpawnSound", at = @At("HEAD"))
private void playSpawnSound(Entity entity, CallbackInfo ci) {
if (entity instanceof AbstractMinecartEntity abstractMinecartEntity) {
this.client.getSoundManager().play(new LevitaMovingMinecartSoundInstance(abstractMinecartEntity));
this.client.getSoundManager().play(new LevitaMovingMinecartSoundInstance(abstractMinecartEntity, false));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.id.paradiselost.mixin.client.sound;

import net.id.paradiselost.component.ParadiseLostComponents;
import net.minecraft.client.sound.MinecartInsideSoundInstance;
import net.minecraft.client.sound.MovingSoundInstance;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.random.Random;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(MinecartInsideSoundInstance.class)
public abstract class MinecartInsideSoundInstanceMixin extends MovingSoundInstance {

@Shadow
@Final
private AbstractMinecartEntity minecart;

protected MinecartInsideSoundInstanceMixin(SoundEvent soundEvent, SoundCategory soundCategory, Random random) {
super(soundEvent, soundCategory, random);
}

@Inject(method = "tick", at = @At("TAIL"))
public void tick(CallbackInfo ci) {
if (!this.minecart.isRemoved()) {
var floatingComponent = ParadiseLostComponents.FLOATING_KEY.get(this.minecart);
if (floatingComponent.getFloating() && !floatingComponent.isCartOnRail(this.minecart)) {
this.volume = 0.0F;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected MovingMinecartSoundInstanceMixin(SoundEvent soundEvent, SoundCategory
public void tick(CallbackInfo ci) {
if (!this.minecart.isRemoved()) {
var floatingComponent = ParadiseLostComponents.FLOATING_KEY.get(this.minecart);
if (floatingComponent.getFloating()) {
if (floatingComponent.getFloating() && !floatingComponent.isCartOnRail(this.minecart)) {
this.volume = 0.0F;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/paradise_lost.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"client.render.NativeImageAccessor",
"client.render.PlayerHeldItemFeatureRendererMixin",
"client.render.WorldRendererMixin",
"client.sound.MinecartInsideSoundInstanceMixin",
"client.sound.MovingMinecartSoundInstanceMixin",
"devel.client.HandledScreenMixin"
],
Expand Down

0 comments on commit 1b64a71

Please sign in to comment.