Jump to content

[Solved]TileEntitySpecialRenderer not rendering based on adjacent blocks[1.6]


Recommended Posts

Posted

Hello,

 

I made a cable-like block with a custom model etc. and the middle part renders always as i want to, but it doesn't render other parts based on the cables next to it.

 

[spoiler=TileEntitySpecialRenderer]

package larsg310.mod.techcraft.renderer.tileentity;

import larsg310.mod.techcraft.lib.ConnectingIds;
import larsg310.mod.techcraft.lib.Reference;
import larsg310.mod.techcraft.model.ModelRedstonePowerCable;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

public class TileEntityRedstonePowerCableRenderer extends TileEntitySpecialRenderer
{
private ModelRedstonePowerCable model;
public ResourceLocation REDSTONE_POWER_CABLE_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/model/ModelRedstonePowerCable.png");

public TileEntityRedstonePowerCableRenderer()
{
	this.model = new ModelRedstonePowerCable();
}
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f)
{
	World world = tileentity.worldObj;

	GL11.glPushMatrix();
	GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
	GL11.glRotatef(180, 0, 0, 1);
	this.bindTexture(REDSTONE_POWER_CABLE_TEXTURE);
	GL11.glPushMatrix();
	model.renderAll(world, (int)x, (int)y, (int)z);
	GL11.glPopMatrix();
	GL11.glPopMatrix();
}
}

 

 

[spoiler=Model Class]

package larsg310.mod.techcraft.model;

import larsg310.mod.techcraft.lib.ConnectingIds;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;

public class ModelRedstonePowerCable extends ModelBase
{
ModelRenderer Middle;
    ModelRenderer ExtensionNorth;
    ModelRenderer ExtensionEast;
    ModelRenderer ExtensionSouth;
    ModelRenderer ExtensionWest;
    ModelRenderer ExtensionDown;
    ModelRenderer ExtensionUp;
  
  public ModelRedstonePowerCable()
  {
      textureWidth = 64;
      textureHeight = 64;
    
      Middle = new ModelRenderer(this, 0, 0);
      Middle.addBox(0F, 0F, 0F, 4, 4, 4);
      Middle.setRotationPoint(-2F, 14F, -2F);
      Middle.setTextureSize(64, 64);
      Middle.mirror = true;
      setRotation(Middle, 0F, 0F, 0F);
      ExtensionNorth = new ModelRenderer(this, 0, 9);
      ExtensionNorth.addBox(0F, 0F, 0F, 4, 4, 6);
      ExtensionNorth.setRotationPoint(-2F, 14F, 2F);
      ExtensionNorth.setTextureSize(64, 64);
      ExtensionNorth.mirror = true;
      setRotation(ExtensionNorth, 0F, 0F, 0F);
      ExtensionEast = new ModelRenderer(this, 0, 20);
      ExtensionEast.addBox(0F, 0F, 0F, 6, 4, 4);
      ExtensionEast.setRotationPoint(2F, 14F, -2F);
      ExtensionEast.setTextureSize(64, 64);
      ExtensionEast.mirror = true;
      setRotation(ExtensionEast, 0F, 0F, 0F);
      ExtensionSouth = new ModelRenderer(this, 0, 9);
      ExtensionSouth.addBox(0F, 0F, 0F, 4, 4, 6);
      ExtensionSouth.setRotationPoint(-2F, 14F, -8F);
      ExtensionSouth.setTextureSize(64, 64);
      ExtensionSouth.mirror = true;
      setRotation(ExtensionSouth, 0F, 0F, 0F);
      ExtensionWest = new ModelRenderer(this, 0, 20);
      ExtensionWest.addBox(0F, 0F, 0F, 6, 4, 4);
      ExtensionWest.setRotationPoint(-8F, 14F, -2F);
      ExtensionWest.setTextureSize(64, 64);
      ExtensionWest.mirror = true;
      setRotation(ExtensionWest, 0F, 0F, 0F);
      ExtensionDown = new ModelRenderer(this, 0, 29);
      ExtensionDown.addBox(0F, 0F, 0F, 4, 6, 4);
      ExtensionDown.setRotationPoint(-2F, 18F, -2F);
      ExtensionDown.setTextureSize(64, 64);
      ExtensionDown.mirror = true;
      setRotation(ExtensionDown, 0F, 0F, 0F);
      ExtensionUp = new ModelRenderer(this, 0, 29);
      ExtensionUp.addBox(0F, 0F, 0F, 4, 6, 4);
      ExtensionUp.setRotationPoint(-2F, 8F, -2F);
      ExtensionUp.setTextureSize(64, 64);
      ExtensionUp.mirror = true;
      setRotation(ExtensionUp, 0F, 0F, 0F);
  }
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    Middle.render(f5);
    ExtensionNorth.render(f5);
    ExtensionEast.render(f5);
    ExtensionSouth.render(f5);
    ExtensionWest.render(f5);
    ExtensionDown.render(f5);
    ExtensionUp.render(f5);
  }
  public void renderAll(World world, int x, int y, int z)
  {
    Middle.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "north")) ExtensionNorth.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "east")) ExtensionEast.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "south")) ExtensionSouth.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "west")) ExtensionWest.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "up")) ExtensionDown.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "down")) ExtensionUp.render(0.0625F);
  }
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  }
}

 

 

