JimiIT92 Posted July 29, 2017 Posted July 29, 2017 I made a custom chest but the rendering is giving some gltiches. First of all the chest is not rendering though the tileentity is registered. This is the TileEntityCode package com.mw.entities.tileentity; import com.mw.blocks.BlockChestMW; import com.mw.utils.EnumDimensions; import net.minecraft.block.Block; import net.minecraft.block.BlockChest; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; public class TileEntityChestCorrupted extends TileEntityChest{ /** * Get the name of this object. For players this returns their username */ public String getName() { return this.hasCustomName() ? super.getName() : "container.chest.corrupted"; } protected TileEntityChest getAdjacentChest(EnumFacing side) { BlockPos blockpos = this.pos.offset(side); if (this.isChestAt(blockpos)) { TileEntity tileentity = this.world.getTileEntity(blockpos); if (tileentity instanceof TileEntityChestCorrupted) { TileEntityChestCorrupted tileentitychest = (TileEntityChestCorrupted)tileentity; tileentitychest.getNeighbor(this, side.getOpposite()); return tileentitychest; } } return null; } @SuppressWarnings("incomplete-switch") private void getNeighbor(TileEntityChest chestTe, EnumFacing side) { if (chestTe.isInvalid()) { this.adjacentChestChecked = false; } else if (this.adjacentChestChecked) { switch (side) { case NORTH: if (this.adjacentChestZNeg != chestTe) { this.adjacentChestChecked = false; } break; case SOUTH: if (this.adjacentChestZPos != chestTe) { this.adjacentChestChecked = false; } break; case EAST: if (this.adjacentChestXPos != chestTe) { this.adjacentChestChecked = false; } break; case WEST: if (this.adjacentChestXNeg != chestTe) { this.adjacentChestChecked = false; } } } } private boolean isChestAt(BlockPos posIn) { if (this.world == null) { return false; } else { Block block = this.world.getBlockState(posIn).getBlock(); return block instanceof BlockChestMW && ((BlockChestMW)block).getDimension() == EnumDimensions.CORRUPTED; } } } And this is how i register the TileEntity addTileEntity(TileEntityChestCorrupted.class, new RenderTileEntityChestMW(EnumDimensions.CORRUPTED)); private static void addTileEntity(Class<? extends TileEntity> tileEntity, TileEntitySpecialRenderer specialRenderer) { ClientRegistry.registerTileEntity(tileEntity, MW.MODID + ":" + tileEntity.getSimpleName().toLowerCase(), specialRenderer); } The rendering class is this package com.mw.renders.tileentity; import com.mw.MW; import com.mw.blocks.BlockChestMW; import com.mw.utils.EnumDimensions; import net.minecraft.block.Block; import net.minecraft.block.BlockChest; import net.minecraft.client.model.ModelChest; import net.minecraft.client.model.ModelLargeChest; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderTileEntityChestMW extends TileEntitySpecialRenderer<TileEntityChest> { private static ResourceLocation TEXTURE_NORMAL_DOUBLE = new ResourceLocation("textures/entity/chest/normal_double.png"); private static ResourceLocation TEXTURE_NORMAL = new ResourceLocation("textures/entity/chest/normal.png"); private final ModelChest simpleChest = new ModelChest(); private final ModelChest largeChest = new ModelLargeChest(); private EnumDimensions dimension; public RenderTileEntityChestMW(EnumDimensions dimension) { this.dimension = dimension; } public void render(TileEntityChest te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { TEXTURE_NORMAL_DOUBLE = new ResourceLocation(MW.MODID, "textures/entity/chest/" + this.dimension.getName() + "_double.png"); TEXTURE_NORMAL = new ResourceLocation(MW.MODID, "textures/entity/chest/" + this.dimension.getName() + ".png"); GlStateManager.enableDepth(); GlStateManager.depthFunc(515); GlStateManager.depthMask(true); int i; if (te.hasWorld()) { Block block = te.getBlockType(); i = te.getBlockMetadata(); if (block instanceof BlockChestMW) { ((BlockChestMW)block).checkForSurroundingChests(te.getWorld(), te.getPos(), te.getWorld().getBlockState(te.getPos())); i = te.getBlockMetadata(); } te.checkForAdjacentChests(); } else { i = 0; } if (te.adjacentChestZNeg == null && te.adjacentChestXNeg == null) { ModelChest modelchest; if (te.adjacentChestXPos == null && te.adjacentChestZPos == null) { modelchest = this.simpleChest; if (destroyStage >= 0) { this.bindTexture(DESTROY_STAGES[destroyStage]); GlStateManager.matrixMode(5890); GlStateManager.pushMatrix(); GlStateManager.scale(4.0F, 4.0F, 1.0F); GlStateManager.translate(0.0625F, 0.0625F, 0.0625F); GlStateManager.matrixMode(5888); } else { this.bindTexture(TEXTURE_NORMAL); } } else { modelchest = this.largeChest; if (destroyStage >= 0) { this.bindTexture(DESTROY_STAGES[destroyStage]); GlStateManager.matrixMode(5890); GlStateManager.pushMatrix(); GlStateManager.scale(8.0F, 4.0F, 1.0F); GlStateManager.translate(0.0625F, 0.0625F, 0.0625F); GlStateManager.matrixMode(5888); } else { this.bindTexture(TEXTURE_NORMAL_DOUBLE); } } GlStateManager.pushMatrix(); GlStateManager.enableRescaleNormal(); if (destroyStage < 0) { GlStateManager.color(1.0F, 1.0F, 1.0F, alpha); } GlStateManager.translate((float)x, (float)y + 1.0F, (float)z + 1.0F); GlStateManager.scale(1.0F, -1.0F, -1.0F); GlStateManager.translate(0.5F, 0.5F, 0.5F); int j = 0; if (i == 2) { j = 180; } if (i == 3) { j = 0; } if (i == 4) { j = 90; } if (i == 5) { j = -90; } if (i == 2 && te.adjacentChestXPos != null) { GlStateManager.translate(1.0F, 0.0F, 0.0F); } if (i == 5 && te.adjacentChestZPos != null) { GlStateManager.translate(0.0F, 0.0F, -1.0F); } GlStateManager.rotate((float)j, 0.0F, 1.0F, 0.0F); GlStateManager.translate(-0.5F, -0.5F, -0.5F); float f = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks; if (te.adjacentChestZNeg != null) { float f1 = te.adjacentChestZNeg.prevLidAngle + (te.adjacentChestZNeg.lidAngle - te.adjacentChestZNeg.prevLidAngle) * partialTicks; if (f1 > f) { f = f1; } } if (te.adjacentChestXNeg != null) { float f2 = te.adjacentChestXNeg.prevLidAngle + (te.adjacentChestXNeg.lidAngle - te.adjacentChestXNeg.prevLidAngle) * partialTicks; if (f2 > f) { f = f2; } } f = 1.0F - f; f = 1.0F - f * f * f; modelchest.chestLid.rotateAngleX = -(f * ((float)Math.PI / 2F)); modelchest.renderAll(); GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); if (destroyStage >= 0) { GlStateManager.matrixMode(5890); GlStateManager.popMatrix(); GlStateManager.matrixMode(5888); } } } } The chest is rendering in inventory as well but when placed down i can only see the bounding box. Also i've noticed that if i place a vanilla chest near my chest the vanilla chest is also rendered as invisible. How can i fix this? Quote Don't blame me if i always ask for your help. I just want to learn to be better
JimiIT92 Posted August 9, 2017 Author Posted August 9, 2017 Up Quote Don't blame me if i always ask for your help. I just want to learn to be better
Recommended Posts
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.