Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8] Chest not updating textures until logging out


Glistre
 Share

Recommended Posts

My custom large chest is not rendering correctly. If I place a small chest, then place a second chest adjacent, the original small chest texture z-fights with the large chest texture. If I exit the game and log back in, the effect is gone and everything is fine -- I see just the large chest texture.

 

This is my render class for the chests. Does anyone know why this texture would not update until I log out and log back in?

 

package com.glistre.glistremod.tileentity;

import net.minecraftforge.fml.common.FMLLog;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Calendar;

import net.minecraft.block.Block;

import net.minecraft.client.model.ModelChest;

import net.minecraft.client.model.ModelLargeChest;

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.tileentity.TileEntity;

import com.glistre.glistremod.blocks.GlistreChest;

import com.glistre.glistremod.blocks.TileEntityGlistreChest;

import com.glistre.glistremod.entities.blacktobie.EntityBlackTobo;

import com.glistre.glistremod.reference.Reference;

import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import org.lwjgl.opengl.GL12;

@SideOnly(Side.CLIENT)

public class GlistreChestRenderer extends TileEntitySpecialRenderer

{

private static ResourceLocation largeChestTexture = new ResourceLocation(Reference.MOD_ID + ":" + "textures/blocks/glistre_large_chest.png");

private static ResourceLocation chestTexture = new ResourceLocation(Reference.MOD_ID + ":" + "textures/blocks/glistre_chest.png");

private ModelChest modelchest = new ModelChest();

private ModelChest largeModelChest = new ModelLargeChest();

private boolean isChristmas;

public GlistreChestRenderer(RenderManager renderManager)

{

Calendar calendar = Calendar.getInstance();

if (calendar.get(2) + 1 == 12 && calendar.get(5) >= 24 && calendar.get(5) <= 26)

{

this.isChristmas = true;

}

}

public void renderTileEntityAt(TileEntityGlistreChest te, double posX, double posY, double posZ, float partialTicks, int destroyStage)

{

int i;

if (!te.hasWorldObj())

{

i = 0;

}

else

{

Block block = te.getBlockType();

i = te.getBlockMetadata();

if (block instanceof GlistreChest && i == 0)

{

try

{

 

((GlistreChest)block).checkForSurroundingChests(te.getWorld(), te.getPos(), te.getWorld().getBlockState(te.getPos()));

}

catch (ClassCastException e)

{

FMLLog.severe("Attempted to render a chest at %d, %d, %d that was not a chest", te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());

}

i = te.getBlockMetadata();

}

te.checkForAdjacentChests();

}

 

if (te.adjacentChestZNeg == null && te.adjacentChestXNeg == null)

{

ModelChest modelchest;

if (te.adjacentChestXPos == null && te.adjacentChestZPos == null)

{

modelchest = this.modelchest;

this.bindTexture(chestTexture);

 

}

else

{

modelchest = this.largeModelChest;

this.bindTexture(largeChestTexture);

 

}

GL11.glPushMatrix();

GL11.glEnable(GL12.GL_RESCALE_NORMAL);

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

GL11.glTranslatef((float)posX, (float)posY + 1.0F, (float)posZ + 1.0F);

GL11.glScalef(1.0F, -1.0F, -1.0F);

GL11.glTranslatef(0.5F, 0.5F, 0.5F);

short short1 = 0;

if (i == 2)

{

short1 = 180;

}

if (i == 3)

{

short1 = 0;

}

if (i == 4)

{

short1 = 90;

}

if (i == 5)

{

short1 = -90;

}

if (i == 2 && te.adjacentChestXPos != null)

{

GL11.glTranslatef(1.0F, 0.0F, 0.0F);

}

if (i == 5 && te.adjacentChestZPos != null)

{

GL11.glTranslatef(0.0F, 0.0F, -1.0F);

}

GL11.glRotatef((float)short1, 0.0F, 1.0F, 0.0F);

GL11.glTranslatef(-0.5F, -0.5F, -0.5F);

float f1 = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks;

float f2;

if (te.adjacentChestZNeg != null)

{

f2 = te.adjacentChestZNeg.prevLidAngle + (te.adjacentChestZNeg.lidAngle - te.adjacentChestZNeg.prevLidAngle) * partialTicks;

if (f2 > f1)

{

f1 = f2;

}

}

if (te.adjacentChestXNeg != null)

{

f2 = te.adjacentChestXNeg.prevLidAngle + (te.adjacentChestXNeg.lidAngle - te.adjacentChestXNeg.prevLidAngle) * partialTicks;

if (f2 > f1)

{

f1 = f2;

}

}

f1 = 1.0F - f1;

f1 = 1.0F - f1 * f1 * f1;

modelchest.chestLid.rotateAngleX = -(f1 * (float)Math.PI / 2.0F);

modelchest.renderAll();

GL11.glDisable(GL12.GL_RESCALE_NORMAL);

GL11.glPopMatrix();

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

 

}

}

@Override

public void renderTileEntityAt(TileEntity te, double posX, double posZ, double p_180535_6_,

float p_180535_8_, int p_180535_9_) {

this.renderTileEntityAt((TileEntityGlistreChest)te, posX, posZ, p_180535_6_, p_180535_8_, p_180535_9_);

}

}

 

