|
1 |
| -package mods.eln.sound; |
2 |
| - |
3 |
| -import mods.eln.client.ClientProxy; |
4 |
| -import mods.eln.client.SoundLoader; |
5 |
| -import mods.eln.misc.Utils; |
6 |
| -import net.minecraft.client.Minecraft; |
7 |
| -import net.minecraft.entity.player.EntityPlayer; |
8 |
| - |
9 |
| -public class SoundClient { |
10 |
| - /*public static void playFromBlock(World world, int x, int y, int z, String track, float volume, float pitch, float rangeNominal, float rangeMax) { |
11 |
| - play(world, x + 0.5, y + 0.5, z + 0.5, track, volume, pitch, rangeNominal, rangeMax); |
12 |
| - }*/ |
13 |
| - |
14 |
| - public static void play(SoundCommand p) { |
15 |
| - ClientProxy.soundClientEventListener.currentUuid = p.uuid; //trolilole |
16 |
| - |
17 |
| - EntityPlayer player = Minecraft.getMinecraft().thePlayer; |
18 |
| - if (p.world.provider.dimensionId != player.dimension) return; |
19 |
| - double distance = Math.sqrt(Math.pow(p.x - player.posX, 2) + Math.pow(p.y - player.posY, 2) + Math.pow(p.z - player.posZ, 2)); |
20 |
| - if (distance >= p.rangeMax) return; |
21 |
| - float distanceFactor = 1; |
| 1 | +package mods.eln.sound |
| 2 | + |
| 3 | +import mods.eln.client.ClientProxy |
| 4 | +import mods.eln.client.SoundLoader |
| 5 | +import mods.eln.misc.Utils.TraceRayWeightOpaque |
| 6 | +import mods.eln.misc.Utils.println |
| 7 | +import mods.eln.misc.Utils.traceRay |
| 8 | +import net.minecraft.client.Minecraft |
| 9 | +import net.minecraft.entity.player.EntityPlayer |
| 10 | +import kotlin.math.pow |
| 11 | +import kotlin.math.sqrt |
| 12 | + |
| 13 | +object SoundClient { |
| 14 | + fun play(p: SoundCommand) { |
| 15 | + ClientProxy.soundClientEventListener.currentUuid = p.uuid |
| 16 | + |
| 17 | + val player: EntityPlayer = Minecraft.getMinecraft().thePlayer |
| 18 | + if (p.world!!.provider.dimensionId != player.dimension) return |
| 19 | + val distance = sqrt((p.x - player.posX).pow(2.0) + (p.y - player.posY).pow(2.0) + (p.z - player.posZ).pow(2.0)) |
| 20 | + if (distance >= p.rangeMax) return |
| 21 | + var distanceFactor = 1f |
22 | 22 | if (distance > p.rangeNominal) {
|
23 |
| - distanceFactor = (float) ((p.rangeMax - distance) / (p.rangeMax - p.rangeNominal)); |
| 23 | + distanceFactor = ((p.rangeMax - distance) / (p.rangeMax - p.rangeNominal)).toFloat() |
24 | 24 | }
|
25 | 25 |
|
26 |
| - float blockFactor = Utils.traceRay(p.world, player.posX, player.posY, player.posZ, p.x, p.y, p.z, new Utils.TraceRayWeightOpaque()) * p.blockFactor; |
| 26 | + val blockFactor = traceRay( |
| 27 | + p.world!!, |
| 28 | + player.posX, |
| 29 | + player.posY, |
| 30 | + player.posZ, |
| 31 | + p.x, |
| 32 | + p.y, |
| 33 | + p.z, |
| 34 | + TraceRayWeightOpaque() |
| 35 | + ) * p.blockFactor |
27 | 36 |
|
28 |
| - int trackCount = SoundLoader.getTrackCount(p.track); |
| 37 | + val trackCount = SoundLoader.getTrackCount(p.track) |
29 | 38 |
|
30 | 39 | if (trackCount == 1) {
|
31 |
| - float temp = 1.0f / (1 + blockFactor); |
32 |
| - p.volume *= Math.pow(temp, 2); |
33 |
| - p.volume *= distanceFactor; |
34 |
| - if (p.volume <= 0) return; |
| 40 | + val temp = 1.0f / (1 + blockFactor) |
| 41 | + p.volume *= temp.pow(2.0f) |
| 42 | + p.volume *= distanceFactor |
| 43 | + if (p.volume <= 0) return |
35 | 44 |
|
36 |
| - p.world.playSound(player.posX + 2 * (p.x - player.posX) / distance, player.posY + 2 * (p.y - player.posY) / distance, player.posZ + 2 * (p.z - player.posZ) / distance, p.track, p.volume, p.pitch, false); |
| 45 | + p.world!!.playSound( |
| 46 | + player.posX + 2 * (p.x - player.posX) / distance, |
| 47 | + player.posY + 2 * (p.y - player.posY) / distance, |
| 48 | + player.posZ + 2 * (p.z - player.posZ) / distance, |
| 49 | + p.track, |
| 50 | + p.volume, |
| 51 | + p.pitch, |
| 52 | + false |
| 53 | + ) |
37 | 54 | } else {
|
38 |
| - for (int idx = 0; idx < trackCount; idx++) { |
39 |
| - float bandVolume = p.volume; |
40 |
| - bandVolume *= distanceFactor; |
41 |
| - float normalizedBlockFactor = blockFactor; |
42 |
| - |
43 |
| - bandVolume -= ((trackCount - 1 - idx) / (trackCount - 1f) + 0.2) * normalizedBlockFactor; |
44 |
| - Utils.println(bandVolume); |
45 |
| - p.world.playSound(player.posX + 2 * (p.x - player.posX) / distance, player.posY + 2 * (p.y - player.posY) / distance, player.posZ + 2 * (p.z - player.posZ) / distance, p.track + "_" + idx + "x", bandVolume, p.pitch, false); |
| 55 | + for (idx in 0 until trackCount) { |
| 56 | + var bandVolume = p.volume |
| 57 | + bandVolume *= distanceFactor |
| 58 | + |
| 59 | + bandVolume -= (((trackCount - 1 - idx) / (trackCount - 1f) + 0.2) * blockFactor).toFloat() |
| 60 | + println(bandVolume) |
| 61 | + p.world!!.playSound( |
| 62 | + player.posX + 2 * (p.x - player.posX) / distance, |
| 63 | + player.posY + 2 * (p.y - player.posY) / distance, |
| 64 | + player.posZ + 2 * (p.z - player.posZ) / distance, |
| 65 | + p.track + "_" + idx + "x", |
| 66 | + bandVolume, |
| 67 | + p.pitch, |
| 68 | + false |
| 69 | + ) |
46 | 70 | }
|
47 | 71 | }
|
48 | 72 |
|
49 |
| - ClientProxy.soundClientEventListener.currentUuid = null; |
| 73 | + ClientProxy.soundClientEventListener.currentUuid = null |
50 | 74 | }
|
51 | 75 | }
|
0 commit comments