Jump to content

[1.7.10] How to change textures of a custom rendered model?


nivla2525

Recommended Posts

I have a custom rendered block using a techne model, I'm trying to make a light that toggles textures and light values on right click. The way I have it set up is I have 2 blocks with a boolean parameter and points to a class. That class sets it's light value to 1.0F if true, 0F is false. When you right click the block runs world.setBlock and sets it to the other block. All the code is working fine except I tried many time and failed to get the texture to change when it changes the block. I am using one render class, I tried to use an if statement for determining which block it is and thus sending which resource location to the bindtexture method but it seems to only render the texturemap of the path I initialized it with (you can't leave the resource location blank otherwise it crashes).

 

Any help on what I can do?

Link to comment
Share on other sites

Code would be helpful...

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I should have fixed the problem I had earlier with this code

 

TESR class

public class RenderLight extends TileEntitySpecialRenderer
{
private static Map<Integer, ResourceLocation> textures = new HashMap<Integer, ResourceLocation>();
    private final ModelLight model;

    static
    {
        //metadata, texture location
        textures.put(0, new ResourceLocation(SMOMAIN.MODID + ":" + "textures/model/light0.png"));
        textures.put(1, new ResourceLocation(SMOMAIN.MODID + ":" + "textures/model/light1.png"));
        for(int i = 0; i < 2; i++)
        {
            textures.put(i, new ResourceLocation(SMOMAIN.MODID + ":" + "textures/model/light" + i + ".png"));
        }
    }

    public RenderLight()
    {
        this.model = new ModelLight();
    }

    public void bindTexture(TileEntity tile)
    {
        // Gets the metadata from the tile
        int metadata = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
        if(textures.containsKey(metadata))
        {
            Minecraft.getMinecraft().renderEngine.bindTexture(textures.get(metadata));
        }
        else
        {
            // If not, it will crash so that you know that you're missing a texture
            throw new IllegalArgumentException(metadata + " doesn't have a valid texture!");
        }
    }

    @Override
    public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f)
    {
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x +0.5F, (float)y + 1.5F, (float)z + 0.5F);
        if(tileentity != null) 
        	this.bindTexture(tileentity);
        GL11.glPushMatrix();
        GL11.glRotatef(180, 0F, 0F, 1F);
        this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
    }
}

 

but now I have problems with my ItemRender class

Public class ItemRenderLight implements IItemRenderer
{
        TileEntitySpecialRenderer render;
private TileEntity entity;

public ItemRenderLight(TileEntitySpecialRenderer render, TileEntity entity)
{
	this.entity = entity;
	this.render = render;
}
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {

	return true;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,
		ItemRendererHelper helper) 
{	
	return true;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	if(type == IItemRenderer.ItemRenderType.ENTITY)
	GL11.glTranslatef(-0.5F, 0F, -0.5F);
	this.render.renderTileEntityAt(this.entity,0.0D, 0.0D, 0.0D, 0.0F);
}
}

 

I even tried using another way for rendering it

public class ItemRenderLight implements IItemRenderer
{
private ModelLight model;
public void RenderLight()
{
	model = new ModelLight();
}

public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
	return true;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
	return true;
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
	GL11.glPushMatrix();
	GL11.glScalef(-1F, -1F, 1F);
	switch (type)
	{
	case INVENTORY:
		GL11.glTranslatef(0, 0.12F, 0);
		break;
	case EQUIPPED:
		GL11.glTranslatef(-0.8F, -0.2F, 0.7F);
		break;
	case EQUIPPED_FIRST_PERSON:
		GL11.glTranslatef(0F, -0.7F, 0.7F);
	default:
	}
	Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("textures/model/light0.png"));
	model.render(null, 0F, 0F, -0.1F, 0F, 0F, 0.0625F);
	GL11.glPopMatrix();
}
}

 

In my client proxy I have this which should be right: MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(SMOMAIN.light), new ItemRenderLight());

 

The game loads up fine but crashes when I load  a world and see the item in the inventory, the crash log gave me this....

 

