diff --git a/dependencies.gradle b/dependencies.gradle index b82bedf..afeb06c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,9 +1,9 @@ // Add your dependencies here dependencies { - api('com.github.GTNewHorizons:Baubles-Expanded:2.1.9-GTNH:dev') + api('com.github.GTNewHorizons:Baubles-Expanded:2.1.14-GTNH:dev') api('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev') - compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.51.368:dev') {transitive = false} + compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.51.457:dev') {transitive = false} } diff --git a/gradle.properties b/gradle.properties index eda05b2..934d1e2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -151,7 +151,7 @@ modrinthProjectId = 1wDWP1tN # type can be one of [project, version], # and the name is the Modrinth project or version slug/id of the other mod. # Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech -# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true +# Note: UniMixins is automatically set as a required dependency if usesMixins = true. modrinthRelations = # Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens. diff --git a/settings.gradle b/settings.gradle index ff436f2..bc5e0f0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.42' } diff --git a/src/main/java/com/kentington/thaumichorizons/client/ClientProxy.java b/src/main/java/com/kentington/thaumichorizons/client/ClientProxy.java index bbf5774..bd2c4fa 100644 --- a/src/main/java/com/kentington/thaumichorizons/client/ClientProxy.java +++ b/src/main/java/com/kentington/thaumichorizons/client/ClientProxy.java @@ -5,6 +5,8 @@ package com.kentington.thaumichorizons.client; import java.awt.Color; +import java.util.HashMap; +import java.util.Map; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -28,6 +30,7 @@ import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.MinecraftForge; +import com.kentington.thaumichorizons.client.audio.VortexSound; import com.kentington.thaumichorizons.client.fx.FXSonic; import com.kentington.thaumichorizons.client.gui.GuiBloodInfuser; import com.kentington.thaumichorizons.client.gui.GuiCase; @@ -555,4 +558,54 @@ public class ClientProxy extends CommonProxy { 1.0f, 0.1f); } + + private final Map activeVortexSounds = new HashMap<>(); + + @Override + public void playVortexSound(TileVortex tile) { + if (tile == null || tile.isInvalid() || tile.getWorldObj() == null) return; + + TileCoord pos = new TileCoord(tile.xCoord, tile.yCoord, tile.zCoord); + if (activeVortexSounds.containsKey(pos)) return; + + VortexSound sound = new VortexSound(tile); + Minecraft.getMinecraft().getSoundHandler().playSound(sound); + activeVortexSounds.put(pos, sound); + } + + @Override + public void stopVortexSound(TileVortex tile) { + if (tile == null) return; + + TileCoord pos = new TileCoord(tile.xCoord, tile.yCoord, tile.zCoord); + VortexSound sound = activeVortexSounds.remove(pos); + if (sound != null) { + sound.markDone(); + } + } + + // Inner class to replace BlockPos for 1.7.10 + private static class TileCoord { + + final int x, y, z; + + TileCoord(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof TileCoord)) return false; + TileCoord other = (TileCoord) o; + return this.x == other.x && this.y == other.y && this.z == other.z; + } + + @Override + public int hashCode() { + return x * 31 * 31 + y * 31 + z; + } + } + } diff --git a/src/main/java/com/kentington/thaumichorizons/client/audio/VortexSound.java b/src/main/java/com/kentington/thaumichorizons/client/audio/VortexSound.java new file mode 100644 index 0000000..9465c27 --- /dev/null +++ b/src/main/java/com/kentington/thaumichorizons/client/audio/VortexSound.java @@ -0,0 +1,48 @@ +package com.kentington.thaumichorizons.client.audio; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.MovingSound; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; + +public class VortexSound extends MovingSound { + + private final TileEntity tile; + + public VortexSound(TileEntity tile) { + super(new ResourceLocation("thaumichorizons:vortex")); + this.tile = tile; + this.repeat = true; + this.field_147665_h = 0; + this.volume = 1.0F; + } + + // Let me know if update needs to be cached or if that's a good idea or not for performance. + + @Override + public void update() { + if (tile == null || tile.isInvalid() || tile.getWorldObj() == null) { + this.donePlaying = true; + return; + } + + // follow tile + this.xPosF = tile.xCoord + 0.5F; + this.yPosF = tile.yCoord + 0.5F; + this.zPosF = tile.zCoord + 0.5F; + + // distance-based volume + EntityPlayer p = Minecraft.getMinecraft().thePlayer; + + if (p != null) { + double dist = p.getDistance(this.xPosF, this.yPosF, this.zPosF); + this.volume = Math.max(0.0F, 1.0F / (1.0F + (float) (dist / 8.0F))); + } + } + + public void markDone() { + this.donePlaying = true; + } + +} diff --git a/src/main/java/com/kentington/thaumichorizons/common/CommonProxy.java b/src/main/java/com/kentington/thaumichorizons/common/CommonProxy.java index 6dd094b..9220046 100644 --- a/src/main/java/com/kentington/thaumichorizons/common/CommonProxy.java +++ b/src/main/java/com/kentington/thaumichorizons/common/CommonProxy.java @@ -29,6 +29,7 @@ import com.kentington.thaumichorizons.common.tiles.TileSoulExtractor; import com.kentington.thaumichorizons.common.tiles.TileSoulforge; import com.kentington.thaumichorizons.common.tiles.TileVat; import com.kentington.thaumichorizons.common.tiles.TileVisDynamo; +import com.kentington.thaumichorizons.common.tiles.TileVortex; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.IGuiHandler; @@ -134,4 +135,8 @@ public class CommonProxy implements IGuiHandler { public void lightningBolt(final World worldObj, final double x, final double y, final double z, final int boltLength) {} + + public void playVortexSound(TileVortex tile) {} + + public void stopVortexSound(TileVortex tile) {} } diff --git a/src/main/java/com/kentington/thaumichorizons/common/tiles/TileVortex.java b/src/main/java/com/kentington/thaumichorizons/common/tiles/TileVortex.java index 098ffe0..c200c46 100644 --- a/src/main/java/com/kentington/thaumichorizons/common/tiles/TileVortex.java +++ b/src/main/java/com/kentington/thaumichorizons/common/tiles/TileVortex.java @@ -62,6 +62,7 @@ public class TileVortex extends TileThaumcraft implements IWandable, IAspectCont public boolean cheat; public ArrayList items; Thread ppThread; + private boolean soundStarted = false; public TileVortex() { this.aspects = new AspectList(); @@ -77,6 +78,11 @@ public class TileVortex extends TileThaumcraft implements IWandable, IAspectCont public void updateEntity() { super.updateEntity(); + if (this.worldObj != null && this.worldObj.isRemote && !soundStarted) { + ThaumicHorizons.proxy.playVortexSound(this); + soundStarted = true; + } + if (this.generating) { this.worldObj.createExplosion( null, @@ -572,4 +578,23 @@ public class TileVortex extends TileThaumcraft implements IWandable, IAspectCont public int containerContains(final Aspect tag) { return 0; } + + @Override + public void invalidate() { + super.invalidate(); + stopSound(); + } + + @Override + public void onChunkUnload() { + super.onChunkUnload(); + stopSound(); + } + + private void stopSound() { + if (this.worldObj != null && this.worldObj.isRemote) { + ThaumicHorizons.proxy.stopVortexSound(this); + } + soundStarted = false; + } } diff --git a/src/main/resources/assets/thaumichorizons/sounds.json b/src/main/resources/assets/thaumichorizons/sounds.json new file mode 100644 index 0000000..1c2a565 --- /dev/null +++ b/src/main/resources/assets/thaumichorizons/sounds.json @@ -0,0 +1,15 @@ +{ + + "vortex": { + + "category": "ambient", + + "sounds": [ + + { "name": "thaumichorizons:vortex", "stream": true } + + ] + + } + +} \ No newline at end of file diff --git a/src/main/resources/assets/thaumichorizons/sounds/vortex.ogg b/src/main/resources/assets/thaumichorizons/sounds/vortex.ogg new file mode 100644 index 0000000..e6b8fe2 Binary files /dev/null and b/src/main/resources/assets/thaumichorizons/sounds/vortex.ogg differ