Skip to content

Commit

Permalink
New sound effect for black hole compressor (#3265)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
Volence and Dream-Master committed Sep 23, 2024
1 parent b9f4304 commit 95d749f
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 21 deletions.
42 changes: 22 additions & 20 deletions src/main/java/gregtech/api/enums/SoundResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,28 @@ public enum SoundResource {
GT_SPRAYCAN_LOCK(244, GregTech.ID, "items.spraycan_lock"),
GT_SPRAYCAN_UNLOCK(245, GregTech.ID, "items.spraycan_unlock"),

GT_MACHINES_MULTI_PRECISE_LOOP(244, GregTech.ID, "machines.MTEPreciseAssembler"),
GT_MACHINES_MULTI_ORE_WASHER_PLANT_LOOP(245, GregTech.ID, "machines.MTEIndustrialWashPlant"),
GT_MACHINES_MULTI_MEGA_VACUUM_FREEZER_LOOP(246, GregTech.ID, "machines.MTEMegaVacuumFreezer"),
GT_MACHINES_MULTI_VACUUM_FREEZER_LOOP(247, GregTech.ID, "machines.MTEVacuumFreezer"),
GT_MACHINES_EXTREME_ENTITY_CRUSHER_LOOP(248, GregTech.ID, "machines.MTEExtremeEntityCrusher"),
GT_MACHINES_CUTTING_MACHINE_LOOP(249, GregTech.ID, "machines.MTEIndustrialCuttingMachine"),
GT_MACHINES_ARC_FURNACE_LOOP(250, GregTech.ID, "machines.MTEIndustrialArcFurnace"),
GT_MACHINES_MEGA_INDUSTRIAL_APIARY_LOOP(251, GregTech.ID, "machines.MTEMegaIndustrialApiary"),
GT_MACHINES_ALGAE_LOOP(252, GregTech.ID, "machines.MTEAlgaePondBase"),
GT_MACHINES_THERMAL_CENTRIFUGE_LOOP(253, GregTech.ID, "machines.MTEIndustrialThermalCentrifuge"),
GT_MACHINES_SIFTER_LOOP(254, GregTech.ID, "machines.MTEIndustrialSifter"),
GT_MACHINES_EYE_OF_HARMONY_LOOP(255, GregTech.ID, "machines.MTEEyeOfHarmony"),
GT_MACHINES_EBF_LOOP(256, GregTech.ID, "machines.MTEElectricBlastFurnace"),
GT_MACHINES_ADV_FREEZER_LOOP(257, GregTech.ID, "machines.MTEIndustrialVacuumFreezer"),
GT_MACHINES_GOD_FORGE_LOOP(258, GregTech.ID, "machines.MTEForgeOfGods"),
GT_MACHINES_MEGA_BLAST_FURNACE_LOOP(259, GregTech.ID, "machines.MTEMegaBlastFurnace"),
GT_MACHINES_OIL_DRILL_LOOP(260, GregTech.ID, "machines.MTEOilDrillBase"),
GT_MACHINES_QUANTUM_FORCE_TRANSFORMER_LOOP(261, GregTech.ID, "machines.MTEQuantumForceTransformer"),
GT_MACHINES_ADV_EBF_LOOP(262, GregTech.ID, "machines.MTEAdvEBF"),
GT_MACHINES_LARGE_TURBINES_LOOP(263, GregTech.ID, "machines.MTELargeTurbine"),
GT_MACHINES_BLACK_HOLE_COMPRESSOR(246, GregTech.ID, "machines.BlackHoleCompressorLoop"),

GT_MACHINES_MULTI_PRECISE_LOOP(247, GregTech.ID, "machines.MTEPreciseAssembler"),
GT_MACHINES_MULTI_ORE_WASHER_PLANT_LOOP(248, GregTech.ID, "machines.MTEIndustrialWashPlant"),
GT_MACHINES_MULTI_MEGA_VACUUM_FREEZER_LOOP(249, GregTech.ID, "machines.MTEMegaVacuumFreezer"),
GT_MACHINES_MULTI_VACUUM_FREEZER_LOOP(250, GregTech.ID, "machines.MTEVacuumFreezer"),
GT_MACHINES_EXTREME_ENTITY_CRUSHER_LOOP(251, GregTech.ID, "machines.MTEExtremeEntityCrusher"),
GT_MACHINES_CUTTING_MACHINE_LOOP(252, GregTech.ID, "machines.MTEIndustrialCuttingMachine"),
GT_MACHINES_ARC_FURNACE_LOOP(253, GregTech.ID, "machines.MTEIndustrialArcFurnace"),
GT_MACHINES_MEGA_INDUSTRIAL_APIARY_LOOP(254, GregTech.ID, "machines.MTEMegaIndustrialApiary"),
GT_MACHINES_ALGAE_LOOP(255, GregTech.ID, "machines.MTEAlgaePondBase"),
GT_MACHINES_THERMAL_CENTRIFUGE_LOOP(256, GregTech.ID, "machines.MTEIndustrialThermalCentrifuge"),
GT_MACHINES_SIFTER_LOOP(257, GregTech.ID, "machines.MTEIndustrialSifter"),
GT_MACHINES_EYE_OF_HARMONY_LOOP(258, GregTech.ID, "machines.MTEEyeOfHarmony"),
GT_MACHINES_EBF_LOOP(259, GregTech.ID, "machines.MTEElectricBlastFurnace"),
GT_MACHINES_ADV_FREEZER_LOOP(260, GregTech.ID, "machines.MTEIndustrialVacuumFreezer"),
GT_MACHINES_GOD_FORGE_LOOP(261, GregTech.ID, "machines.MTEForgeOfGods"),
GT_MACHINES_MEGA_BLAST_FURNACE_LOOP(262, GregTech.ID, "machines.MTEMegaBlastFurnace"),
GT_MACHINES_OIL_DRILL_LOOP(263, GregTech.ID, "machines.MTEOilDrillBase"),
GT_MACHINES_QUANTUM_FORCE_TRANSFORMER_LOOP(264, GregTech.ID, "machines.MTEQuantumForceTransformer"),
GT_MACHINES_ADV_EBF_LOOP(265, GregTech.ID, "machines.MTEAdvEBF"),
GT_MACHINES_LARGE_TURBINES_LOOP(266, GregTech.ID, "machines.MTELargeTurbine"),

GUI_BUTTON_DOWN(-1, GregTech.ID, "gui.buttonDown"),
GUI_BUTTON_UP(-1, GregTech.ID, "gui.buttonUp"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import javax.annotation.Nonnull;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
Expand All @@ -48,9 +50,12 @@
import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.Materials;
import gregtech.api.enums.MaterialsUEVplus;
import gregtech.api.enums.SoundResource;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.interfaces.ITexture;
Expand All @@ -76,6 +81,7 @@
import gtPlusPlus.core.util.minecraft.PlayerUtils;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import tectech.thing.metaTileEntity.multi.base.SoundLoopAnyBlock;

public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase<MTEBlackHoleCompressor>
implements ISurvivalConstructable {
Expand Down Expand Up @@ -153,6 +159,9 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase<MTEBl
*/
private byte blackHoleStatus = 1;

@SideOnly(Side.CLIENT)
private SoundLoopAnyBlock blackholeSoundLoop;

private final FluidStack blackholeCatalyzingCost = (MaterialsUEVplus.SpaceTime).getMolten(1);
private int catalyzingCostModifier = 1;

Expand Down Expand Up @@ -216,6 +225,44 @@ public void onValueUpdate(byte aValue) {
if (oBlackHoleStatus != blackHoleStatus) getBaseMetaTileEntity().issueTextureUpdate();
}

@SideOnly(Side.CLIENT)
public void playBlackHoleSounds() {
if (blackHoleStatus > 1) {
if (blackholeSoundLoop == null) {
ForgeDirection oppositeDirection = getDirection().getOpposite();
int offsetX = 7 * oppositeDirection.offsetX;
int offsetY = 11;
int offsetZ = 7 * oppositeDirection.offsetZ;

World world = Minecraft.getMinecraft().thePlayer.worldObj;
IGregTechTileEntity base = getBaseMetaTileEntity();

int x = base.getXCoord() + offsetX;
int y = base.getYCoord() + offsetY;
int z = base.getZCoord() + offsetZ;

Block blockAtSoundLocation = world.getBlock(x, y, z);
if (blockAtSoundLocation == Blocks.air) return;

int[] offset = { offsetX, offsetY, offsetZ };
blackholeSoundLoop = new SoundLoopAnyBlock(
SoundResource.GT_MACHINES_BLACK_HOLE_COMPRESSOR.resourceLocation,
getBaseMetaTileEntity(),
false,
false,
offset,
Blocks.air);
Minecraft.getMinecraft()
.getSoundHandler()
.playSound(blackholeSoundLoop);
}
} else {
if (blackholeSoundLoop != null) {
blackholeSoundLoop = null;
}
}
}

@Override
public byte getUpdateData() {
return blackHoleStatus;
Expand Down Expand Up @@ -544,13 +591,16 @@ public boolean onRunningTick(ItemStack aStack) {
mOutputItems = null;
mOutputFluids = null;
}

return super.onRunningTick(aStack);
}

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);

if (!aBaseMetaTileEntity.isServerSide()) {
playBlackHoleSounds();
}
if (aTick % 20 == 0) {
if (blackHoleStatus == 2) {
if (blackHoleStability >= 0) {
Expand Down
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;
}
}
9 changes: 9 additions & 0 deletions src/main/resources/assets/gregtech/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@
}
]
},
"machines.BlackHoleCompressorLoop": {
"category": "block",
"sounds": [
{
"name": "BlackHoleCompressorLoop",
"stream": false
}
]
},
"items.spraycan_shake": {
"category": "player",
"sounds": [
Expand Down
Binary file not shown.

0 comments on commit 95d749f

Please sign in to comment.