Skip to content

Commit

Permalink
Activity Sound (#1811)
Browse files Browse the repository at this point in the history
* Added activity sound

* Added acitivity sound to DTPF

* Added missing annotation

* Missed one
  • Loading branch information
minecraft7771 authored Mar 22, 2023
1 parent 3681f2f commit b0843b0
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/enums/SoundResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public enum SoundResource {

GT_MACHINES_FUSION_LOOP(230, MOD_ID, "machines.FusionLoop"),
GT_MACHINES_DISTILLERY_LOOP(231, MOD_ID, "machines.DistilleryLoop"),
GT_MACHINES_PLASMAFORGE_LOOP(232, MOD_ID, "machines.PlasmaForgeLoop"),

GUI_BUTTON_DOWN(-1, MOD_ID, "gui.buttonDown"),
GUI_BUTTON_UP(-1, MOD_ID, "gui.buttonUp"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
Expand All @@ -35,6 +37,8 @@
import com.gtnewhorizons.modularui.api.widget.Widget;
import com.gtnewhorizons.modularui.common.widget.*;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.ConfigCategories;
Expand All @@ -51,6 +55,7 @@
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.util.*;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.client.GT_SoundLoop;
import gregtech.common.GT_Pollution;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_DrillerBase;
Expand Down Expand Up @@ -91,6 +96,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
public ArrayList<GT_MetaTileEntity_Hatch_Energy> mEnergyHatches = new ArrayList<>();
public ArrayList<GT_MetaTileEntity_Hatch_Maintenance> mMaintenanceHatches = new ArrayList<>();
protected final List<GT_MetaTileEntity_Hatch> mExoticEnergyHatches = new ArrayList<>();
@SideOnly(Side.CLIENT)
protected GT_SoundLoop activitySoundLoop;

protected static final byte INTERRUPT_SOUND_INDEX = 8;
protected static final byte PROCESS_START_SOUND_INDEX = 1;
Expand Down Expand Up @@ -366,6 +373,8 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
aBaseMetaTileEntity.setActive(mMaxProgresstime > 0);
boolean active = aBaseMetaTileEntity.isActive() && mPollution > 0;
setMufflers(active);
} else {
doActivitySound(getActivitySoundLoop());
}
}

Expand Down Expand Up @@ -509,6 +518,20 @@ public void startSoundLoop(byte aIndex, double aX, double aY, double aZ) {
}
}

@SideOnly(Side.CLIENT)
protected void doActivitySound(ResourceLocation activitySound) {
if (getBaseMetaTileEntity().isActive() && activitySound != null) {
if (activitySoundLoop == null) {
activitySoundLoop = new GT_SoundLoop(activitySound, getBaseMetaTileEntity(), false, true);
Minecraft.getMinecraft().getSoundHandler().playSound(activitySoundLoop);
}
} else {
if (activitySoundLoop != null) {
activitySoundLoop = null;
}
}
}

/**
* @return Time before the start process sound is played again
*/
Expand All @@ -523,6 +546,14 @@ protected SoundResource getProcessStartSound() {
return null;
}

/**
* @return Sound that will be looped for as long as the machine is doing a recipe
*/
@SideOnly(Side.CLIENT)
protected ResourceLocation getActivitySoundLoop() {
return null;
}

/**
* Called every tick the Machine runs
*/
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/gregtech/client/GT_SoundLoop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package gregtech.client;

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 GT_SoundLoop extends MovingSound {

private static final float VOLUME_RAMP = 0.0625f;
private final boolean whileActive;
private final boolean whileInactive;
private final int worldID;
private boolean fadeMe = false;

public GT_SoundLoop(ResourceLocation p_i45104_1_, IGregTechTileEntity base, boolean stopWhenActive,
boolean stopWhenInactive) {
super(p_i45104_1_);
this.whileActive = stopWhenActive;
this.whileInactive = stopWhenInactive;
xPosF = base.getXCoord();
yPosF = base.getYCoord();
zPosF = base.getZCoord();
worldID = base.getWorld().provider.dimensionId;
repeat = true;
volume = VOLUME_RAMP;
}

@Override
public void update() {
if (donePlaying) {
return;
}
if (fadeMe) {
volume -= VOLUME_RAMP;
if (volume <= 0) {
volume = 0;
donePlaying = true;
}
} else if (volume < 1) {
volume += VOLUME_RAMP;
}
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;
TileEntity tile = world.getTileEntity((int) xPosF, (int) yPosF, (int) zPosF);
if (!(tile instanceof IGregTechTileEntity)) {
donePlaying = true;
return;
}
fadeMe |= ((IGregTechTileEntity) tile).isActive() ? whileActive : whileInactive;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraftforge.fluids.FluidStack;
Expand All @@ -24,9 +25,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.GregTech_API;
import gregtech.api.enums.HeatingCoilLevel;
import gregtech.api.enums.Materials;
import gregtech.api.enums.SoundResource;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
Expand Down Expand Up @@ -942,6 +946,12 @@ public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBu
return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 16, 21, 16, realBudget, env, false, true);
}

@SideOnly(Side.CLIENT)
@Override
protected ResourceLocation getActivitySoundLoop() {
return SoundResource.GT_MACHINES_PLASMAFORGE_LOOP.resourceLocation;
}

@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setLong("eRunningTime", running_time);
Expand Down
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 @@ -34,5 +34,14 @@
"stream": false
}
]
},
"machines.PlasmaForgeLoop": {
"category": "block",
"sounds": [
{
"name": "PlasmaForgeLoop",
"stream": false
}
]
}
}
Binary file not shown.

0 comments on commit b0843b0

Please sign in to comment.