Jump to content

Shading issues with tile entity renderer


Aidanamite

Recommended Posts

Minecraft Version: 1.12.2

So I've created a custom block with a huge number of possible varients so I've been trying to setup a tile entity to handle its rendering instead of waiting over 30 minutes for the game to start every time.

The block is working correctly and everything and I've gotten most of the rendering working however I'm having an issue with the shading on the tile entity.
For the purposes of the block I want it to look/render like the other blocks, as such I've made it generate a BakedModel and then parse that through the game's block rendering method.

This is working for the most part except for the shading.

Left: tile entity, Right: normal block
Smooth lighting on: image.png.3c543e3d5fdc51c79ce8096356eaba69.png Smooth lighting off: image.png.2af90f2f6be08fcb9ee2c1b5bcebbf54.png

Right: normal block, Left: tile entity
Smooth lighting on: image.png.edc4b3aec11115ebf2ba1d798afb7491.png Smooth lighting off: image.png.bafb86a296744500b533d5b41669cbfd.png

Center: normal block, Left & Right: tile entity
Smooth lighting on: image.png.37c2569773629c2ea8d69b2a123f0be3.png (Note: smooth lighting does not seem to apply to the tile entities render)

 

This is the section of the block's class that does the model generation and rendering:

public class MCreatorCobble extends Elementsdesignblock.ModElement {
	public class BlockCustomEntityRender extends TileEntitySpecialRenderer<BlockCustomEntity> {
        //private BlockCustomEntityModel model;
        public BlockCustomEntityRender() {
                super();
        }
        public void render(BlockCustomEntity te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
            super.render(te,x,y,z,partialTicks,destroyStage,alpha);
            World world = te.getWorld();
            BlockPos pos = te.getPos();
            IBlockState state = world.getBlockState(pos);

            Tessellator tessellator = Tessellator.getInstance();
            BufferBuilder bufferbuilder = tessellator.getBuffer();
            BlockColors colours = Minecraft.getMinecraft().getBlockColors();
            BlockType type = blockTypes[BlockCustom.getMaterialId(state)];
            try {
                BlockCustomEntityModel model = new BlockCustomEntityModel(state,type);
                GlStateManager.color(1f, 1f, 1f, alpha);
                GlStateManager.pushMatrix();
                GlStateManager.translate(x - pos.getX(), y - pos.getY(), z - pos.getZ());
                GlStateManager.bindTexture(ModelManager().getTextureMap().getGlTextureId());
                bufferbuilder.begin(7, DefaultVertexFormats.ITEM);
                BlockModelRenderer().renderModel(world, model.model, state, pos, bufferbuilder, true);
                tessellator.draw();
                GlStateManager.popMatrix();
                GlStateManager.color(1f, 1f, 1f, 1f);
            } catch (Exception e) {
                if (e instanceof ReportedException) {
                    CrashReport cr = ((ReportedException)e).getCrashReport();
                    System.err.println(cr.getCompleteReport());
                    cr.getCrashCause().printStackTrace(System.err);
                } else {
                    System.err.println("Block with id " + Block.getIdFromBlock(type.block) + " failed to render\n" + e.getClass().getName() + ": " + e.getMessage());
                    e.printStackTrace(System.err);
                }
            }
        }
    }
    
