nivla2525 Posted March 24, 2015 Posted March 24, 2015 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? Quote
SanAndreaP Posted March 25, 2015 Posted March 25, 2015 Code would be helpful... Quote 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.
nivla2525 Posted March 28, 2015 Author Posted March 28, 2015 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? Quote
nivla2525 Posted March 28, 2015 Author Posted March 28, 2015 Ok... But BOTH of them don't work, the other one doesn't have that constructor/what ever it is.... Quote
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.