Skip to content
Permalink
Browse files

Tesla coil arcs now hold for 2 seconds on fluorescent lights and set …

…an output voltage of 1MV
  • Loading branch information...
Ri5ux Ri5ux
Ri5ux authored and Ri5ux committed Jul 16, 2019
1 parent d8d75b8 commit 0d13dbe824086382939e0fd60c2d1ac7d0909d4f
Showing with 68 additions and 15 deletions.
  1. +68 −15 src/main/java/org/avp/tile/TileEntityTeslaCoil.java
@@ -14,22 +14,28 @@
import com.asx.mdx.lib.world.tile.IRotatableXAxis;
import com.asx.mdx.lib.world.tile.IRotatableYAxis;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class TileEntityTeslaCoil extends TileEntityElectrical implements IVoltageProvider, IVoltageReceiver, IRotatableYAxis, IRotatableXAxis
{
private EnumFacing rotationX;
private EnumFacing rotationY;
private EnumFacing rotationX;
private EnumFacing rotationY;
private Pos sustainArcPos;
private long sustainArcTimestamp;
private static final int SUSTAIN_TIME = 20 * 2;

public TileEntityTeslaCoil()
{
super(false);
this.srcVoltage = 1000000;
}

@Override
@@ -126,7 +132,7 @@ public Pos getArcOrigin()
double x = 0;
double z = 0;
double y = 0;

if (this.rotationY == EnumFacing.DOWN)
{
x = 0.5D + Math.cos(angle) * radius;
@@ -170,29 +176,68 @@ else if (this.rotationY == EnumFacing.NORTH && this.rotationX == EnumFacing.SOUT
@Override
public void tryElectricArc()
{
if (this.getVoltage() > 0 && canArc())
if (this.getVoltage() > 0 && canArc() || this.getVoltage() > 0 && this.sustainArcPos != null)
{
Random rand = new Random();
float m = 1.75F;
Pos origin = this.getArcOrigin();
int rng = 8;
Pos t = origin.add(world.rand.nextInt(rng) - world.rand.nextInt(rng), world.rand.nextInt(rng) - world.rand.nextInt(rng), world.rand.nextInt(rng) - world.rand.nextInt(rng));
Pos t = null;

if (this.sustainArcTimestamp > 0 && world.getWorldTime() - this.sustainArcTimestamp > SUSTAIN_TIME || this.getWorld().getWorldTime() - this.sustainArcTimestamp < 0)
{
this.sustainArcPos = null;
this.sustainArcTimestamp = 0;
}

if (this.sustainArcPos != null)
{
t = sustainArcPos;
}
else
{
t = origin.add(world.rand.nextInt(rng) - world.rand.nextInt(rng), world.rand.nextInt(rng) - world.rand.nextInt(rng), world.rand.nextInt(rng) - world.rand.nextInt(rng));
}

Entity target = Entities.getRandomEntityInCoordsRange(world, EntityLivingBase.class, new Pos(this), (int) Math.floor(rng));
double distG = origin.distanceFrom(t);
double distE = 1000;
double dist = distG;
double arcWidth = MDXMath.map((double) this.voltage, 600D, 10000D, 0.05D, 0.5D);
float damageMult = (float) (arcWidth * 100F);

Block b = t.getBlock(this.world);

if (b != null)
{
TileEntity tile = this.world.getTileEntity(t.blockPos());

if (tile != null)
{
if (tile instanceof TileEntityCCFLTube)
{
TileEntityCCFLTube tube = (TileEntityCCFLTube) tile;

if (this.sustainArcPos == null)
{
this.sustainArcTimestamp = world.getWorldTime();
this.sustainArcPos = t = t.add(-0.5, -1, -0.5);
}

tube.setVoltage(this.srcVoltage);
}
}
}

if (target != null)
{
Pos p = new Pos(target.getPosition()).add(target.width / 2, 0, target.width / 2);
distE = target.getDistance(origin.x, origin.y, origin.z);
t = p;
m = 8F;
dist = distE;
target.attackEntityFrom(DamageSources.electricity, damageMult);
target.setFire(3);
// Pos p = new Pos(target.getPosition()).add(target.width / 2, 0, target.width / 2);
// distE = target.getDistance(origin.x, origin.y, origin.z);
// t = p;
// m = 8F;
// dist = distE;
// target.attackEntityFrom(DamageSources.electricity, damageMult);
// target.setFire(3);
}

if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
@@ -205,13 +250,21 @@ public void tryElectricArc()
@SideOnly(Side.CLIENT)
public void spawnArc(Pos t, float m, Random rand, double dist, Pos origin, double arcWidth)
{
boolean holdArc = sustainArcTimestamp > 0 && this.world.getWorldTime() - sustainArcTimestamp < 1;
float targetX = (float) (t.x + (rand.nextFloat() / m) - (rand.nextFloat() / m));
float targetY = (float) (t.y + 1);
float targetZ = (float) (t.z + (rand.nextFloat() / m) - (rand.nextFloat() / m));
int age = 1;
int age = holdArc ? SUSTAIN_TIME : 1;
int color = 0xFF8866CC;
EntityFXElectricArc arc = new EntityFXElectricArc(world, origin.x, origin.y, origin.z, targetX, targetY, targetZ, age, 6F, 0.065F, (float) 0.2F, color);
Game.minecraft().effectRenderer.addEffect(arc);

if (sustainArcTimestamp == 0 && !holdArc || holdArc)
{
if (this.world.isRemote)
{
EntityFXElectricArc arc = new EntityFXElectricArc(world, origin.x, origin.y, origin.z, targetX, targetY, targetZ, age, 6F, 0.065F, (float) 0.2F, color);
Game.minecraft().effectRenderer.addEffect(arc);
}
}
}

@Override

0 comments on commit 0d13dbe

Please sign in to comment.
You can’t perform that action at this time.