    public class BlockCustomEntityModel {
        public List<BakedQuad> faces = Lists.<BakedQuad>newArrayList();
        public IBakedModel model;
        public BlockCustomEntityModel() {
            super();
        }
        public BlockCustomEntityModel(IBlockState state, BlockType type) {
            super();
            TextureMap tm = ModelManager().getTextureMap();
            TextureAtlasSprite spriteUp = tm.getTextureExtry(type.textureUp.main.texture);
            TextureAtlasSprite spriteDown = tm.getTextureExtry(type.textureDown.main.texture);
            TextureAtlasSprite spriteSide = tm.getTextureExtry(type.textureSide.main.texture);
            TextureAtlasSprite spriteUp2 = (type.textureUp.secondary == null ? null : tm.getTextureExtry(type.textureUp.secondary.texture));
            TextureAtlasSprite spriteDown2 = (type.textureDown.secondary == null ? null : tm.getTextureExtry(type.textureDown.secondary.texture));
            TextureAtlasSprite spriteSide2 = (type.textureSide.secondary == null ? null : tm.getTextureExtry(type.textureSide.secondary.texture));
            if (spriteUp != null && spriteDown != null && spriteSide != null && (type.textureUp.secondary == null || spriteUp2 != null) && (type.textureDown.secondary == null || spriteDown2 != null) && (type.textureSide.secondary == null || spriteSide2 != null))
                for (AxisAlignedBB axisalignedbb : BlockCustom.getCollisionBoxList(state)) {
                    float minX = (float)(axisalignedbb.minX * 16);
                    float minY = (float)(axisalignedbb.minY * 16);
                    float minZ = (float)(axisalignedbb.minZ * 16);
                    float maxX = (float)(axisalignedbb.maxX * 16);
                    float maxY = (float)(axisalignedbb.maxY * 16);
                    float maxZ = (float)(axisalignedbb.maxZ * 16);
                    int x = 16-(int)minX;
                    int X = 16-(int)maxX;
                    int y = 16-(int)minY;
                    int Y = 16-(int)maxY;
                    int z = 16-(int)minZ;
                    int Z = 16-(int)maxZ;
                    addFaces(type.textureUp, minX,minY,minZ, maxX,maxY,maxZ, EnumFacing.UP, 16-x, 16-z, 16-X, 16-Z, spriteUp, spriteUp2);
                    addFaces(type.textureDown, minX,minY,minZ, maxX,maxY,maxZ, EnumFacing.DOWN, 16-x, Z, 16-X, z, spriteDown, spriteDown2);
                    addFaces(type.textureSide, minX,minY,minZ, maxX,maxY,maxZ, EnumFacing.WEST, 16-z, Y, 16-Z, y, spriteSide, spriteSide2);
                    addFaces(type.textureSide, minX,minY,minZ, maxX,maxY,maxZ, EnumFacing.EAST, Z, Y, z, y, spriteSide, spriteSide2);
                    addFaces(type.textureSide, minX,minY,minZ, maxX,maxY,maxZ, EnumFacing.NORTH, X, Y, x, y, spriteSide, spriteSide2);
                    addFaces(type.textureSide, minX,minY,minZ, maxX,maxY,maxZ, EnumFacing.SOUTH, 16-x, Y, 16-X, y, spriteSide, spriteSide2);
                }
            else
                RenderFailed(Block.getIdFromBlock(type.block) + ":" + type.meta);
            Map<EnumFacing, List<BakedQuad>> fm = Maps.newEnumMap(EnumFacing.class);
            for (EnumFacing enumfacing : EnumFacing.values())
                fm.put(enumfacing, Lists.newArrayList());
            model = new SimpleBakedModel(faces, fm, true, true, spriteUp, ItemCameraTransforms.DEFAULT, ItemOverrideList.NONE);
        }

        private void addFaces(TextureData texture, float minX, float minY, float minZ, float maxX, float maxY, float maxZ, EnumFacing facing, float minU, float minV, float maxU, float maxV, TextureAtlasSprite sprite1, TextureAtlasSprite sprite2) {
            faces.add(MCreatorCobble.FaceBakery().makeBakedQuad(
                new Vector3f(minX,minY,minZ), new Vector3f(maxX,maxY,maxZ),
                new BlockPartFace(facing, texture.main.tint, texture.main.texture, new BlockFaceUV(new float[] {minU, minV, maxU, maxV}, 0)),
                sprite1, facing, ModelRotation.X0_Y0, null, true, true
            ));
            if (texture.secondary != null)
                faces.add(MCreatorCobble.FaceBakery().makeBakedQuad(
                    new Vector3f(minX,minY,minZ), new Vector3f(maxX,maxY,maxZ),
                    new BlockPartFace(facing, texture.secondary.tint, texture.secondary.texture, new BlockFaceUV(new float[] {minU, minV, maxU, maxV}, 0)),
                    sprite2, facing, ModelRotation.X0_Y0, null, true, true
                ));
        }
    }
}

I've tried a large number of things, including:

  • changing GlStateManager:
    • the blending profile (trying to set to "DEFAULT" causes an exception to occur: "java.lang.ArrayIndexOutOfBoundsException: -33984 at net.minecraft.client.renderer.GlStateManager.bindTexture(GlStateManager.java:483)")
    • matrix mode
    • color
    • blendFunc
    • alphaFunc
  • enabling/disabling GlStateManager:
    • lighting
    • light 0 through 7
    • blend
    • alpha
    • cull
    • depth
    • rescale normal

However I've been unable to find any combination of these that some much as changes the shading that is done on the block.

Any help or suggestions would be appritiated.
Also if my post is missing any important information please feel free to ask.

the block's full java file can be found here: MCreatorCobble.java

 

 

Edited by Aidanamite
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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