Jump to content

Strange Item Rendering Glitch - Dark Blocks in Inventory


Recommended Posts

Posted

I used an online tutorial to accomplish what BuildCraft, Redpower, and other big mods do to render custom-modelled blocks as 3D items in the inventory, using the ItemRendering system...

...And it caused a very strange error. Blocks - and only full-cube "Render Type 0" blocks - in the inventory will, when under a cursor, in the hotbar, or when my custom creative inventory tab is open, render rather darker than normal. Even more strangely, if I disable the rendering of a few of my custom blocks (Fan, Shaft, and Bridge Emitter - see code), this restricts to only in my custom inventory tab.

vjgeN9Q.png

My ItemRenderer code:

public class ItemMachineRenderer implements IItemRenderer {

private ModelAC acModel;
private ModelAerosolizer aeroModel;
private ModelBevel bevelModel;
private ModelBridge bridgeModel;
private ModelClutch clutchModel;
private ModelCombustion combustionModel;
private ModelCompactor compactorModel;
private ModelDC dcModel;
private ModelExtractor extractorModel;
private ModelFan fanModel;
private ModelFlywheel flywheelModel;
private ModelGearbox gearModel;
private ModelGearbox16 gearModel16;
private ModelGearbox8 gearModel8;
private ModelGearbox4 gearModel4;
private ModelHRay rayModel;
private ModelLamp lampModel;
private ModelPulseFurnace pulseModel;
private ModelPump pumpModel;
private ModelReservoir reservoirModel;
private ModelShaft shaftModel;
private ModelShaftV shaftvModel;
private ModelSteam steamModel;

private int Renderid;
private int engineType;
private int metadata;
private float floatControl;
//public static final float cheatControl = -200F;

public ItemMachineRenderer(int id) {

	acModel = new ModelAC();
	aeroModel = new ModelAerosolizer();
	bevelModel = new ModelBevel();
	bridgeModel = new ModelBridge();
	clutchModel = new ModelClutch();
	combustionModel = new ModelCombustion();
	compactorModel = new ModelCompactor();
	dcModel = new ModelDC();
	extractorModel = new ModelExtractor();
	fanModel = new ModelFan();
	flywheelModel = new ModelFlywheel();
	gearModel = new ModelGearbox();
	gearModel16 = new ModelGearbox16();
	gearModel8 = new ModelGearbox8();
	gearModel4 = new ModelGearbox4();
	rayModel = new ModelHRay();
	lampModel = new ModelLamp();
	pulseModel = new ModelPulseFurnace();
	pumpModel = new ModelPump();
	reservoirModel = new ModelReservoir();
	shaftModel = new ModelShaft();
	shaftvModel = new ModelShaftV();
	steamModel = new ModelSteam();

	Renderid = id;
	if (id == 0) {

	}
	if (id ==  {
		switch(this.metadata/4) {
		case 0:
			floatControl = -1000;
		break;
		case 1:
			floatControl = -2000;
		break;
		case 2:
			floatControl = -3000;
		break;
		case 3:
			floatControl = -4000;
		break;
		}
	}
}

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	//this.metadata = item.getItemDamage();
	if (item.itemID == mod_RotaryCraft.fan.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.aerosolizer.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.engine.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.bridgeemitter.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.clutch.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.compactor.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.extractor.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.floodlight.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.flywheel.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.gbevel.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.gearbox.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.heatray.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.pulsejet.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.pump.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.reservoir.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.shaft.blockID)
		return true;
	if (item.itemID == mod_RotaryCraft.splitter.blockID)
		return true;
	return false;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
	if (type.equals(helper.BLOCK_3D))
		return false;
	return true;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	switch (Renderid) {
	case 0:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityEngine(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 1:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityAerosolizer(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 2:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityGearBevel(), 0.0D, -0.1D, 0.0D, 0.0F);
	break;
	case 3:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityBridgeEmitter(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 4:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityClutch(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 5:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityCompactor(), 0.0D, -0.1D, 0.0D, 0.0F);
	break;
	case 6:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityExtractor(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 7:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityFan(), 0.0D, -0.1D, 0.0D, 0.0F);
	break;
	case 8:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityFlywheel(), 0.0D, 0.0D, 0.0D, floatControl);
	break;
	case 9:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityGearbox(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 10:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityHeatRay(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 11:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityFloodlight(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 12:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityPulseFurnace(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 13:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityPump(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	case 14:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityReservoir(), 0.0D, -0.1D, 0.0D, 0.0F);
	break;
	case 15:
		TileEntityRenderer.instance.renderTileEntityAt(new TileEntityShaft(), 0.0D, 0.0D, 0.0D, 0.0F);
	break;
	}
}

 

And the relevant part of my ClientProxy:

	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.engine.blockID, new ItemMachineRenderer(0));

	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.aerosolizer.blockID, new ItemMachineRenderer(1));		
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.gbevel.blockID, new ItemMachineRenderer(2));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.bridgeemitter.blockID, new ItemMachineRenderer(3));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.clutch.blockID, new ItemMachineRenderer(4));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.compactor.blockID, new ItemMachineRenderer(5));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.extractor.blockID, new ItemMachineRenderer(6));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.fan.blockID, new ItemMachineRenderer(7));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.flywheel.blockID, new ItemMachineRenderer();
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.gearbox.blockID, new ItemMachineRenderer(9));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.heatray.blockID, new ItemMachineRenderer(10));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.floodlight.blockID, new ItemMachineRenderer(11));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.pulsejet.blockID, new ItemMachineRenderer(12));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.pump.blockID, new ItemMachineRenderer(13));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.reservoir.blockID, new ItemMachineRenderer(14));
	MinecraftForgeClient.registerItemRenderer(mod_RotaryCraft.shaft.blockID, new ItemMachineRenderer(15));

