From 95d749f1d690f63e862aa0a86142e036cc0ada8a Mon Sep 17 00:00:00 2001 From: Volence <32358820+Volence@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:30:53 -0400 Subject: New sound effect for black hole compressor (#3265) Co-authored-by: Martin Robertz --- .../multi/base/SoundLoopAnyBlock.java | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/main/java/tectech/thing/metaTileEntity/multi/base/SoundLoopAnyBlock.java (limited to 'src/main/java/tectech/thing/metaTileEntity/multi/base/SoundLoopAnyBlock.java') diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/base/SoundLoopAnyBlock.java b/src/main/java/tectech/thing/metaTileEntity/multi/base/SoundLoopAnyBlock.java new file mode 100644 index 0000000000..15b08afb5c --- /dev/null +++ b/src/main/java/tectech/thing/metaTileEntity/multi/base/SoundLoopAnyBlock.java @@ -0,0 +1,90 @@ +package tectech.thing.metaTileEntity.multi.base; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.MovingSound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +@SideOnly(Side.CLIENT) +public class SoundLoopAnyBlock extends MovingSound { + + private final boolean stopWhenBlockActive; + private final boolean stopWhenBlockInactive; + private final int worldID; + private boolean fadeOut = false; + private int tileX; + private int tileY; + private int tileZ; + private Block blockToTriggerEnd = null; + + /** + * Constructs a SoundLoopAnyBlock. + * + * @param soundResource the sound file location + * @param tileEntity the tile entity associated with this sound + * @param stopWhenActive flag to stop the sound when the block is active + * @param stopWhenInactive flag to stop the sound when the block is inactive + * @param offset positional offset for sound origin from the tile entity [x, y, z] + * @param blockCheck block that ends the sound when matched at the sound location + */ + public SoundLoopAnyBlock(ResourceLocation soundResource, IGregTechTileEntity tileEntity, boolean stopWhenActive, + boolean stopWhenInactive, int[] offset, Block blockCheck) { + super(soundResource); + this.stopWhenBlockActive = stopWhenActive; + this.stopWhenBlockInactive = stopWhenInactive; + tileX = tileEntity.getXCoord(); + tileY = tileEntity.getYCoord(); + tileZ = tileEntity.getZCoord(); + xPosF = tileX + offset[0]; + yPosF = tileY + offset[1]; + zPosF = tileZ + offset[2]; + worldID = tileEntity.getWorld().provider.dimensionId; + repeat = true; + volume = 0.0625f; + blockToTriggerEnd = blockCheck; + } + + @Override + public void update() { + if (donePlaying) { + return; + } + + if (fadeOut) { + volume -= 0.0625f; + if (volume <= 0) { + volume = 0; + donePlaying = true; + } + } else if (volume < 1) { + volume += 0.0625f; + } + + World world = Minecraft.getMinecraft().thePlayer.worldObj; + donePlaying = world.provider.dimensionId != worldID + || !world.checkChunksExist((int) xPosF, (int) yPosF, (int) zPosF, (int) xPosF, (int) yPosF, (int) zPosF); + + if (donePlaying) return; + + Block blockAtSoundLocation = world.getBlock((int) xPosF, (int) yPosF, (int) zPosF); + if (blockToTriggerEnd != null) { + donePlaying = blockAtSoundLocation == blockToTriggerEnd; + } + + if (donePlaying) return; + + TileEntity tile = world.getTileEntity(tileX, tileY, tileZ); + donePlaying = tile == null; + + if (donePlaying) return; + + // Adjust fading based on the activity state of the tile entity + fadeOut |= ((IGregTechTileEntity) tile).isActive() ? stopWhenBlockActive : stopWhenBlockInactive; + } +} -- cgit