diff --git a/src/main/java/com/drmangotea/createindustry/CreateTFMG.java b/src/main/java/com/drmangotea/createindustry/CreateTFMG.java index b47a2f40..378ac9d2 100644 --- a/src/main/java/com/drmangotea/createindustry/CreateTFMG.java +++ b/src/main/java/com/drmangotea/createindustry/CreateTFMG.java @@ -54,16 +54,19 @@ public class CreateTFMG TFMGCreativeModeTabs.init(); TFMGFluids.register(); TFMGPaletteBlocks.register(); + TFMGSoundEvents.prepare(); TFMGColoredFires.register(modEventBus); TFMGFeatures.register(modEventBus); TFMGRecipeTypes.register(modEventBus); // + MinecraftForge.EVENT_BUS.register(this); modEventBus.addListener(EventPriority.LOWEST, CreateTFMG::gatherData); + modEventBus.addListener(TFMGSoundEvents::register); DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> CreateTFMGClient::new); modEventBus.addListener(this::clientSetup); - MinecraftForge.EVENT_BUS.register(this); + } @SuppressWarnings("removal") public static void gatherData(GatherDataEvent event) { diff --git a/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineBlockEntity.java index cd5fd070..d9e9eac6 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineBlockEntity.java @@ -1,11 +1,10 @@ package com.drmangotea.createindustry.blocks.engines.diesel; -import com.drmangotea.createindustry.CreateTFMG; import com.drmangotea.createindustry.blocks.engines.diesel.engine_expansion.DieselEngineExpansionBlockEntity; -import com.drmangotea.createindustry.registry.TFMGBlockEntities; import com.drmangotea.createindustry.registry.TFMGBlocks; import com.drmangotea.createindustry.registry.TFMGFluids; +import com.drmangotea.createindustry.registry.TFMGSoundEvents; import com.simibubi.create.content.contraptions.bearing.WindmillBearingBlockEntity; import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation; import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity; @@ -17,7 +16,6 @@ import com.simibubi.create.content.kinetics.steamEngine.SteamEngineBlock; import com.simibubi.create.content.kinetics.steamEngine.SteamEngineValueBox; import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; -import com.simibubi.create.foundation.blockEntity.behaviour.fluid.SmartFluidTankBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollOptionBehaviour; import com.simibubi.create.foundation.fluid.CombinedTankWrapper; import com.simibubi.create.foundation.fluid.SmartFluidTank; @@ -28,10 +26,7 @@ import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; import net.minecraft.core.Direction.AxisDirection; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtUtils; import net.minecraft.network.chat.Component; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.DirectionalBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -129,7 +124,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo super.tick(); Direction direction; - + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::makeSound); if(getBlockState().getValue(FACE)==AttachFace.WALL) expansionPos = this.getBlockPos().relative(getBlockState().getValue(FACING).getOpposite()); @@ -206,7 +201,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo } shaft.update(worldPosition, conveyedSpeedLevel, engineStrength); - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::makeSound); + } @OnlyIn(Dist.CLIENT) private void makeSound(){ @@ -214,8 +209,8 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo PoweredShaftBlockEntity ste = target.get(); if (ste == null) return; - if (!ste.isPoweredBy(worldPosition) || ste.engineEfficiency == 0) - return; + //if (engineStrength == 0) + // return; if (targetAngle == null) return; @@ -231,13 +226,13 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo prevAngle = angle; return; } + if (angle < 0 && !(prevAngle < -180 && angle > -180)) { prevAngle = angle; return; } - float pitch = 1.18f - level.random.nextFloat() * .25f; - //CISoundEvents.DIESEL_ENGINE_SOUNDS.playAt(level, worldPosition, 0.3f, .2f, false); + TFMGSoundEvents.ENGINE.playAt(level, worldPosition, 1.0f, 1f, false); prevAngle = angle; } @@ -392,7 +387,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo if (!TFMGBlocks.DIESEL_ENGINE.has(blockState)) return null; - Direction facing = DieselEngineBlock.getFacing(blockState); + Direction facing = SteamEngineBlock.getFacing(blockState); PoweredShaftBlockEntity shaft = getShaft(); Axis facingAxis = facing.getAxis(); Axis axis = Axis.Y; diff --git a/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineValueBox.java b/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineValueBox.java deleted file mode 100644 index cb26437e..00000000 --- a/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineValueBox.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.drmangotea.createindustry.blocks.engines.diesel; - - -import com.jozufozu.flywheel.util.transform.TransformStack; -import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform; -import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.Pointing; -import com.simibubi.create.foundation.utility.VecHelper; -import net.minecraft.core.Direction; -import net.minecraft.core.Direction.Axis; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; - -public class DieselEngineValueBox extends ValueBoxTransform.Sided { - - @Override - protected boolean isSideActive(BlockState state, Direction direction) { - return DieselEngineBlock.getFacing(state) - .getAxis() != direction.getAxis(); - } - - @Override - public Vec3 getLocalOffset(BlockState state) { - Direction side = getSide(); - Direction engineFacing = DieselEngineBlock.getFacing(state); - - float roll = 0; - for (Pointing p : Pointing.values()) { - if (p.getCombinedDirection(engineFacing) == side) - roll = p.getXRotation(); - } - if (engineFacing == Direction.UP) - roll += 180; - - float horizontalAngle = AngleHelper.horizontalAngle(engineFacing); - float verticalAngle = AngleHelper.verticalAngle(engineFacing); - - boolean recessed = roll % 180 == 0; - if (engineFacing.getAxis() == Axis.Y) - recessed ^= state.getValue(DieselEngineBlock.FACING).getAxis() == Axis.X; - - Vec3 local = VecHelper.voxelSpace(8, recessed ? 13 : 15, 9); - - local = VecHelper.rotateCentered(local, roll, Axis.Z); - local = VecHelper.rotateCentered(local, horizontalAngle, Axis.Y); - local = VecHelper.rotateCentered(local, verticalAngle, Axis.X); - - return local; - } - - @Override - public void rotate(BlockState state, PoseStack ms) { - Direction facing = DieselEngineBlock.getFacing(state); - - if (facing.getAxis() == Axis.Y) { - super.rotate(state, ms); - return; - } - - float roll = 0; - for (Pointing p : Pointing.values()) { - if (p.getCombinedDirection(facing) == getSide()) - roll = p.getXRotation(); - } - - float yRot = AngleHelper.horizontalAngle(facing) + (facing == Direction.DOWN ? 180 : 0); - TransformStack.cast(ms) - .rotateY(yRot) - .rotateX(facing == Direction.DOWN ? -90 : 90) - .rotateY(roll); - } - - @Override - protected Vec3 getSouthLocation() { - return Vec3.ZERO; - } - -} diff --git a/src/main/java/com/drmangotea/createindustry/blocks/engines/small/AbstractEngineTileEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/engines/small/AbstractEngineTileEntity.java index d3c6b5d3..70b9ca8a 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/engines/small/AbstractEngineTileEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/engines/small/AbstractEngineTileEntity.java @@ -4,13 +4,12 @@ package com.drmangotea.createindustry.blocks.engines.small; import com.drmangotea.createindustry.blocks.engines.small.turbine.TurbineEngineTileEntity; import com.drmangotea.createindustry.registry.TFMGBlocks; import com.drmangotea.createindustry.registry.TFMGFluids; -import com.simibubi.create.AllSoundEvents; +import com.drmangotea.createindustry.registry.TFMGSoundEvents; import com.simibubi.create.Create; import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation; import com.simibubi.create.content.equipment.wrench.IWrenchable; import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; -import com.simibubi.create.foundation.blockEntity.behaviour.fluid.SmartFluidTankBehaviour; import com.simibubi.create.foundation.fluid.CombinedTankWrapper; import com.simibubi.create.foundation.fluid.SmartFluidTank; import com.simibubi.create.foundation.utility.Lang; @@ -444,7 +443,7 @@ public void write(CompoundTag compound, boolean clientPacket) { soundTimer++; // if(!isExhaustTankFull()) { - if (soundTimer >= ((16-signal)/2)+1) { + if (soundTimer >= ((16-signal)/0.8)+1) { if(signal!=0&& hasBackPart()&& tankInventory.getFluidAmount()!=0 && @@ -543,11 +542,11 @@ public void write(CompoundTag compound, boolean clientPacket) { private void makeSound(){ soundTimer=0; if(this instanceof TurbineEngineTileEntity){ - AllSoundEvents.WHISTLE_CHIFF.playAt(level, worldPosition, 0.03f, .2f, false); + TFMGSoundEvents.ENGINE.playAt(level, worldPosition, 0.4f, 1.5f, false); } - //else + else - // CISoundEvents.DIESEL_ENGINE_SOUNDS.playAt(level, worldPosition, 0.9f, .1f, false); + TFMGSoundEvents.ENGINE.playAt(level, worldPosition, 0.6f, 1f, false); } diff --git a/src/main/java/com/drmangotea/createindustry/blocks/machines/metal_processing/coke_oven/CokeOvenBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/machines/metal_processing/coke_oven/CokeOvenBlockEntity.java index 90d4a905..25fda2fe 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/machines/metal_processing/coke_oven/CokeOvenBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/machines/metal_processing/coke_oven/CokeOvenBlockEntity.java @@ -187,14 +187,14 @@ public class CokeOvenBlockEntity extends TFMGMachineBlockEntity implements IWren if(lastRecipe!=null &&isController &&timer==-1 - &&inputInventory.getItem(0).getCount()>=20&& + &&inputInventory.getItem(0).getCount()>=10&& (tank2.getPrimaryHandler().getFluidAmount()+CARBON_DIOXIDE_PRODUCTION)<=tank2.getPrimaryHandler().getCapacity()&& (tank1.getPrimaryHandler().getFluidAmount()+lastRecipe.getFluidResults().get(0).getAmount())<=tank1.getPrimaryHandler().getCapacity( )){ timer = lastRecipe.getProcessingDuration(); - inputInventory.setItem(0,new ItemStack(inputInventory.getItem(0).getItem(),inputInventory.getItem(0).getCount()-20)); + inputInventory.setItem(0,new ItemStack(inputInventory.getItem(0).getItem(),inputInventory.getItem(0).getCount()-10)); } // if(lastRecipe != null) diff --git a/src/main/java/com/drmangotea/createindustry/registry/TFMGSoundEvents.java b/src/main/java/com/drmangotea/createindustry/registry/TFMGSoundEvents.java new file mode 100644 index 00000000..ad017204 --- /dev/null +++ b/src/main/java/com/drmangotea/createindustry/registry/TFMGSoundEvents.java @@ -0,0 +1,440 @@ + +package com.drmangotea.createindustry.registry; + + +import com.drmangotea.createindustry.CreateTFMG; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.simibubi.create.Create; +import net.minecraft.core.Registry; +import net.minecraft.core.Vec3i; +import net.minecraft.data.CachedOutput; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.DataProvider; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegisterEvent; +import net.minecraftforge.registries.RegistryObject; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + + +public class TFMGSoundEvents { + + public static final Map ALL = new HashMap<>(); + + public static final TFMGSoundEvents.SoundEntry + + + ENGINE = create("diesel_engine") + .subtitle("idk how to call this :3") + .category(SoundSource.BLOCKS) + .attenuationDistance(10) + .build(); + + + + private static TFMGSoundEvents.SoundEntryBuilder create(String name) { + return create(CreateTFMG.asResource(name)); + } + + public static TFMGSoundEvents.SoundEntryBuilder create(ResourceLocation id) { + return new TFMGSoundEvents.SoundEntryBuilder(id); + } + + public static void prepare() { + for (TFMGSoundEvents.SoundEntry entry : ALL.values()) + entry.prepare(); + } + + public static void register(RegisterEvent event) { + event.register(Registry.SOUND_EVENT_REGISTRY, helper -> { + for (TFMGSoundEvents.SoundEntry entry : ALL.values()) + entry.register(helper); + }); + } + + public static JsonObject provideLangEntries() { + JsonObject object = new JsonObject(); + for (TFMGSoundEvents.SoundEntry entry : ALL.values()) + if (entry.hasSubtitle()) + object.addProperty(entry.getSubtitleKey(), entry.getSubtitle()); + return object; + } + + public static TFMGSoundEvents.SoundEntryProvider provider(DataGenerator generator) { + return new TFMGSoundEvents.SoundEntryProvider(generator); + } + + public static void playItemPickup(Player player) { + player.level.playSound(null, player.blockPosition(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, .2f, + 1f + Create.RANDOM.nextFloat()); + } + +// @SubscribeEvent +// public static void cancelSubtitlesOfCompoundedSounds(PlaySoundEvent event) { +// ResourceLocation soundLocation = event.getSound().getSoundLocation(); +// if (!soundLocation.getNamespace().equals(Create.ID)) +// return; +// if (soundLocation.getPath().contains("_compounded_") +// event.setResultSound(); +// +// } + + private static class SoundEntryProvider implements DataProvider { + + private DataGenerator generator; + + public SoundEntryProvider(DataGenerator generator) { + this.generator = generator; + } + + @Override + public void run(CachedOutput cache) throws IOException { + generate(generator.getOutputFolder(), cache); + } + + @Override + public String getName() { + return "TFMG's Custom Sounds"; + } + + public void generate(Path path, CachedOutput cache) { + Gson GSON = (new GsonBuilder()).setPrettyPrinting() + .disableHtmlEscaping() + .create(); + path = path.resolve("assets/createindustry"); + + try { + JsonObject json = new JsonObject(); + ALL.entrySet() + .stream() + .sorted(Map.Entry.comparingByKey()) + .forEach(entry -> { + entry.getValue() + .write(json); + }); + DataProvider.saveStable(cache, json, path.resolve("sounds.json")); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + + public record ConfiguredSoundEvent(Supplier event, float volume, float pitch) { + } + + public static class SoundEntryBuilder { + + protected ResourceLocation id; + protected String subtitle = "unregistered"; + protected SoundSource category = SoundSource.BLOCKS; + protected List wrappedEvents; + protected List variants; + protected int attenuationDistance; + + public SoundEntryBuilder(ResourceLocation id) { + wrappedEvents = new ArrayList<>(); + variants = new ArrayList<>(); + this.id = id; + } + + public TFMGSoundEvents.SoundEntryBuilder subtitle(String subtitle) { + this.subtitle = subtitle; + return this; + } + + public TFMGSoundEvents.SoundEntryBuilder attenuationDistance(int distance) { + this.attenuationDistance = distance; + return this; + } + + public TFMGSoundEvents.SoundEntryBuilder noSubtitle() { + this.subtitle = null; + return this; + } + + public TFMGSoundEvents.SoundEntryBuilder category(SoundSource category) { + this.category = category; + return this; + } + + public TFMGSoundEvents.SoundEntryBuilder addVariant(String name) { + return addVariant(CreateTFMG.asResource(name)); + } + + public TFMGSoundEvents.SoundEntryBuilder addVariant(ResourceLocation id) { + variants.add(id); + return this; + } + + public TFMGSoundEvents.SoundEntryBuilder playExisting(Supplier event, float volume, float pitch) { + wrappedEvents.add(new TFMGSoundEvents.ConfiguredSoundEvent(event, volume, pitch)); + return this; + } + + public TFMGSoundEvents.SoundEntryBuilder playExisting(SoundEvent event, float volume, float pitch) { + return playExisting(() -> event, volume, pitch); + } + + public TFMGSoundEvents.SoundEntryBuilder playExisting(SoundEvent event) { + return playExisting(event, 1, 1); + } + + public TFMGSoundEvents.SoundEntry build() { + TFMGSoundEvents.SoundEntry entry = + wrappedEvents.isEmpty() ? new TFMGSoundEvents.CustomSoundEntry(id, variants, subtitle, category, attenuationDistance) + : new TFMGSoundEvents.WrappedSoundEntry(id, subtitle, wrappedEvents, category, attenuationDistance); + ALL.put(entry.getId(), entry); + return entry; + } + + } + + public static abstract class SoundEntry { + + protected ResourceLocation id; + protected String subtitle; + protected SoundSource category; + protected int attenuationDistance; + + public SoundEntry(ResourceLocation id, String subtitle, SoundSource category, int attenuationDistance) { + this.id = id; + this.subtitle = subtitle; + this.category = category; + this.attenuationDistance = attenuationDistance; + } + + public abstract void prepare(); + + public abstract void register(RegisterEvent.RegisterHelper registry); + + public abstract void write(JsonObject json); + + public abstract SoundEvent getMainEvent(); + + public String getSubtitleKey() { + return id.getNamespace() + ".subtitle." + id.getPath(); + } + + public ResourceLocation getId() { + return id; + } + + public boolean hasSubtitle() { + return subtitle != null; + } + + public String getSubtitle() { + return subtitle; + } + + public void playOnServer(Level world, Vec3i pos) { + playOnServer(world, pos, 1, 1); + } + + public void playOnServer(Level world, Vec3i pos, float volume, float pitch) { + play(world, null, pos, volume, pitch); + } + + public void play(Level world, Player entity, Vec3i pos) { + play(world, entity, pos, 1, 1); + } + + public void playFrom(Entity entity) { + playFrom(entity, 1, 1); + } + + public void playFrom(Entity entity, float volume, float pitch) { + if (!entity.isSilent()) + play(entity.level, null, entity.blockPosition(), volume, pitch); + } + + public void play(Level world, Player entity, Vec3i pos, float volume, float pitch) { + play(world, entity, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, volume, pitch); + } + + public void play(Level world, Player entity, Vec3 pos, float volume, float pitch) { + play(world, entity, pos.x(), pos.y(), pos.z(), volume, pitch); + } + + public abstract void play(Level world, Player entity, double x, double y, double z, float volume, float pitch); + + public void playAt(Level world, Vec3i pos, float volume, float pitch, boolean fade) { + playAt(world, pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5, volume, pitch, fade); + } + + public void playAt(Level world, Vec3 pos, float volume, float pitch, boolean fade) { + playAt(world, pos.x(), pos.y(), pos.z(), volume, pitch, fade); + } + + public abstract void playAt(Level world, double x, double y, double z, float volume, float pitch, boolean fade); + + } + + private static class WrappedSoundEntry extends TFMGSoundEvents.SoundEntry { + + private List wrappedEvents; + private List compiledEvents; + + public WrappedSoundEntry(ResourceLocation id, String subtitle, + List wrappedEvents, SoundSource category, int attenuationDistance) { + super(id, subtitle, category, attenuationDistance); + this.wrappedEvents = wrappedEvents; + compiledEvents = new ArrayList<>(); + } + + @Override + public void prepare() { + for (int i = 0; i < wrappedEvents.size(); i++) { + TFMGSoundEvents.ConfiguredSoundEvent wrapped = wrappedEvents.get(i); + ResourceLocation location = getIdOf(i); + RegistryObject event = RegistryObject.create(location, ForgeRegistries.SOUND_EVENTS); + compiledEvents.add(new TFMGSoundEvents.WrappedSoundEntry.CompiledSoundEvent(event, wrapped.volume(), wrapped.pitch())); + } + } + + @Override + public void register(RegisterEvent.RegisterHelper helper) { + for (TFMGSoundEvents.WrappedSoundEntry.CompiledSoundEvent compiledEvent : compiledEvents) { + ResourceLocation location = compiledEvent.event().getId(); + helper.register(location, new SoundEvent(location)); + } + } + + @Override + public SoundEvent getMainEvent() { + return compiledEvents.get(0) + .event().get(); + } + + protected ResourceLocation getIdOf(int i) { + return new ResourceLocation(id.getNamespace(), i == 0 ? id.getPath() : id.getPath() + "_compounded_" + i); + } + + @Override + public void write(JsonObject json) { + for (int i = 0; i < wrappedEvents.size(); i++) { + TFMGSoundEvents.ConfiguredSoundEvent event = wrappedEvents.get(i); + JsonObject entry = new JsonObject(); + JsonArray list = new JsonArray(); + JsonObject s = new JsonObject(); + s.addProperty("name", event.event() + .get() + .getLocation() + .toString()); + s.addProperty("type", "event"); + if (attenuationDistance != 0) + s.addProperty("attenuation_distance", attenuationDistance); + list.add(s); + entry.add("sounds", list); + if (i == 0 && hasSubtitle()) + entry.addProperty("subtitle", getSubtitleKey()); + json.add(getIdOf(i).getPath(), entry); + } + } + + @Override + public void play(Level world, Player entity, double x, double y, double z, float volume, float pitch) { + for (TFMGSoundEvents.WrappedSoundEntry.CompiledSoundEvent event : compiledEvents) { + world.playSound(entity, x, y, z, event.event().get(), category, event.volume() * volume, + event.pitch() * pitch); + } + } + + @Override + public void playAt(Level world, double x, double y, double z, float volume, float pitch, boolean fade) { + for (TFMGSoundEvents.WrappedSoundEntry.CompiledSoundEvent event : compiledEvents) { + world.playLocalSound(x, y, z, event.event().get(), category, event.volume() * volume, + event.pitch() * pitch, fade); + } + } + + private record CompiledSoundEvent(RegistryObject event, float volume, float pitch) { + } + + } + + private static class CustomSoundEntry extends TFMGSoundEvents.SoundEntry { + + protected List variants; + protected RegistryObject event; + + public CustomSoundEntry(ResourceLocation id, List variants, String subtitle, + SoundSource category, int attenuationDistance) { + super(id, subtitle, category, attenuationDistance); + this.variants = variants; + } + + @Override + public void prepare() { + event = RegistryObject.create(id, ForgeRegistries.SOUND_EVENTS); + } + + public void register(RegisterEvent.RegisterHelper helper) { + ResourceLocation location = event.getId(); + helper.register(location, new SoundEvent(location)); + } + + @Override + public SoundEvent getMainEvent() { + return event.get(); + } + + @Override + public void write(JsonObject json) { + JsonObject entry = new JsonObject(); + JsonArray list = new JsonArray(); + + JsonObject s = new JsonObject(); + s.addProperty("name", id.toString()); + s.addProperty("type", "file"); + if (attenuationDistance != 0) + s.addProperty("attenuation_distance", attenuationDistance); + list.add(s); + + for (ResourceLocation variant : variants) { + s = new JsonObject(); + s.addProperty("name", variant.toString()); + s.addProperty("type", "file"); + if (attenuationDistance != 0) + s.addProperty("attenuation_distance", attenuationDistance); + list.add(s); + } + + entry.add("sounds", list); + if (hasSubtitle()) + entry.addProperty("subtitle", getSubtitleKey()); + json.add(id.getPath(), entry); + } + + @Override + public void play(Level world, Player entity, double x, double y, double z, float volume, float pitch) { + world.playSound(entity, x, y, z, event.get(), category, volume, pitch); + } + + @Override + public void playAt(Level world, double x, double y, double z, float volume, float pitch, boolean fade) { + world.playLocalSound(x, y, z, event.get(), category, volume, pitch, fade); + } + + } + +} diff --git a/src/main/resources/assets/createindustry/sounds.json b/src/main/resources/assets/createindustry/sounds.json new file mode 100644 index 00000000..7e999b18 --- /dev/null +++ b/src/main/resources/assets/createindustry/sounds.json @@ -0,0 +1,13 @@ +{ + + "diesel_engine": { + "sounds": [ + { + "name": "createindustry:diesel_engine", + "type": "file", + "attenuation_distance": 16 + } + ], + "subtitle": "createindustry.subtitle.engine_sounds" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/createindustry/sounds/diesel_engine.ogg b/src/main/resources/assets/createindustry/sounds/diesel_engine.ogg new file mode 100644 index 00000000..a3885eb1 Binary files /dev/null and b/src/main/resources/assets/createindustry/sounds/diesel_engine.ogg differ diff --git a/src/main/resources/assets/createindustry/sounds/diesel_engine_.ogg b/src/main/resources/assets/createindustry/sounds/diesel_engine_.ogg new file mode 100644 index 00000000..5254b4fe Binary files /dev/null and b/src/main/resources/assets/createindustry/sounds/diesel_engine_.ogg differ diff --git a/src/main/resources/data/createindustry/recipes/coking/coal_coke.json b/src/main/resources/data/createindustry/recipes/coking/coal_coke.json index 431fba41..8acdd73d 100644 --- a/src/main/resources/data/createindustry/recipes/coking/coal_coke.json +++ b/src/main/resources/data/createindustry/recipes/coking/coal_coke.json @@ -2,14 +2,14 @@ "type": "createindustry:coking", "ingredients": [ { - "count": 20, + "count": 10, "item": "minecraft:coal" } ], - "processingTime": 2000, + "processingTime": 1000, "results": [ { - "count": 20, + "count": 10, "item": "createindustry:coal_coke" } ,