Get lasers rendering. I've yet to proxy it off, so THIS WILL CRASH DEDICATED SERVERS

This commit is contained in:
Ben Spiers 2014-07-22 03:39:36 +01:00
parent 733da7396f
commit e35a673c8b
3 changed files with 99 additions and 4 deletions

View file

@ -1,13 +1,17 @@
package mekanism.api.lasers;
import mekanism.api.Coord4D;
import mekanism.client.entity.EntityLaser;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityNoteFX;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.client.FMLClientHandler;
public class LaserManager
{
@ -35,16 +39,16 @@ public class LaserManager
}
}
renderLaser(from, new Coord4D(mop.blockX, mop.blockY, mop.blockZ));
renderLaser(world, from, new Coord4D(mop.blockX, mop.blockY, mop.blockZ), direction);
}
else
{
renderLaser(from, to);
renderLaser(world, from, to, direction);
}
}
public static void renderLaser(Coord4D from, Coord4D to)
public static void renderLaser(World world, Coord4D from, Coord4D to, ForgeDirection direction)
{
//TODO Particle effects
Minecraft.getMinecraft().effectRenderer.addEffect(new EntityLaser(world, from, to, direction));
}
}

View file

@ -0,0 +1,91 @@
package mekanism.client.entity;
import mekanism.api.Coord4D;
import mekanism.api.Pos3D;
import mekanism.client.render.MekanismRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.client.FMLClientHandler;
import org.lwjgl.opengl.GL11;
public class EntityLaser extends EntityFX
{
double length;
ForgeDirection direction;
public EntityLaser(World world, Coord4D start, Coord4D end, ForgeDirection direction)
{
super(world, (start.xCoord + end.xCoord)/2D + 0.5D, (start.yCoord + end.yCoord)/2D + 0.5D, (start.zCoord+end.zCoord)/2D + 0.5D);
particleMaxAge = 1;
particleRed = 1;
particleGreen = 0;
particleBlue = 0;
particleAlpha = 0.3F;
particleScale = 0.1F;
length = new Pos3D(end).distance(new Pos3D(start));
this.direction = direction;
}
@Override
public void renderParticle(Tessellator tessellator, float partialTick, float rotationX, float rotationXZ, float rotationZ, float rotationYZ, float rotationXY)
{
tessellator.draw();
GL11.glPushMatrix();
Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("mekanism", "particles/laser.png"));
float newX = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)partialTick - interpPosX);
float newY = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)partialTick - interpPosY);
float newZ = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTick - interpPosZ);
GL11.glTranslatef(newX, newY, newZ);
switch(direction)
{
case UP:
case DOWN:
default:
break;
case WEST:
case EAST:
GL11.glRotated(90, 0, 0, 1);
break;
case NORTH:
case SOUTH:
GL11.glRotated(90, 1, 0, 0);
break;
}
GL11.glRotated(45, 0, 1, 0);
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha);
tessellator.addVertexWithUV(-particleScale, -length/2, 0, 0, 0);
tessellator.addVertexWithUV(-particleScale, length/2, 0, 0, 1);
tessellator.addVertexWithUV(particleScale, length/2, 0, 1, 1);
tessellator.addVertexWithUV(particleScale, -length/2, 0, 1, 0);
tessellator.draw();
GL11.glRotated(90, 0, 1, 0);
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha);
tessellator.addVertexWithUV(-particleScale, -length/2, 0, 0, 0);
tessellator.addVertexWithUV(-particleScale, length/2, 0, 0, 1);
tessellator.addVertexWithUV(particleScale, length/2, 0, 1, 1);
tessellator.addVertexWithUV(particleScale, -length/2, 0, 1, 0);
tessellator.draw();
GL11.glPopMatrix();
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismRenderer.getBlocksTexture());
tessellator.startDrawingQuads();
}
public int getFXLayer()
{
return 1;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B