Some work on electric bolt fxs

This commit is contained in:
Calclavia 2013-08-01 23:07:56 -04:00
parent d6efc5540b
commit 7016ee0b76
5 changed files with 256 additions and 16 deletions

View file

@ -3,9 +3,11 @@
*/
package resonantinduction;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import resonantinduction.base.Vector3;
import resonantinduction.fx.FXElectricBolt;
import resonantinduction.render.BlockRenderingHandler;
import resonantinduction.render.RenderTesla;
import resonantinduction.tesla.TileEntityTesla;
@ -37,6 +39,6 @@ public class ClientProxy extends CommonProxy
@Override
public void renderElectricShock(World world, Vector3 start, Vector3 target, float r, float g, float b)
{
Minecraft.getMinecraft().effectRenderer.addEffect(new FXElectricBolt(world, start, target).setColor(r, g, b));
}
}

View file

@ -5,8 +5,10 @@ import java.util.Arrays;
import java.util.logging.Logger;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.ShapedOreRecipe;
import resonantinduction.tesla.BlockTesla;
import resonantinduction.tesla.TileEntityTesla;
import cpw.mods.fml.common.FMLLog;
@ -136,6 +138,11 @@ public class ResonantInduction
@EventHandler
public void preInit(FMLPostInitializationEvent evt)
{
/**
* Recipes
*/
/** by Jyzarc */
GameRegistry.addRecipe(new ShapedOreRecipe(blockTesla, "EEE", " C ", " I ", 'E', Item.eyeOfEnder, 'C', Item.redstone, 'I', Block.blockIron));
}

View file

@ -3,6 +3,7 @@
*/
package resonantinduction.base;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
/**
@ -25,11 +26,36 @@ public class Vector3
this(0, 0, 0);
}
public Vector3(double amount)
{
this(amount, amount, amount);
}
public Vector3(Vector3 clone)
{
this(clone.x, clone.y, clone.z);
}
public Vector3(TileEntity tileEntity)
{
this(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
}
public Vector3(Entity entity)
{
this(entity.posX, entity.posY, entity.posZ);
}
public Vector3 scale(double amount)
{
return this.scale(new Vector3(amount));
}
public Vector3 scale(Vector3 amount)
{
return new Vector3(this.x * amount.x, this.y * amount.y, this.z * amount.z);
}
public Vector3 difference(Vector3 compare)
{
return new Vector3(compare.x - this.x, compare.y - this.y, compare.z - this.z);
@ -50,4 +76,55 @@ public class Vector3
Vector3 difference = this.difference(compare);
return difference.getMagnitude();
}
/**
* Cross product functions
*
* @return The cross product between this vector and another.
*/
public Vector3 crossProduct(Vector3 vec2)
{
return new Vector3(this.y * vec2.z - this.z * vec2.y, this.z * vec2.x - this.x * vec2.z, this.x * vec2.y - this.y * vec2.x);
}
public Vector3 xCrossProduct()
{
return new Vector3(0.0D, this.z, -this.y);
}
public Vector3 zCrossProduct()
{
return new Vector3(-this.y, this.x, 0.0D);
}
public double dotProduct(Vector3 vec2)
{
return this.x * vec2.x + this.y * vec2.y + this.z * vec2.z;
}
/**
* @return The perpendicular vector.
*/
public Vector3 getPerpendicular()
{
if (this.z == 0.0F)
{
return this.zCrossProduct();
}
return this.xCrossProduct();
}
/**
* @return True if this Vector3 is zero.
*/
public boolean isZero()
{
return (this.x == 0.0F) && (this.y == 0.0F) && (this.z == 0.0F);
}
public Vector3 translate(Vector3 offset)
{
return new Vector3(this.x + offset.x, this.y + offset.y, this.z + offset.z);
}
}

View file

