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.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import cr0s.warpdrive.SirenSound;
|
import cr0s.warpdrive.client.SirenSound;
|
||||||
import cr0s.warpdrive.WarpDrive;
|
import cr0s.warpdrive.WarpDrive;
|
||||||
import cr0s.warpdrive.block.TileEntityAbstractBase;
|
import cr0s.warpdrive.block.TileEntityAbstractBase;
|
||||||
import net.minecraft.client.Minecraft;
|
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.Minecraft;
|
||||||
import net.minecraft.client.audio.MovingSound;
|
import net.minecraft.client.audio.MovingSound;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public class SirenSound extends MovingSound {
|
public class SirenSound extends MovingSound {
|
||||||
ResourceLocation resource;
|
ResourceLocation resource;
|
||||||
float range;
|
float range;
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
/**x, y and z are the position of the tile entity. the actual sound is broadcast from
|
/**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.
|
xPosF, yPosF, zPosF, which is the location of the player.
|
||||||
The volume is adjusted according to the distance to x, y, z.
|
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.*/
|
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) {
|
public SirenSound(ResourceLocation resource, float range, float x, float y, float z) {
|
||||||
super(resource);
|
super(resource);
|
||||||
|
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
this.range = range;
|
this.range = range;
|
||||||
|
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
|
|
||||||
this.xPosF = x;
|
this.xPosF = x;
|
||||||
this.yPosF = y;
|
this.yPosF = y;
|
||||||
this.zPosF = z;
|
this.zPosF = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||||
|
|
||||||
this.xPosF = (float) player.posX;
|
this.xPosF = (float) player.posX;
|
||||||
this.yPosF = (float) player.posY;
|
this.yPosF = (float) player.posY;
|
||||||
this.zPosF = (float) player.posZ;
|
this.zPosF = (float) player.posZ;
|
||||||
|
|
||||||
if (player.getDistance(x, y, z) > range) {
|
if (player.getDistance(x, y, z) > range) {
|
||||||
this.volume = 0.0F;
|
this.volume = 0.0F;
|
||||||
} else {
|
} 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);
|
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;
|
return ((newMax - newMin)*(num - oldMin)) / (oldMax - oldMin) + newMin;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue