From 2543185a55a60197494850582ca45d729e463f40 Mon Sep 17 00:00:00 2001 From: Rabbitminers Date: Mon, 3 Apr 2023 09:45:23 +0100 Subject: [PATCH] Added Bogey Sound Customisation --- .../logistics/trains/entity/BogeyStyle.java | 3 ++- .../logistics/trains/entity/CarriageSounds.java | 14 ++++++++++++-- .../create/foundation/data/BogeyStyleBuilder.java | 8 ++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java index 6bdc81a8e..bd75ec0d9 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/BogeyStyle.java @@ -8,6 +8,7 @@ import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; import net.minecraftforge.registries.ForgeRegistries; @@ -23,7 +24,7 @@ import java.util.stream.Stream; public final class BogeyStyle extends ForgeRegistryEntry implements IForgeRegistryEntry { public Map blocks = new EnumMap<>(BogeySize.class); public Component displayName; - public SoundType soundType; + public SoundEvent soundType; public CompoundTag defaultData; public BogeyRenderer renderer; diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageSounds.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageSounds.java index 6d109d1ad..097ffe5bf 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageSounds.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageSounds.java @@ -3,6 +3,8 @@ package com.simibubi.create.content.logistics.trains.entity; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllSoundEvents.SoundEntry; import com.simibubi.create.content.logistics.trains.entity.Carriage.DimensionalCarriageEntity; +import com.simibubi.create.foundation.utility.Couple; +import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; @@ -29,6 +31,8 @@ public class CarriageSounds { LoopingSound sharedWheelSoundSeated; LoopingSound sharedHonkSound; + SoundEvent closestBogeySound; + boolean arrived; int tick; @@ -79,6 +83,12 @@ public class CarriageSounds { double distance1 = toBogey1.length(); double distance2 = toBogey2.length(); + CarriageContraptionEntity cce = dce.entity.get(); + if (cce != null) { + Couple bogeys = cce.getCarriage().bogeys; + closestBogeySound = bogeys.get(distance1 > distance2).getStyle().soundType; + } + Vec3 toCarriage = distance1 > distance2 ? toBogey2 : toBogey1; double distance = Math.min(distance1, distance2); Vec3 soundLocation = cam.add(toCarriage); @@ -97,7 +107,7 @@ public class CarriageSounds { seatCrossfade.tickChaser(); minecartEsqueSound = playIfMissing(mc, minecartEsqueSound, AllSoundEvents.TRAIN.getMainEvent()); - sharedWheelSound = playIfMissing(mc, sharedWheelSound, AllSoundEvents.TRAIN2.getMainEvent()); + sharedWheelSound = playIfMissing(mc, sharedWheelSound, closestBogeySound); sharedWheelSoundSeated = playIfMissing(mc, sharedWheelSoundSeated, AllSoundEvents.TRAIN3.getMainEvent()); float volume = Math.min(Math.min(speedFactor.getValue(), distanceFactor.getValue() / 100), @@ -205,7 +215,7 @@ public class CarriageSounds { public void submitSharedSoundVolume(Vec3 location, float volume) { Minecraft mc = Minecraft.getInstance(); minecartEsqueSound = playIfMissing(mc, minecartEsqueSound, AllSoundEvents.TRAIN.getMainEvent()); - sharedWheelSound = playIfMissing(mc, sharedWheelSound, AllSoundEvents.TRAIN2.getMainEvent()); + sharedWheelSound = playIfMissing(mc, sharedWheelSound, closestBogeySound); sharedWheelSoundSeated = playIfMissing(mc, sharedWheelSoundSeated, AllSoundEvents.TRAIN3.getMainEvent()); boolean approach = true; diff --git a/src/main/java/com/simibubi/create/foundation/data/BogeyStyleBuilder.java b/src/main/java/com/simibubi/create/foundation/data/BogeyStyleBuilder.java index 61116c4d2..253b8fa89 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BogeyStyleBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/data/BogeyStyleBuilder.java @@ -23,6 +23,7 @@ import net.minecraft.core.particles.ParticleType; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; import net.minecraft.world.level.block.SoundType; import org.jetbrains.annotations.NotNull; @@ -35,7 +36,7 @@ import java.util.function.Supplier; public class BogeyStyleBuilder extends AbstractBuilder> { private final T style; private NonNullSupplier renderer; - private Supplier soundType; + private Supplier soundType; private Supplier data; private Supplier> particles; @@ -46,6 +47,7 @@ public class BogeyStyleBuilder extends AbstractBuilder< protected BogeyStyleBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, T style) { super(owner, parent, name, callback, AllRegistries.Keys.BOGEYS); this.style = style; + this.soundType = AllSoundEvents.TRAIN2::getMainEvent; this.particles = AllParticleTypes.AIR_FLOW::get; this.data = CompoundTag::new; } @@ -60,7 +62,8 @@ public class BogeyStyleBuilder extends AbstractBuilder< return this; } - public BogeyStyleBuilder soundType(SoundType soundEntry) { + public BogeyStyleBuilder soundType(SoundEvent soundEntry) { + this.soundType = () -> soundEntry; return this; } @@ -82,6 +85,7 @@ public class BogeyStyleBuilder extends AbstractBuilder< protected @NotNull T createEntry() { style.defaultData = data.get(); style.renderer = renderer.get(); + style.soundType = soundType.get(); return style; } }