Skip to content

Commit

Permalink
close #4542
Browse files Browse the repository at this point in the history
  • Loading branch information
yrsegal committed Dec 28, 2023
1 parent 2c2b249 commit e3ae22f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.item.Item;

import net.minecraft.world.phys.AABB;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZConfigChanged;
import org.violetmoon.zeta.module.ZetaLoadModule;
Expand All @@ -26,7 +26,12 @@ public final void configChanged(ZConfigChanged event) {
}

public static boolean canPlay(AbstractMinecart cart) {
return !staticEnabled || !cart.level().getBlockState(cart.blockPosition().below()).is(BlockTags.DAMPENS_VIBRATIONS);
if (!staticEnabled)
return true;

AABB bounds = cart.getBoundingBox();
bounds = bounds.move(0, bounds.minY - bounds.maxY, 0);
return cart.level().getBlockStates(bounds).noneMatch((it) -> it.is(BlockTags.DAMPENS_VIBRATIONS));
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package org.violetmoon.quark.mixin.mixins.client;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.resources.sounds.MinecartSoundInstance;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.violetmoon.quark.content.client.module.WoolShutsUpMinecartsModule;

@Mixin(MinecartSoundInstance.class)
public class MinecartSoundInstanceMixin {

@Shadow
@Final
private AbstractMinecart minecart;

@ModifyExpressionValue(method = "tick()V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/resources/sounds/MinecartSoundInstance;volume:F", opcode = Opcodes.PUTFIELD))
public float muteIfOnWool(float volumeToSet) {
if (volumeToSet > 0 && !WoolShutsUpMinecartsModule.canPlay(minecart))
return 0;
return volumeToSet;
@WrapOperation(method = "tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;getDeltaMovement()Lnet/minecraft/world/phys/Vec3;"))
public Vec3 pretendThereIsNoMovementIfMuted(AbstractMinecart minecart, Operation<Vec3> original) {
if (!WoolShutsUpMinecartsModule.canPlay(minecart))
return Vec3.ZERO;
return original.call(minecart);
}

}

0 comments on commit e3ae22f

Please sign in to comment.