Link to comment
Share on other sites

Hi

 

It sound to me like you have two TileEntities rendering instead of one:

1) the one you placed originally

2) the second one you placed

 

First TileEntity renders a small chest.  Second TileEntity renders a large chest over the top of the first one.  I suggest putting something like  System.out.println("render pos:" + te.getPos() + " size:" + (size ? "large" : "small")) into your code to see what's going on

 

-TGG

 

Link to comment
Share on other sites

Hi

 

Nearly all the files are missing from the repo so I can't compile and run it.  You need to put the entire project on GitHub, similar to this

https://github.com/TheGreyGhost/MinecraftByExample

 

If you're not already using GitHub or similar I recommend you spend a few hours learning about it because it will be a huge help to make sure your code is backed up and you have good control of different versions.  IntelliJ in particular is very easy to integrate with GitHub.

 

In the meantime you could zip your entire src and resources folders instead and add that, that would also be enough for me to work with.

 

-TGG

 

Link to comment
Share on other sites

thanks I will learn how to use it better then get back

 

 

Edit:  I have much to learn about git and code sharing.  Meanwhile,

I uploaded a zip file of all source and resources if that would be possible to access

 

https://github.com/Glistre/GlistreMod3.0/upload/master

 

Edit:  I pushed the project to github now hope that is better

https://github.com/Glistre/GlistreMod3.1/

Link to comment
Share on other sites

Hi

 

That's much better :)

 

I downloaded it and tested, the problem appears to be here, where you renamed a method but forgot to update all the calls to it.

In IntelliJ and probably Eclipse as well, there's a rename command which lets you rename a method and will automatically update all code which calls the method as well.  Stops you forgetting any.  In this case, it was call the base class method which for some reason was causing one of the two tileentities to render single size, and the one next to it to render large.  I don't quite understand why because I expected the base method to detect your GlistreChest as well as the chest, but anyway it appears to have fixed the problem.

 

    /**
     * Performs the check for adjacent chests to determine if this chest is double or not.
     */
    public void checkForAdjacentChests()
    {
        if (!this.adjacentChestChecked)
        {
            this.adjacentChestChecked = true;
            this.adjacentChestXNeg = this.getAdjacentChest(EnumFacing.WEST);  //changed
            this.adjacentChestXPos = this.getAdjacentChest(EnumFacing.EAST); //changed
            this.adjacentChestZNeg = this.getAdjacentChest(EnumFacing.NORTH); //changed
            this.adjacentChestZPos = this.getAdjacentChest(EnumFacing.SOUTH); //changed
        }
    }

 

FYI there is another bug - double chests disappear when you look at them out of the corner of your eye.

 

You need to override

 

TileEntityGlistreChest::
    @SideOnly(Side.CLIENT)
    public net.minecraft.util.AxisAlignedBB getRenderBoundingBox()
    {
        net.minecraft.util.AxisAlignedBB bb = INFINITE_EXTENT_AABB;
        Block type = getBlockType();
        if (type == Blocks.enchanting_table)
        {
            bb = new net.minecraft.util.AxisAlignedBB(getPos(), getPos().add(1, 1, 1));
        }
        else if (type == Blocks.chest || type == Blocks.trapped_chest)  // only works for vanilla chests, you need to do similar for your chest
        {
            bb = new net.minecraft.util.AxisAlignedBB(getPos().add(-1, 0, -1), getPos().add(2, 2, 2));
        }

 

For example

 

	/** Return an appropriate bounding box enclosing the TESR
 * This method is used to control whether the TESR should be rendered or not, depending on where the player is looking.
 * The default is the AABB for the parent block, which might be too small if the TESR renders outside the borders of the
 *   parent block.
 * If you get the boundary too small, the TESR may disappear when you aren't looking directly at it.
 * @return an appropriately size AABB for the TileEntity
 */
@SideOnly(Side.CLIENT)
@Override
public AxisAlignedBB getRenderBoundingBox()
{
	// if your render should always be performed regardless of where the player is looking, use infinite
	AxisAlignedBB infiniteExample = INFINITE_EXTENT_AABB;

	// our gem will stay above the block, up to 1 block higher, so our bounding box is from [x,y,z] to  [x+1, y+2, z+1]
	AxisAlignedBB aabb = new AxisAlignedBB(getPos(), getPos().add(1, 2, 1));
	return aabb;
}

 

-TGG

Link to comment
Share on other sites

That works great now thank you so much!  And I learned some new things about git and renaming methods

 

I have one more odd thing -- my chest does not show in inventory ... it shows in my hot bar but not under the tab . . .

 

Would you happen to know why?

Edited:  forgot to add chest to my list in TabRegistry fixed with adding :

list.add(new ItemStack(BlockRegistry.glistre_chest));

 

Working great now!

 

Aside:  were you at Minecon in September on the modding forum panel with LexManos?

 

Link to comment
Share on other sites

That works great now thank you so much!  And I learned some new things about git and renaming methods

Keen, you're welcome :)

 

Aside:  were you at Minecon in September on the modding forum panel with LexManos?

no :)  I live in Australia which is a very long way away from both the US and the UK so I've never gone to a Minecon....

 

-TGG

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
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.

 Share



×
×
  • Create New...

Important Information

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