From 154ea3f6b563c4a8ad2d3faa5c4df87d3f11ab23 Mon Sep 17 00:00:00 2001 From: LemADEC Date: Sat, 11 Feb 2017 18:21:45 +0100 Subject: [PATCH] Code cleanup --- .../block/detection/TileEntitySiren.java | 2 +- .../warpdrive/{ => client}/SirenSound.java | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) rename src/main/java/cr0s/warpdrive/{ => client}/SirenSound.java (84%) diff --git a/src/main/java/cr0s/warpdrive/block/detection/TileEntitySiren.java b/src/main/java/cr0s/warpdrive/block/detection/TileEntitySiren.java index 5f5e7f3d..3aaaf2ff 100644 --- a/src/main/java/cr0s/warpdrive/block/detection/TileEntitySiren.java +++ b/src/main/java/cr0s/warpdrive/block/detection/TileEntitySiren.java @@ -2,7 +2,7 @@ package cr0s.warpdrive.block.detection; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import cr0s.warpdrive.SirenSound; +import cr0s.warpdrive.client.SirenSound; import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.block.TileEntityAbstractBase; import net.minecraft.client.Minecraft; diff --git a/src/main/java/cr0s/warpdrive/SirenSound.java b/src/main/java/cr0s/warpdrive/client/SirenSound.java similarity index 84% rename from src/main/java/cr0s/warpdrive/SirenSound.java rename to src/main/java/cr0s/warpdrive/client/SirenSound.java index 706bace5..f8b9b509 100644 --- a/src/main/java/cr0s/warpdrive/SirenSound.java +++ b/src/main/java/cr0s/warpdrive/client/SirenSound.java @@ -1,15 +1,18 @@ -package cr0s.warpdrive; +package cr0s.warpdrive.client; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.MovingSound; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; +@SideOnly(Side.CLIENT) public class SirenSound extends MovingSound { ResourceLocation resource; float range; float x, y, z; - + /**x, y and z are the position of the tile entity. the actual sound is broadcast from xPosF, yPosF, zPosF, which is the location of the player. The volume is adjusted according to the distance to x, y, z. @@ -21,26 +24,27 @@ public class SirenSound extends MovingSound { 4. Doesn't completely spazz out the instant you try to actually use it.*/ public SirenSound(ResourceLocation resource, float range, float x, float y, float z) { super(resource); - + this.resource = resource; this.range = range; - + this.x = x; this.y = y; this.z = z; - + this.xPosF = x; this.yPosF = y; this.zPosF = z; } - + + @Override public void update() { EntityPlayer player = Minecraft.getMinecraft().thePlayer; - + this.xPosF = (float) player.posX; this.yPosF = (float) player.posY; this.zPosF = (float) player.posZ; - + if (player.getDistance(x, y, z) > range) { this.volume = 0.0F; } else { @@ -48,8 +52,8 @@ public class SirenSound extends MovingSound { this.volume = 1.0F - scaleTo((float) player.getDistance(x, y, z), 0.0F, range, 0.0F, 1.0F); } } - - private float scaleTo(float num, float oldMin, float oldMax, float newMin, float newMax) { + + private float scaleTo(final float num, final float oldMin, final float oldMax, final float newMin, final float newMax) { return ((newMax - newMin)*(num - oldMin)) / (oldMax - oldMin) + newMin; } }