-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New sound effect for black hole compressor (#3265)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
- Loading branch information
1 parent
b9f4304
commit 95d749f
Showing
5 changed files
with
172 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/tectech/thing/metaTileEntity/multi/base/SoundLoopAnyBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.