mirror of
https://github.com/GTNewHorizons/ThaumicHorizons.git
synced 2026-11-27 23:45:57 +00:00
Add client-side vortex sound in TileVortex (#96)
This commit is contained in:
1 parent
76258cd038
commit
47c06267c1
9 files changed
+150
-4
No files matched your search
+2
-2
@@ -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}
|
||||
}
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.42'
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TileCoord, VortexSound> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ public class TileVortex extends TileThaumcraft implements IWandable, IAspectCont
|
||||
public boolean cheat;
|
||||
public ArrayList<ItemStack> 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
|
||||
"vortex": {
|
||||
|
||||
"category": "ambient",
|
||||
|
||||
"sounds": [
|
||||
|
||||
{ "name": "thaumichorizons:vortex", "stream": true }
|
||||
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user