Added Laser Relay Renderer.

Differently than originally planned, but it works and looks nice.
Thanks to xdjackiexd though
This commit is contained in:
Ellpeck 2015-10-26 22:28:49 +01:00
parent 0b3288d002
commit f520c87d94
6 changed files with 28 additions and 89 deletions

View file

@ -10,15 +10,9 @@
package ellpeck.actuallyadditions.blocks.render;
import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler;
import ellpeck.actuallyadditions.tile.TileEntityLaserRelay;
import ellpeck.actuallyadditions.util.WorldPos;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
/**
* Made by Canitzp.
* Thanks. Seriously. It looks really awesome. I don't think I could do this.
@ -185,21 +179,6 @@ public class ModelLaserRelay extends ModelBaseAA{
return "modelLaserRelay";
}
@Override
public void renderExtra(float f, TileEntity tile){
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
WorldPos firstWP = new WorldPos(relay.getWorldObj(), relay.xCoord, relay.yCoord, relay.zCoord);
ArrayList<LaserRelayConnectionHandler.ConnectionPair> network = LaserRelayConnectionHandler.getInstance().getNetworkFor(firstWP);
if(network != null){
for(LaserRelayConnectionHandler.ConnectionPair aPair : network){
TileEntityLaserRelay firstRelay = (TileEntityLaserRelay) aPair.firstRelay.getTileEntity();
if(aPair.contains(firstWP) && aPair.firstRelay.isEqual(firstWP)){
firstRelay.drawLine(aPair.firstRelay, aPair.secondRelay);
}
}
}
}
@Override
public boolean doesRotate(){
return true;

View file

@ -11,7 +11,6 @@
package ellpeck.actuallyadditions.blocks.render;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
@ -54,11 +53,7 @@ public class RenderLaserRelay extends RenderTileEntity{
}
theModel.render(0.0625F);
//A Random texture, so it is a smooth Laser!
bindTexture(new ResourceLocation("actuallyadditions:textures/blocks/blockBreaker.png"));
theModel.renderExtra(0.0625F, tile);
GL11.glPopMatrix();
}
}

View file

@ -60,6 +60,7 @@ public class ItemLaserWrench extends Item implements IActAddItemOrBlock{
}
else{
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".laser.cantConnect.desc")));
ItemPhantomConnector.clearStorage(stack);
}
}
}

View file

@ -83,7 +83,7 @@ public class ItemPhantomConnector extends Item implements IActAddItemOrBlock{
int y = tag.getInteger("YCoordOfTileStored");
int z = tag.getInteger("ZCoordOfTileStored");
World world = DimensionManager.getWorld(tag.getInteger("WorldOfTileStored"));
if(x != 0 && y != 0 && z != 0 && world != null){
if(!(x == 0 && y == 0 && z == 0) && world != null){
return new WorldPos(world, x, y, z);
}
}

View file

@ -13,20 +13,16 @@ package ellpeck.actuallyadditions.tile;
import cofh.api.energy.IEnergyReceiver;
import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler;
import ellpeck.actuallyadditions.util.WorldPos;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
public class TileEntityLaserRelay extends TileEntityBase implements IEnergyReceiver{
private GLColor laserColor = GLColor.RED_PURE;
@Override
public void invalidate(){
super.invalidate();
@ -36,8 +32,27 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
}
@Override
public boolean canUpdate(){
return false;
public void updateEntity(){
if(this.worldObj.isRemote){
if(this.worldObj.rand.nextInt(4) == 0){
WorldPos thisPos = new WorldPos(this.getWorldObj(), this.xCoord, this.yCoord, this.zCoord);
ArrayList<LaserRelayConnectionHandler.ConnectionPair> network = LaserRelayConnectionHandler.getInstance().getNetworkFor(thisPos);
if(network != null){
for(LaserRelayConnectionHandler.ConnectionPair aPair : network){
if(aPair.contains(thisPos) && thisPos.isEqual(aPair.firstRelay)){
int difX = aPair.firstRelay.getX()-aPair.secondRelay.getX();
int difY = aPair.firstRelay.getY()-aPair.secondRelay.getY();
int difZ = aPair.firstRelay.getZ()-aPair.secondRelay.getZ();
double distance = aPair.firstRelay.toVec().distanceTo(aPair.secondRelay.toVec());
for(double i = 0; i <= 1; i += 1/(distance*4)){
this.worldObj.spawnParticle("reddust", (difX*i)+aPair.secondRelay.getX()+0.5, (difY*i)+aPair.secondRelay.getY()+0.5, (difZ*i)+aPair.secondRelay.getZ()+0.5, 0, 0, 0);
}
}
}
}
}
}
}
@Override
@ -100,60 +115,4 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
public boolean canConnectEnergy(ForgeDirection from){
return true;
}
public void drawLine(WorldPos firstPos, WorldPos secondPos){
double x = firstPos.getX() - secondPos.getX();
double y = firstPos.getY() - secondPos.getY() + 1;
double z = -(firstPos.getZ() - secondPos.getZ());
double relativePlayerBlockLocation = Minecraft.getMinecraft().thePlayer.posY - firstPos.getY();
float f;
if(relativePlayerBlockLocation < 10) f=5;
else if(relativePlayerBlockLocation < 20 && relativePlayerBlockLocation > 10) f = 4;
else if(relativePlayerBlockLocation < 30 && relativePlayerBlockLocation > 20) f = 3;
else if(relativePlayerBlockLocation < 40 && relativePlayerBlockLocation > 30) f = 2;
else if(relativePlayerBlockLocation < 50 && relativePlayerBlockLocation > 40) f = 1;
else f=1;
GL11.glPushMatrix();
GL11.glLineWidth(f);
GL11.glBegin(GL11.GL_LINE_STRIP);
{
GL11.glColor3f(this.laserColor.getRed(), this.laserColor.getGreen(), this.laserColor.getBlue());
GL11.glVertex3d(x, y, z);
GL11.glVertex3d(0, 1, 0);
}
GL11.glEnd();
GL11.glLineWidth(1);
GL11.glPopMatrix();
}
public void changeLineColor(GLColor color){this.laserColor = color;}
//Colors for the Laser:
public enum GLColor{
RED_PURE(1.0F, 0, 0),
GREEN_PURE(0, 1.0F, 0),
BLUE_PURE(0, 0, 1.0F),
DARK_YELLOW(1, 1, 0);
private float red, green, blue;
GLColor(float red, float green, float blue){
this.red = red;
this.green = green;
this.blue = blue;
}
public float getRed() {
return red;
}
public float getGreen() {
return green;
}
public float getBlue() {
return blue;
}
}
}

View file

@ -14,6 +14,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
@ -84,4 +85,8 @@ public class WorldPos{
public String toString(){
return "["+this.x+", "+this.y+", "+this.z+" in world "+this.worldID+"]";
}
public Vec3 toVec(){
return Vec3.createVectorHelper(this.x, this.y, this.z);
}
}