Files
Electro-Magic-Tools/src/main/java/emt/util/EMTRandomHelper.java
T

83 lines
2.1 KiB
Java
Raw Normal View History

2016-03-16 17:49:28 +03:00
package emt.util;
2014-09-28 22:40:24 +02:00
2015-07-25 01:12:33 +03:00
import ic2.api.item.ElectricItem;
2015-07-11 13:32:13 +03:00
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
2014-09-28 22:40:24 +02:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
2016-04-04 14:49:42 +03:00
import java.util.ArrayList;
2015-09-13 15:33:13 +03:00
import java.util.Locale;
2016-04-04 14:49:42 +03:00
import java.util.Random;
2015-09-13 15:33:13 +03:00
2015-12-14 21:29:29 +03:00
public class EMTRandomHelper {
2015-12-06 19:47:41 +03:00
public static ItemStack getChargedItem(Item item, int charge) {
ItemStack stack = new ItemStack(item);
2015-07-25 01:12:33 +03:00
ElectricItem.manager.charge(stack, charge, charge, true, false);
return stack;
2015-12-06 19:47:41 +03:00
}
2016-04-04 14:49:42 +03:00
public static class Bolt {
Random rnd = new Random();
public ArrayList<Point> points = new ArrayList<Point>();
public float angleZ = 0;
public float angleY = 0;
float dist = 0;
float length = 0;
float height = 0;
public Bolt(float dist, float length, float height) {
this.dist = dist;
this.length = (length / 2f) + (rnd.nextInt((int) (length / 2f)));
this.height = height;
regenerate(this.dist, this.length, this.height);
}
public void regenerate() {
regenerate(dist, length, height);
}
public void regenerate(float dist, float length, float height) {
points.clear();
angleZ = rnd.nextInt(360);
angleY = rnd.nextInt(360);
for (int i = 0; i < length / dist; i++) {
float x = i * dist;
float prevY = i == 0 ? 0 : points.get(i - 1).y;
float prevZ = i == 0 ? 0 : points.get(i - 1).z;
float y = prevY + (rnd.nextInt((int) height) - (height / 2));
float z = prevZ + (rnd.nextInt((int) height) - (height / 2));
points.add(new Point(x, y, z));
}
}
}
public static class Point {
public float x = 0;
public float y = 0;
public float z = 0;
public Point(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point(double x, double y, double z) {
this.x = (float) x;
this.y = (float) y;
this.z = (float) z;
}
}
2014-09-28 22:40:24 +02:00
}