Fixed Bogey Sound Loading

This commit is contained in:
Rabbitminers 2023-04-03 17:20:17 +01:00
parent 2543185a55
commit 129be61fee
3 changed files with 15 additions and 5 deletions

View file

@ -1,6 +1,7 @@
package com.simibubi.create.content.logistics.trains.entity;
import com.jozufozu.flywheel.api.MaterialManager;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.content.logistics.trains.BogeyRenderer;
import com.simibubi.create.content.logistics.trains.BogeyRenderer.BogeySize;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
@ -15,6 +16,8 @@ import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistryEntry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import org.jetbrains.annotations.NotNull;
import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
@ -24,7 +27,7 @@ import java.util.stream.Stream;
public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements IForgeRegistryEntry<BogeyStyle> {
public Map<BogeySize, ResourceLocation> blocks = new EnumMap<>(BogeySize.class);
public Component displayName;
public SoundEvent soundType;
public ResourceLocation soundType;
public CompoundTag defaultData;
public BogeyRenderer renderer;
@ -58,6 +61,13 @@ public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements
return sizes[nextOrdinal];
}
@NotNull
public SoundEvent getSoundType() {
AllSoundEvents.SoundEntry entry = AllSoundEvents.ALL.get(this.soundType);
if (entry == null) entry = AllSoundEvents.TRAIN2;
return entry.getMainEvent();
}
public BogeyInstance createInstance(CarriageBogey bogey, BogeySize size, MaterialManager materialManager) {
return new BogeyInstance(bogey, this.renderer.newInstance(), size, materialManager);
}

View file

@ -86,7 +86,7 @@ public class CarriageSounds {
CarriageContraptionEntity cce = dce.entity.get();
if (cce != null) {
Couple<CarriageBogey> bogeys = cce.getCarriage().bogeys;
closestBogeySound = bogeys.get(distance1 > distance2).getStyle().soundType;
closestBogeySound = bogeys.get(distance1 > distance2).getStyle().getSoundType();
}
Vec3 toCarriage = distance1 > distance2 ? toBogey2 : toBogey1;

View file

@ -36,7 +36,7 @@ import java.util.function.Supplier;
public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<BogeyStyle, T, P, BogeyStyleBuilder<T, P>> {
private final T style;
private NonNullSupplier<BogeyRenderer> renderer;
private Supplier<SoundEvent> soundType;
private Supplier<ResourceLocation> soundType;
private Supplier<CompoundTag> data;
private Supplier<ParticleType<?>> particles;
@ -47,7 +47,7 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> 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.soundType = AllSoundEvents.TRAIN2::getId;
this.particles = AllParticleTypes.AIR_FLOW::get;
this.data = CompoundTag::new;
}
@ -62,7 +62,7 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<
return this;
}
public BogeyStyleBuilder<T, P> soundType(SoundEvent soundEntry) {
public BogeyStyleBuilder<T, P> soundType(ResourceLocation soundEntry) {
this.soundType = () -> soundEntry;
return this;
}