I'm not putting in the ConnectingIds class, because i know it works because i'm using it to make the block bounds in the block class. If you need mor classes i'll put them here.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

It can't be the cause of the code you've put here if you say the middle part renders. The cables will render if you remove the check if they are connected or not right? Then it should be the cause of the check. I would suggest placing a breakpoint just before a check and tracing down why it returns false.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

Serieusly, i can't find it. Here's some more code:

[spoiler=ConnectingIds]

package larsg310.mod.techcraft.lib;

import larsg310.mod.techcraft.block.TCBlocks;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class ConnectingIds
{
private static IBlockAccess world;
private static int x;
private static int y;
private static int z;

public static boolean getCableConnectings(IBlockAccess world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;

	return isConnecting(direction); 
}
public static boolean getCableConnectings(World world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;

	return isConnecting(direction);
}
public static int getNorthBlock()
{
	return world.getBlockId(x-1, y, z);
}
public static int getSouthBlock()
{
	return world.getBlockId(x+1, y, z);
}
public static int getEastBlock()
{
	return world.getBlockId(x, y, z-1);
}
public static int getWestBlock()
{
	return world.getBlockId(x, y, z+1);
}
public static int getUpBlock()
{
	return world.getBlockId(x, y-1, z);
}
public static int getDownBlock()
{
	return world.getBlockId(x, y+1, z);
}
public static boolean isConnecting(String direction)
{
	boolean north = false;
	boolean east = false;
	boolean south = false;
	boolean west = false;
	boolean up = false;
	boolean down = false;

	if(direction == "north")
	{
		if(getNorthBlock() == TCBlocks.redstonePowerCable.blockID) north = true;
		else if(getNorthBlock() == TCBlocks.redstonePowerGenerator.blockID) north = true;
		return north;
	}
	if(direction == "south")
	{
		if(getSouthBlock() == TCBlocks.redstonePowerCable.blockID) south = true;
		else if(getSouthBlock() == TCBlocks.redstonePowerGenerator.blockID) south = true;
		return south;
	}
	if(direction == "east")
	{
		if(getEastBlock() == TCBlocks.redstonePowerCable.blockID) east = true;
		else if(getEastBlock() == TCBlocks.redstonePowerGenerator.blockID) east = true;
		return east;
	}
	if(direction == "west")
	{
		if(getWestBlock() == TCBlocks.redstonePowerCable.blockID) west = true;
		else if(getWestBlock() == TCBlocks.redstonePowerGenerator.blockID) west = true;
		return west;
	}
	if(direction == "up")
	{
		if(getUpBlock() == TCBlocks.redstonePowerCable.blockID) up = true;
		else if(getUpBlock() == TCBlocks.redstonePowerGenerator.blockID) up = true;
		return up;
	}
	if(direction == "down")
	{
		if(getDownBlock() == TCBlocks.redstonePowerCable.blockID) down = true;
		else if(getDownBlock() == TCBlocks.redstonePowerGenerator.blockID) down = true;
		return down;
	}
	return false;
}
}

 

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Serieusly, i can't find it. Here's some more code:

[spoiler=ConnectingIds]

package larsg310.mod.techcraft.lib;

