missing class from previous commits (derp)

This commit is contained in:
octarine-noise
2014-08-12 23:11:28 +02:00
parent 97f528d426
commit f107fe0e1a

View File

@@ -0,0 +1,63 @@
package mods.betterfoliage.client;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
public class WindTracker {
public Random random = new Random();
public double targetX;
public double targetZ;
public double currentX;
public double currentZ;
public long nextChange = 0;
public void changeWind(World world) {
long changeTime = 120;
nextChange = world.getWorldInfo().getWorldTime() + changeTime;
double direction = 2.0 * Math.PI * random.nextDouble();
double speed = Math.abs(random.nextGaussian()) * 0.025;
if (world.isRaining()) speed += Math.abs(random.nextGaussian()) * 0.05;
targetX = Math.cos(direction) * speed;
targetZ = Math.sin(direction) * speed;
}
@SubscribeEvent
public void handleWorldTick(ClientTickEvent event) {
if (event.phase != TickEvent.Phase.START) return;
World world = Minecraft.getMinecraft().theWorld;
if (world == null) return;
// change target wind speed
if (world.getWorldInfo().getWorldTime() >= nextChange) changeWind(world);
// change current wind speed
double changeRate = world.isRaining() ? 0.00075 : 0.00025;
double deltaX = targetX - currentX;
if (deltaX < -changeRate) deltaX = -changeRate;
if (deltaX > changeRate) deltaX = changeRate;
double deltaZ = targetZ - currentZ;
if (deltaZ < -changeRate) deltaZ = -changeRate;
if (deltaZ > changeRate) deltaZ = changeRate;
currentX += deltaX;
currentZ += deltaZ;
}
@SubscribeEvent
public void handleWorldLoad(WorldEvent.Load event) {
if (event.world.isRemote) changeWind(event.world);
}
}