44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
|
package xyz.pixelatedw.betterbeta.mixin;
|
||
|
|
||
|
import org.spongepowered.asm.mixin.Mixin;
|
||
|
import org.spongepowered.asm.mixin.injection.At;
|
||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||
|
|
||
|
import net.minecraft.entity.Minecart;
|
||
|
import net.minecraft.tile.RailTile;
|
||
|
import net.minecraft.util.maths.MathsHelper;
|
||
|
import xyz.pixelatedw.betterbeta.WyHelper;
|
||
|
|
||
|
@Mixin(Minecart.class)
|
||
|
public class MinecartMixin {
|
||
|
|
||
|
@Inject(method = "tick", at = @At("TAIL"))
|
||
|
public void tick(CallbackInfo ci) {
|
||
|
Minecart minecart = (Minecart) (Object) this;
|
||
|
int x = MathsHelper.floor(minecart.x);
|
||
|
int y = MathsHelper.floor(minecart.y);
|
||
|
int z = MathsHelper.floor(minecart.z);
|
||
|
int tileId = minecart.level.getTileId(x, y, z);
|
||
|
if (RailTile.method_1107(tileId)) {
|
||
|
float speed = MathsHelper.sqrt(minecart.velocityX * minecart.velocityX + minecart.velocityZ * minecart.velocityZ);
|
||
|
float volume = 0;
|
||
|
float pitch = 0;
|
||
|
if (speed >= 0.01D) {
|
||
|
++minecart.field_1645;
|
||
|
pitch = WyHelper.clamp(pitch + 0.0025F, 0.0F, 1.0F);
|
||
|
volume = WyHelper.lerp(WyHelper.clamp(speed, 0.0F, 0.5F), 0.0F, 0.7F);
|
||
|
} else {
|
||
|
volume = 0.0f;
|
||
|
pitch = 0.0f;
|
||
|
}
|
||
|
|
||
|
if (speed >= 0.01D) {
|
||
|
if (minecart.field_1645 % 25 == 1) {
|
||
|
minecart.level.playSound(x, y, z, "minecart.base", volume, pitch);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|