import larsg310.mod.techcraft.block.TCBlocks;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class ConnectingIds
{
private static IBlockAccess world;
private static int x;
private static int y;
private static int z;

public static boolean getCableConnectings(IBlockAccess world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;

	return isConnecting(direction); 
}

 

 

Gah! x..X

Don't use static variables like that.  While it's not messing up when executed, its generally not good practice.  Those are prime examples of values that should be passed to the various functions that use them.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Serieusly, i can't find it. Here's some more code:

[spoiler=ConnectingIds]

package larsg310.mod.techcraft.lib;

import larsg310.mod.techcraft.block.TCBlocks;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class ConnectingIds
{
private static IBlockAccess world;
private static int x;
private static int y;
private static int z;

public static boolean getCableConnectings(IBlockAccess world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;

	return isConnecting(direction); 
}

 

 

Gah! x..X

Don't use static variables like that.  While it's not messing up when executed, its generally not good practice.  Those are prime examples of values that should be passed to the various functions that use them.

Ok, I'll change that after it renders. I have a picture of the bounding boxes that work, and use the same class. Maybe it has something to with that the boundingbox method passes the IBlockAccess variable to the ConnectingIds class, but the TileEntitySpecialRenderer class a worldObj.

[spoiler=Image]3DzAYT2.png

 

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

I've been trying to figure it out for about 3 days, but i can't find the problem. I really need the help!

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Hi

 

I've spent a few minutes looking at your posts and code and to be honest I really don't understand what it is supposed to do, or how it is supposed to work.

 

Could you describe to us in some more detail what you're trying to do?  What are "cables", "middle parts", and "extensions"?  Perhaps you could mock up a screenshot of what the possible arrangements should be, using (say) stone for middle parts and something else for cables (redstone? wood?)

 

-TGG

 

Posted

Ok, i'm gonna do my best to explain it.

 

First of all the middle part is what is supposed to render all the time, even if there are no other cables next to it. The extensions are the part that need to render based on adjacent cables, like if there are 2 cables next to each other and they are connecting. In my bounding box picture you can see what i mean with "connecting" [spoiler=Bounding Boxes]3DzAYT2.png

As you can see,the bounding boxes are extending out to the cable block next to it, and the same for the other directions. In this picture:

 

pX0pgwZ.png

you can see that if there are 2 cables (stone) next to each other the extensions (repeaters) are facing to the cable next to it. And if there are no other cables next to it, it doesn't render any extensions at all.

yT7oBgg.png

I hope that i explained it well enough to understand, and if you need more explanation, just aks  ;)

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Hi

 

OK I think I understand better.

 

A couple of further questions..

 

if you modify your  code to this, what do you see?  Are the Extensions rendering in all six directions properly?  Or just the middle?

public void renderAll(World world, int x, int y, int z)
  {
    Middle.render(0.0625F);
    ExtensionNorth.render(0.0625F);
    ExtensionEast.render(0.0625F);
    ExtensionSouth.render(0.0625F);
    ExtensionWest.render(0.0625F);
    ExtensionDown.render(0.0625F);
    ExtensionUp.render(0.0625F);
  }

 

-TGG

 

Posted

Yeah, they do render if i put that instead, so it must be with the if checks, but i dont see why, it's working for my bounding boxes.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Hi

 

Do you know how to use breakpoints?  If so I suggest you add a breakpoint in your renderAll, then trace into your getCableConnectings to see why it's not working.

 

Otherwise, you could add logging code to your methods to see what's happening.

 

	public static boolean getCableConnectings(World world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;
	System.out.println("getCableConnectings (" + x1 + "," + y1 + "," + z1 + "):" + direction);
	return isConnecting(direction);
}
public static int getNorthBlock()
{
	System.out.println("getNorthBlock (" + (x-1) + "," + y + "," + z +"):" +world.getBlockId(x-1, y, z));
	return world.getBlockId(x-1, y, z);
}
public static int getSouthBlock()
{
	System.out.println("getSouthBlock (" + (x+1) + "," + y + "," + z +"):" +world.getBlockId(x+1, y, z));
            return world.getBlockId(x+1, y, z);
}

{etc}

 

It looks to me like your blockIDs probably aren't right for some reason.

 

-TGG

 

Posted

If i place it on the coordinates (114, 64, 436) it gives me this log:

 

2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (-1, -2, 0
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (-1, -2, 0
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (-1, -2, 0
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (-1, -2, 0
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436

It seems like it can't always find the right coordinates, but it mostly will, but even then, it's not rendering

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Hi

 

That's odd

 

I don't understand why this code

		System.out.println("getNorthBlock (" + (x-1) + "," + y + "," + z +"):" +world.getBlockId(x-1, y, z));

give this output

2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436

and why

System.out.println("getCableConnectings (" + x1 + "," + y1 + "," + z1 + "):" + direction);

isn't printing anything.

 

North of (114, 64, 436) is (114, 64, 435) not (113, 64, 436)

 

The point of the logging was to see what the blockID is.  But to be honest I think it would be time well-spent to tear up your ConnectingId class and rewrite it without the static variables.  It might help make the cause of the bug clearer.

 

-TGG

Posted

After a bit of testing, it seems like to me, that the TileEntityRedstonePowerCable#renderTileEntityAt is passing the players position OR the coordinates (0,0,0), cause in the IItemRenderer class (which i will be implementing once this is working) is passing the coordinates (0,0,0)

TileEntityRenderer.instance.renderTileEntityAt(new TileEntityRedstonePowerCable(), 0D, 0D, 0D, 0F);

but i don't know howto put the right coordinates there...

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Ah now that you say that I think I know what you're problem is! You're using the coordinates given in the TESR method, but these are not world coordinates, these are relative render coordinates and only tell you how much you need to translate the render matrix!

 

TileEntityRenderer, line 157

this.renderTileEntityAt(par1TileEntity, (double)par1TileEntity.xCoord - staticPlayerX, (double)par1TileEntity.yCoord - staticPlayerY, (double)par1TileEntity.zCoord - staticPlayerZ, par2);

 

So the solution is to use tileEntity.xCoord to get all the world coordinates.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.