Posted

OK...this is strange. I have not changed any of my rendering code (though I have added classes like new Tile Entities, new GUIs, and the like), but the behavior of my glitch changed. In the OP I said I could limit it to my custom creative tab by disabling 3 renders...now it is limited there even with the renders enabled...

 

This is an improvement, but HOW did it change itself?

Posted

Make sure you have glEnable(GL_LIGHTING); in your rendering filles if you are disabling lighting. (pretty sure that's all it is)

Nice looking stuff by the way

I think its my java of the variables.

Posted

OK, it built and ran without error, but it also had no effect.

Sample code:

public class RenderHRay extends TileEntitySpecialRenderer
{
    /** The normal small chest model. */
    private ModelHRay HRayModel = new ModelHRay();

    /**
     * Renders the TileEntity for the position.
     */
    public void renderTileEntityHeatRayAt(TileEntityHeatRay par1TileEntity, double par2, double par4, double par6, float par8)
    {
        int var9;

        if (par1TileEntity.worldObj == null)
        {
            var9 = 0;
        }
        else
        {
            Block var10 = par1TileEntity.getBlockType();
            var9 = par1TileEntity.getBlockMetadata();

            if (var10 != null && var9 == 0)
            {
                //((BlockHRayBlock1)var10).unifyAdjacentChests(par1TileEntity.worldObj, par1TileEntity.xCoord, par1TileEntity.yCoord, par1TileEntity.zCoord);
                var9 = par1TileEntity.getBlockMetadata();
            }
        }

        if (true)
        {
            ModelHRay var14;

            if (true)
            {
                var14 = this.HRayModel;
                this.bindTextureByName("/Reika/RotaryCraft/HRay.png");
            }

            GL11.glPushMatrix();
            GL11.glEnable(GL12.GL_RESCALE_NORMAL);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            GL11.glTranslatef((float)par2, (float)par4 + 2.0F, (float)par6 + 1.0F);
            GL11.glScalef(1.0F, -1.0F, -1.0F);
            GL11.glTranslatef(0.5F, 0.5F, 0.5F);
            int var11 = 0;	 //used to rotate the model about metadata
            
            if (par1TileEntity.worldObj != null) {
            
            switch(par1TileEntity.getBlockMetadata()) {
            case 0:
            	var11 = 0;
            break;
            case 1:
            	var11 = 180;
            break;
            case 2:
            	var11 = 270;
            break;
            case 3:
            	var11 = 90;
            break;
            }

            GL11.glRotatef((float)var11+90, 0.0F, 1.0F, 0.0F);
            }
            else {
            	GL11.glEnable(GL11.GL_LIGHTING);
            }
            
            //GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
            //float var12 = par1TileEntity.prevLidAngle + (par1TileEntity.lidAngle - par1TileEntity.prevLidAngle) * par8;
            float var13;/*

            var12 = 1.0F - var12;
            var12 = 1.0F - var12 * var12 * var12;*/
            var14.renderAll();
            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
            GL11.glPopMatrix();
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        }
    }

    public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8)
    {
        this.renderTileEntityHeatRayAt((TileEntityHeatRay)par1TileEntity, par2, par4, par6, par8);
    }
}

  • 2 weeks later...
Posted

After some messing around, using Lighting Disable will fix the problem, but it also makes the blocks look completely wrong (they do not render the shading correctly, and look "overexposed").

Ncnqmrc.png

 

So ... does it fix the problem or not :D If it does, disable the lighting when rendering and enable it when you exit the scope.

Posted

After some messing around, using Lighting Disable will fix the problem, but it also makes the blocks look completely wrong (they do not render the shading correctly, and look "overexposed").

Ncnqmrc.png

 

So ... does it fix the problem or not :D If it does, disable the lighting when rendering and enable it when you exit the scope.

That is what I did. Also, it does not fix blocks that are "under the cursor" (being moved between slots).

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.