diff --git a/src/main/java/mekanism/api/lasers/LaserManager.java b/src/main/java/mekanism/api/lasers/LaserManager.java index 1bfd1d134..08cfd52d2 100644 --- a/src/main/java/mekanism/api/lasers/LaserManager.java +++ b/src/main/java/mekanism/api/lasers/LaserManager.java @@ -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)); } } diff --git a/src/main/java/mekanism/client/entity/EntityLaser.java b/src/main/java/mekanism/client/entity/EntityLaser.java new file mode 100644 index 000000000..61372dbce --- /dev/null +++ b/src/main/java/mekanism/client/entity/EntityLaser.java @@ -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; + } +} diff --git a/src/main/resources/assets/mekanism/particles/laser.png b/src/main/resources/assets/mekanism/particles/laser.png new file mode 100644 index 000000000..d2ddfa721 Binary files /dev/null and b/src/main/resources/assets/mekanism/particles/laser.png differ