Jump to content

[Unsolved] TileEntitySpecialRenderer not updating it's textures [1.6.2]


larsgerrits

Recommended Posts

So, I made a custom block model and it works, I added some checklines to check if the redstone control works, and it did. Now my only problem is that in the TileEntitySpecialRenderer class, it checks for a boolean in the TileEntity class, which is updated by the block itself, but it isn't updating it's textures based on the state of the boolean. It only uses 1 texture.

 

TileEntitySpecialRenderer.java

 

package larsg310.mods.bd.render.tileentity;

import larsg310.mods.bd.lib.Textures;
import larsg310.mods.bd.model.ModelStoplight;
import larsg310.mods.bd.tileentity.TileEntityStoplight;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class TileEntityStoplightRenderer extends TileEntitySpecialRenderer
{
private ModelStoplight modelStoplight = new ModelStoplight();
private Minecraft mc;
public ResourceLocation stoplightRedResourceLocation = new ResourceLocation(Textures.MODEL_STOPLIGHT_RED);
public ResourceLocation stoplightYellowResourceLocation = new ResourceLocation(Textures.MODEL_STOPLIGHT_YELLOW);
public ResourceLocation stoplightGreenResourceLocation = new ResourceLocation(Textures.MODEL_STOPLIGHT_GREEN);

public TileEntityStoplightRenderer()
{
	this.mc = Minecraft.getMinecraft();
}
@Override
    public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick)
{
        if (tileEntity instanceof TileEntityStoplight)
        {
            TileEntityStoplight TileEntityStoplight = (TileEntityStoplight) tileEntity;
            ForgeDirection direction = null;
            if (TileEntityStoplight.getWorldObj() != null)
            {
                direction = ForgeDirection.getOrientation(TileEntityStoplight.getBlockMetadata());
            }
            if(((TileEntityStoplight) tileEntity).isPowered == true)
            {
            	if(((TileEntityStoplight)tileEntity).isPoweredFor3Seconds == true)
            	{
            		this.mc.renderEngine.func_110577_a(stoplightGreenResourceLocation);
            	}
            	else
            	{
            		this.mc.renderEngine.func_110577_a(stoplightYellowResourceLocation);
            	}
            }
            else
            {
            	this.mc.renderEngine.func_110577_a(stoplightRedResourceLocation);
            }
   		 	GL11.glPushMatrix();
            GL11.glEnable(GL12.GL_RESCALE_NORMAL);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
            GL11.glScalef(1.0F, -1.0F, -1.0F);
            GL11.glTranslatef(0.5F, 0.5F, 0.5F);
            int rotation = 180;
            switch(tileEntity.getBlockMetadata() % 4)
            {
                case 0:
                    rotation = 180;
                    break;
                case 3:
                    rotation = 90;
                    break;
                case 2:
                    rotation = 0;
                    break;
                case 1:
                    rotation = 270;
                    break;
            }
            GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F);
            GL11.glTranslatef(0F, -1F, 0F);
            modelStoplight.renderAll(0.0625F);
            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
            GL11.glPopMatrix();
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        }
    }
}

 

 

TileEntity.java:

 

package larsg310.mods.bd.tileentity;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityStoplight extends TileEntity
{
public int TICKS_NEEDED = 60;
public int currentTick = 0;

public boolean isPowered = false;
public boolean canTime = false;
public boolean isPoweredFor3Seconds = false;

public TileEntityStoplight()
{

}
public void writeToNBT(NBTTagCompound nbt)
{
	nbt.setBoolean("isPowered", isPowered);
}
public void readFromNBT(NBTTagCompound nbt)
{
	this.isPowered = nbt.getBoolean("isPowered");
}
@Override
public void updateEntity()
{
	if(isPowered)
	{
		if(canTime)
		{
			currentTick++;
			System.out.println(currentTick);
			if(currentTick == TICKS_NEEDED)
			{
				isPoweredFor3Seconds = true;
				canTime = false;
			}
		}
	}
	else
	{
		currentTick = 0;
	}
}
}

 

 

Block.java:

 

package larsg310.mods.bd.block;

import java.util.List;

import larsg310.mods.bd.lib.Reference;
import larsg310.mods.bd.lib.RenderIds;
import larsg310.mods.bd.lib.Strings;
import larsg310.mods.bd.tileentity.TileEntityStoplight;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class BlockStoplight extends BlockContainer
{

protected BlockStoplight(int id)
{
	super(id, Material.iron);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setUnlocalizedName(Strings.STOPLIGHT_NAME);
	this.setHardness(3F);
	this.setResistance(5F);
}
@Override
public TileEntity createNewTileEntity(World world)
{
	return new TileEntityStoplight();
}
@Override
public boolean isOpaqueCube()
{
	return false;
}
@Override
public boolean renderAsNormalBlock()
{
	return false;
}
@Override
public int getRenderType()
{
	return RenderIds.STOPLIGHT_RENDER_ID;
}
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    {
        super.breakBlock(par1World, par2, par3, par4, par5, par6);
        par1World.removeBlockTileEntity(par2, par3, par4);
    }
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemStack)
{
    int blockSet = world.getBlockMetadata(x, y, z) / 4;
    int direction = MathHelper.floor_double((entityliving.rotationYaw * 4F) / 360F + 0.5D) & 3;
    int newMeta = (blockSet * 4) + direction;
    world.setBlockMetadataWithNotify(x, y, z, newMeta, 0);
}
@Override
public void registerIcons(IconRegister iconRegister)
{
	this.blockIcon = iconRegister.registerIcon(Reference.MOD_ID + ":" + this.getUnlocalizedName());
}
public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
{
    	this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 7.0F, 1.0F);
    	super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    }
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockId)
    {
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

        if (!world.isRemote)
        {
        	if(tileEntity != null)
        	{
        		if(world.isBlockIndirectlyGettingPowered(x, y, z))
        		{
        			((TileEntityStoplight)tileEntity).isPowered = true;
        			((TileEntityStoplight)tileEntity).canTime = true;
        			
        		}
        		else
        		{
        			((TileEntityStoplight)tileEntity).isPowered = false;
        			((TileEntityStoplight)tileEntity).isPoweredFor3Seconds = false;
        			((TileEntityStoplight)tileEntity).canTime = 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/

Link to comment
Share on other sites

BTW does anyone know if there's an update method that checks every tick or something like that, just like in the TileEntity class with the updateEntity class.

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/

Link to comment
Share on other sites

You need to sync the state of your TileEntity via the getDescriptionPacket and onDataPacket methods. Since Minecraft is a Client/Server application there are 2 TileEntity instances for each TE. One on the client and one serverside. Your data only gets modified in the serverside one if you don't send packets.

That could be the case, but which packets do i have to send for them to sync?

BTW does anyone know if there's an update method that checks every tick or something like that, just like in the TileEntity class with the updateEntity class.

Are you talking about TickHandlers?

If it kinda like the same as the updateEntity() method in the TileEntity class, that could be yes.

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/

Link to comment
Share on other sites

That could be the case, but which packets do i have to send for them to sync?

From getDescriptionPacket return a Packet132TileEntityData. That has an NBTTagCompound as its parameter, put all the data you need on the client side in there, and read it back in onDataPacket (the Packet will arrive there).

Ok that makes sense.

If it kinda like the same as the updateEntity() method in the TileEntity class, that could be yes.

Kinda, yes. What do you want to achieve?

At first, I thaught that the TileEntitySpecialRenderer class only got the TileEntity booleans once, and that I needed a method to constantly check for the booleans.

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/

Link to comment
Share on other sites

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.