Code cleanup
This commit is contained in:
parent
7a7024c5bb
commit
154ea3f6b5
2 changed files with 15 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue