Worked out client side rendering for addons

I was doing it wrong just to be short. Long story though when calling
for the addon to render you can't do any of the normal GL11 call for
changing the location, scale, etc., or at least not the way i was doing
it. Only thing the addon creator should need to do is call for the part
of the model to render connected to the pipe core.
This commit is contained in:
Rseifert 2013-04-02 13:52:44 -04:00
parent da813ace2d
commit 67454a0a29
4 changed files with 38 additions and 24 deletions

View file

@ -7,6 +7,8 @@ import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
import fluidmech.client.model.ModelLargePipe; import fluidmech.client.model.ModelLargePipe;
import fluidmech.client.render.pipeextentions.IPipeExtentionRender; import fluidmech.client.render.pipeextentions.IPipeExtentionRender;
import fluidmech.common.FluidMech; import fluidmech.common.FluidMech;
@ -53,13 +55,14 @@ public class RenderPipe extends TileEntitySpecialRenderer
IPipeExtentionRender render = (IPipeExtentionRender) ob; IPipeExtentionRender render = (IPipeExtentionRender) ob;
if (render != null) if (render != null)
{ {
render.renderAModelAt(pipe, d, d1, d2, f, ForgeDirection.getOrientation(i)); System.out.println("Rendering Pipe Addon side " + i);
render.renderAModelAt(this, pipe, new Vector3(0, 0, 0), f, ForgeDirection.getOrientation(i));
} }
} }
} }
catch (Exception e) catch (Exception e)
{ {
System.out.print("Failed to render a pipe extention"); System.out.println("Failed to render a pipe extention");
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -70,6 +73,11 @@ public class RenderPipe extends TileEntitySpecialRenderer
} }
public void bindTextureForPipe(String texture)
{
this.bindTextureByName(texture);
}
public static String getPipeTexture(int meta) public static String getPipeTexture(int meta)
{ {
return FluidMech.MODEL_TEXTURE_DIRECTORY + "pipes/" + ColorCode.get(meta).getName() + "Pipe.png"; return FluidMech.MODEL_TEXTURE_DIRECTORY + "pipes/" + ColorCode.get(meta).getName() + "Pipe.png";

View file

@ -7,6 +7,8 @@ import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector3;
import fluidmech.client.model.ModelLargePipe; import fluidmech.client.model.ModelLargePipe;
import fluidmech.client.render.pipeextentions.IPipeExtentionRender; import fluidmech.client.render.pipeextentions.IPipeExtentionRender;
import fluidmech.common.FluidMech; import fluidmech.common.FluidMech;
@ -24,14 +26,12 @@ public class RenderPipeWindow implements IPipeExtentionRender
SixPipe = new ModelLargePipe(); SixPipe = new ModelLargePipe();
} }
public void renderAModelAt(TileEntityPipe pipe, double d, double d1, double d2, float size, ForgeDirection facingDirection) @Override
public void renderAModelAt(RenderPipe renderPipe, TileEntityPipe pipe, Vector3 location, float size, ForgeDirection facingDirection)
{ {
// Texture file renderPipe.bindTextureForPipe(renderPipe.getPipeTexture(0));
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.1F, -1.1F, -1.1F);
this.render(facingDirection.ordinal()); this.render(facingDirection.ordinal());
GL11.glPopMatrix(); System.out.println("Rendered Window Pipe");
} }

View file

@ -1,6 +1,9 @@
package fluidmech.client.render.pipeextentions; package fluidmech.client.render.pipeextentions;
import universalelectricity.core.vector.Vector3;
import fluidmech.client.render.RenderPipe;
import fluidmech.common.machines.pipes.TileEntityPipe; import fluidmech.common.machines.pipes.TileEntityPipe;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -15,12 +18,14 @@ public interface IPipeExtentionRender
{ {
/** /**
* Renders the pipe extension just like a normal tileEntity render however this is called and * Renders the pipe extension just like a normal tileEntity render however this is called and
* process threw the RenderPipe.class * process threw the RenderPipe.class so you don't need to do all the GL11 calls for scaling,
* translation, etc
* *
* @param renderPipe - render instance that is calling this method
* @param pipe - TileEntity this extension is attached too * @param pipe - TileEntity this extension is attached too
* @param xPos yPos zPos position too be rendered from the players plane * @param location - position too be rendered from the players plane
* @param size - This should be the size of the render, correct me if wrong * @param size - This should be the size of the render, correct me if wrong
* @param facingDirection - Facing direction of the extension in relation to its pipe frame * @param facingDirection - Facing direction of the extension in relation to its pipe frame
*/ */
public void renderAModelAt(TileEntityPipe pipe, double xPos, double yPos, double zPos, float size, ForgeDirection facingDirection); public void renderAModelAt(RenderPipe renderPipe, TileEntityPipe pipe, Vector3 location, float size, ForgeDirection facingDirection);
} }

View file

@ -65,13 +65,13 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
public void initiate() public void initiate()
{ {
this.updateAdjacentConnections(); this.updateAdjacentConnections();
if (!worldObj.isRemote)
{
if (this.subEntities[0] == null) if (this.subEntities[0] == null)
{ {
this.subEntities[0] = new TileEntityPipeWindow(); this.addNewExtention(0, TileEntityPipeWindow.class);
this.initSubTile(0);
} }
if (!worldObj.isRemote)
{
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
TileEntity entity = (TileEntity) this.subEntities[i]; TileEntity entity = (TileEntity) this.subEntities[i];
@ -110,7 +110,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
IPipeExtention extention = subEntities[i]; IPipeExtention extention = subEntities[i];
if (this.ticks % extention.updateTick() == 0) if (this.ticks % extention.updateTick() == 0)
{ {
System.out.println("Updating addon " + (worldObj.isRemote ? "Client" : "Server") + " on side " + i); //System.out.println("Updating addon " + (worldObj.isRemote ? "Client" : "Server") + " on side " + i);
((TileEntity) extention).updateEntity(); ((TileEntity) extention).updateEntity();
if (extention.shouldSendPacket(!this.worldObj.isRemote) && extention.getExtentionPacketData(!this.worldObj.isRemote) != null) if (extention.shouldSendPacket(!this.worldObj.isRemote) && extention.getExtentionPacketData(!this.worldObj.isRemote) != null)
{ {
@ -215,7 +215,8 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
TileEntity tile = partClass.newInstance(); TileEntity tile = partClass.newInstance();
if (tile instanceof IPipeExtention) if (tile instanceof IPipeExtention)
{ {
this.subEntities[side] = (IPipeExtention) tile;
this.initSubTile(side);
} }
} }
catch (Exception e) catch (Exception e)