Caused by: java.lang.NullPointerException

at com.shadowbyte.SwordMineOnline.ItemRenderLight.renderItem(ItemRenderLight.java:45) ~[itemRenderLight.class:?]

 

Any ideas?

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://drive.google.com/file/d/1M0EG-c5yfRd08DSnE5HVQNCu2v0YtA7A/view?usp=sharing  
    • so im not sure if your still watching this TileEntity but once we loaded a FTB modpack we wanted to run on the server it no longer seems to run. The console opens like normal but we've been sitting here for like a little over an hour and the server screen has not yet opened. Should we just keep waiting at this point?
    • I have now easily fixed the duplication error present, I was just not looking.   I have been working for the past half hour to try and fix another error present, this time with the Creative Mode Tab.   I have changed some things around to get where I am currently. (ModFoods to ModDrinks*) and it cannot find the symbol ".get" at the end of the code. *The custom class you recommended pOutput.accept(ModDrinks.ORANGE_JUICE.get()); I think the point I am at currently is the closest I have to how it should be but because I am not as experienced with java I would not know.  I have also removed ORANGE_JUICE and LEMON_JUICE from the ModFoods class, to avoid confliction. I do hope all this can be fully resolved soon.  
    • [SOLVED]  public class RenderGUIHandler { @SubscribeEvent public void renderGUI(RenderGameOverlayEvent.Text event){ Client.hud.draw(); } } As I was playing around a little with the code, i found out about an option to change The RenderGameOverlayEvent.Post to RenderGameOverlayEvent.Text
    • public class HUD { public Minecraft mc = Minecraft.getMinecraft(); public static class ModuleComparator implements Comparator<Module>{ @Override public int compare(Module o1, Module o2) { if (Minecraft.getMinecraft().fontRendererObj.getStringWidth(o1.name) > Minecraft.getMinecraft().fontRendererObj.getStringWidth(o2.name)){ return -1; } if (Minecraft.getMinecraft().fontRendererObj.getStringWidth(o1.name) < Minecraft.getMinecraft().fontRendererObj.getStringWidth(o2.name)){ return 1; } return 0; } } public void draw(){ ScaledResolution sr = new ScaledResolution(mc); FontRenderer fr = mc.fontRendererObj; Collections.sort(Client.modules, new ModuleComparator()); GlStateManager.pushMatrix(); GlStateManager.translate(4,4,0); GlStateManager.scale(1.5,1.5,1); GlStateManager.translate(-4, -4, 0); fr.drawString("Skyline", 10, 10, -1); GlStateManager.popMatrix(); int count = 0; for (Module m : Client.modules){ if (!m.toggled || m.name.equals("TabGUI")) continue; int offset = count* (fr.FONT_HEIGHT + 6); GL11.glTranslated(0.0f, 0.0f, -1.0f); Gui.drawRect(sr.getScaledWidth() - fr.getStringWidth(m.name) - 10, offset, sr.getScaledWidth() - fr.getStringWidth(m.name) - 8, 6 + fr.FONT_HEIGHT + offset, -1); Gui.drawRect(sr.getScaledWidth() - fr.getStringWidth(m.name) - 8, offset, sr.getScaledWidth(), 6 + fr.FONT_HEIGHT + offset, 0x90000000); fr.drawString(m.name, sr.getScaledWidth() - fr.getStringWidth(m.name) - 4, offset + 4, -1); count++; } Client.onEvent(new EventRenderGUI()); } } I have just recently stumbled upon this Problem, where the HudRenderer renders the wrong section of the textures and therefore completely destroys the Minecraft Armour and Hunger Bar. I am currently thinking if it is an issue with the DrawRect changing something it shouldn't. But I couldn't find anything about it. (To keep things Clean, the function is Called from another file) public class RenderGUIHandler { @SubscribeEvent public void renderGUI(RenderGameOverlayEvent.Post event){ Client.hud.draw(); } } Any help would be greatly appreciated  
  • Topics

×
×
  • Create New...

Important Information

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