@ -0,0 +1,169 @@
/**
*
*/
package resonantinduction.fx;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import resonantinduction.ResonantInduction;
import resonantinduction.base.Vector3;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Electric shock Fxs.
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class FXElectricBolt extends EntityFX
{
public static final ResourceLocation FADED_SPHERE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "fadedSphere.png");
public static final ResourceLocation PARTICLE_RESOURCE = new ResourceLocation("textures/particle/particles.png");
private final float boltWidth = 0.05f;
private BoltPoint start;
private BoltPoint target;
private double boltLength;
private int segmentCount;
private Set<BoltSegment> segments = new HashSet<BoltSegment>();
public FXElectricBolt(World world, Vector3 start, Vector3 target)
{
super(world, start.x, start.y, start.z);
this.start = new BoltPoint(target);
this.target = new BoltPoint(target);
this.boltLength = start.distance(target);
this.segments.add(new BoltSegment(this.start, this.target));
}
public FXElectricBolt setColor(float r, float g, float b)
{
this.particleRed = r;
this.particleGreen = g;
this.particleBlue = b;
return this;
}
public void calculate()
{
}
@Override
public void onUpdate()
{
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
if (this.particleAge++ >= this.particleMaxAge)
{
this.setDead();
}
}
@Override
public void renderParticle(Tessellator tessellator, float partialFrame, float cosYaw, float cosPitch, float sinYaw, float sinSinPitch, float cosSinPitch)
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
tessellator.draw();
FMLClientHandler.instance().getClient().renderEngine.func_110577_a(FADED_SPHERE);
GL11.glPushMatrix();
/**
* Do rendering here.
*/
GL11.glDepthMask(true);
GL11.glEnable(3042);
Vector3 playerVector = new Vector3(sinYaw * -cosPitch, -cosSinPitch / cosYaw, cosYaw * cosPitch);
int renderLength = (int) (this.particleAge + partialFrame + this.boltLength * 3) / (int) (this.boltLength * 3) * this.segmentCount;
for (BoltSegment segment : this.segments)
{
// TODO: Weight? Scale
double width = this.width * (new Vector3(player).distance(segment.start) / 5 + 1);
Vector3 prevDiff = playerVector.crossProduct(segment.prevDiff).scale(this.width);
Vector3 nextDiff = playerVector.crossProduct(segment.nextDiff).scale(this.width);
Vector3 renderStart = segment.start;
Vector3 renderEnd = segment.end;
tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha);
float rx1 = (float) (renderStart.x - interpPosX);
float ry1 = (float) (renderStart.y - interpPosY);
float rz1 = (float) (renderStart.z - interpPosZ);
float rx2 = (float) (renderEnd.x - interpPosX);
float ry2 = (float) (renderEnd.y - interpPosY);
float rz2 = (float) (renderEnd.z - interpPosZ);
tessellator.addVertexWithUV(rx2 - nextDiff.x, ry2 - nextDiff.y, rz2 - nextDiff.z, 0.5D, 0.0D);
tessellator.addVertexWithUV(rx1 - prevDiff.x, ry1 - prevDiff.y, rz1 - prevDiff.z, 0.5D, 0.0D);
tessellator.addVertexWithUV(rx1 + prevDiff.x, ry1 + prevDiff.y, rz1 + prevDiff.z, 0.5D, 1.0D);
tessellator.addVertexWithUV(rx2 + nextDiff.x, ry2 + nextDiff.y, rz2 + nextDiff.z, 0.5D, 1.0D);
}
GL11.glDisable(3042);
GL11.glDepthMask(false);
GL11.glPopMatrix();
FMLClientHandler.instance().getClient().renderEngine.func_110577_a(PARTICLE_RESOURCE);
tessellator.startDrawingQuads();
}
@Override
public boolean shouldRenderInPass(int pass)
{
return pass == 2;
}
public class BoltPoint extends Vector3
{
public Vector3 base;
public Vector3 offset;
public BoltPoint(Vector3 base, Vector3 offset)
{
super(base.translate(offset));
this.base = base;
this.offset = offset;
}
public BoltPoint(Vector3 base)
{
this(base, new Vector3());
}
}
public class BoltSegment
{
public BoltPoint start;
public BoltPoint end;
public BoltSegment prev;
public BoltSegment next;
public Vector3 prevDiff;
public Vector3 nextDiff;
public BoltSegment(BoltPoint start, BoltPoint end)
{
this.start = start;
this.end = end;
}
}
}

View file

@ -1,15 +0,0 @@
/**
*
*/
package resonantinduction.fx;
/**
* Electric shock Fxs.
*
* @author Calclavia
*
*/
public class FxElectric
{
}