diff options
6 files changed, 111 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/enums/SoundResource.java b/src/main/java/gregtech/api/enums/SoundResource.java index af6f768c67..f1dffb3884 100644 --- a/src/main/java/gregtech/api/enums/SoundResource.java +++ b/src/main/java/gregtech/api/enums/SoundResource.java @@ -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"), diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 92d90c63a9..51086d806b 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -12,12 +12,14 @@ import java.util.List; 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; @@ -35,6 +37,8 @@ import com.gtnewhorizons.modularui.api.screen.UIBuildContext; 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; @@ -51,6 +55,7 @@ import gregtech.api.metatileentity.MetaTileEntity; 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; @@ -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; @@ -366,6 +373,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity aBaseMetaTileEntity.setActive(mMaxProgresstime > 0); boolean active = aBaseMetaTileEntity.isActive() && mPollution > 0; setMufflers(active); + } else { + doActivitySound(getActivitySoundLoop()); } } @@ -509,6 +518,20 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity } } + @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 */ @@ -524,6 +547,14 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity } /** + * @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 */ public boolean onRunningTick(ItemStack aStack) { diff --git a/src/main/java/gregtech/client/GT_SoundLoop.java b/src/main/java/gregtech/client/GT_SoundLoop.java new file mode 100644 index 0000000000..6b6546ced5 --- /dev/null +++ b/src/main/java/gregtech/client/GT_SoundLoop.java @@ -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; + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java index 6c22badf9e..d058bf1f42 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java @@ -15,6 +15,7 @@ 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.ChunkCoordIntPair; import net.minecraftforge.fluids.FluidStack; @@ -24,9 +25,12 @@ import com.gtnewhorizon.structurelib.structure.IStructureDefinition; 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; @@ -942,6 +946,12 @@ public class GT_MetaTileEntity_PlasmaForge extends GT_MetaTileEntity_AbstractMul 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); diff --git a/src/main/resources/assets/gregtech/sounds.json b/src/main/resources/assets/gregtech/sounds.json index 1286fb0633..95d534b7cd 100644 --- a/src/main/resources/assets/gregtech/sounds.json +++ b/src/main/resources/assets/gregtech/sounds.json @@ -34,5 +34,14 @@ "stream": false } ] + }, + "machines.PlasmaForgeLoop": { + "category": "block", + "sounds": [ + { + "name": "PlasmaForgeLoop", + "stream": false + } + ] } } diff --git a/src/main/resources/assets/gregtech/sounds/PlasmaForgeLoop.ogg b/src/main/resources/assets/gregtech/sounds/PlasmaForgeLoop.ogg Binary files differnew file mode 100644 index 0000000000..e9b7a2bdba --- /dev/null +++ b/src/main/resources/assets/gregtech/sounds/PlasmaForgeLoop.ogg |