diff options
author | Volence <32358820+Volence@users.noreply.github.com> | 2024-09-23 16:30:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-23 20:30:53 +0000 |
commit | 95d749f1d690f63e862aa0a86142e036cc0ada8a (patch) | |
tree | 2b408b76c95c73e30cddf12b94dd55538c7a3215 /src/main/java/tectech | |
parent | b9f4304cc182802c32197ac15e153d0e840f7a4d (diff) | |
download | GT5-Unofficial-95d749f1d690f63e862aa0a86142e036cc0ada8a.tar.gz GT5-Unofficial-95d749f1d690f63e862aa0a86142e036cc0ada8a.tar.bz2 GT5-Unofficial-95d749f1d690f63e862aa0a86142e036cc0ada8a.zip |
New sound effect for black hole compressor (#3265)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src/main/java/tectech')
-rw-r--r-- | src/main/java/tectech/thing/metaTileEntity/multi/base/SoundLoopAnyBlock.java | 90 |
1 files changed, 90 insertions, 0 deletions
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; + } +} |