Posted September 13, 201312 yr Ok, so basically what I want to have is a block that has one texture when the player isn't wearing a certain helmet, and a different one when they do. Right now, I've got the block all set up, as well as a TileEntity that detects whether or not the nearest player is wearing this helmet (which is already fully implemented). The problem is, I can't get the info from the TileEntity every tick in the block to set the texture, and I can't set the texture from the TileEntity. Somebody suggested a TESR or an ISBRH. I haven't delved too much into block rendering, so I really don't know how to implement one or which one I should even use. Any help would be greatly appreciated
September 13, 201312 yr Just to make sure, do you want any player to see the second texture if one player is close enough to the block with the helmet ? If you do, then TESR would be easier. If you don't, then ISBRH, with Minecraft.thePlayer.getCurrentArmor(... , and the tile entity is unneeded.
September 13, 201312 yr Author OK, sounds like the ISBRH way is best, but I can't figure out how to use it. I don't have a param of Minecraft in any of my methods, and even if I did I can't seem to find the thePlayer field. If someone could write some example code or point me towards a tutorial that would be awesomazing. EDIT: Made a bit of progress, just realised I have to use Minecraft.getMinecraft.etc... thanks! Haven't got it fully working yet, if I do /don't I will post here!
September 14, 201312 yr Author OK, so the code appears to be slightly unreasonable today, so I'll just post my source and hope somebody knows where I went wrong. Block Class package EnderLore.block; import java.util.Random; import EnderLore.tileentity.TileEntityEnderOre; import net.minecraft.block.material.Material; import net.minecraft.block.Block; import net.minecraft.block.BlockOre; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; public class BlockEnderOre extends Block { public BlockEnderOre(int id, Material material) { super(id, material); } } Relevant Part of Main Class ISimpleBlockRenderingHandler OreISBRH = new RenderEnderOre(); RenderingRegistry.registerBlockHandler(EnderOre.getRenderType(), OreISBRH); In the load() method. ISBRH Class package EnderLore.render; import EnderLore.block.BlockEnderOre; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.RenderingRegistry; public class RenderEnderOre implements ISimpleBlockRenderingHandler { @Override public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { renderer.renderBlockAsItem(block, 0, 1F); } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { // TODO Auto-generated method stub renderer.renderStandardBlock(block, x, y, z); block.func_111022_d(getOreTexture()); return false; } @Override public boolean shouldRender3DInInventory() { return false; } @Override public int getRenderId() { return RenderingRegistry.getNextAvailableRenderId(); } public String getOreTexture(){ if(Minecraft.getMinecraft().thePlayer.getCurrentArmor(0).itemID == EnderLore.EnderLore.HelmetOfSeeing.itemID){ return "EnderLore:EnderOre"; } else { return "stone"; } } } Do I need something registered in the Client Proxy? If so, how? or did I just make some really basic mistake? Any help greatly appreciated!
September 14, 201312 yr Hi A couple of comments might help 1) in renderWorldBlock you need to override the texture before calling renderStandardBlock, not afterwards 2) It might be easier just to override Block.getIcon() and put your texture selection in here (see http://greyminecraftcoder.blogspot.com.au/2013/07/rendering-standard-blocks-cubes.html) Also, Minecraft doesn't update the appearance of the blocks every tick, only when you have made a change (eg placed a block). So if you put your helmet on or off, you will need to force Minecraft to re-update the scene otherwise you won't see any change. http://greyminecraftcoder.blogspot.com.au/2013/07/rendering-world-more-details-including.html Cheers TGG
September 14, 201312 yr the easyest way(like in Thaumcraft with auras) to do that: if (Minecraft.getMinecraft().thePlayer.youCheckIfHelmetIsOn) return OneTexture; else return OtherTexture; p.s. but to make it work it need to be updated,sooo just call setBlock with you id and meta,if you want or make block to be re rendered with Minecraft.getMinecraft().renderGlobal.markBlockNeedsUpdate(x, y, z); but when update? when player changing helmet,that is when.You can check when player changing helmet with TickHandler(google TickHandler)
October 22, 201311 yr Author OK so now what I have is a block that has the wireframe thing around it, and collides properly, but are completely invisible. I guess the textures aren't working... I guess I'll dump my code again and hope for some help... Block Class package EnderLore.block; import java.util.Random; import cpw.mods.fml.client.registry.RenderingRegistry; import EnderLore.tileentity.TileEntityEnderOre; import net.minecraft.block.material.Material; import net.minecraft.block.Block; import net.minecraft.block.BlockOre; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; public class BlockEnderOre extends Block { public BlockEnderOre(int id, Material material) { super(id, material); } @Override public int getRenderType(){ return RenderingRegistry.getNextAvailableRenderId(); } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } protected boolean canSilkHarvest() { return true; } } Renderer Class package EnderLore.render; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.world.IBlockAccess; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.RenderingRegistry; public class RenderEnderOre implements ISimpleBlockRenderingHandler { @Override public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { renderer.renderBlockAsItem(block, 0, 1F); } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { block.func_111022_d("EnderLore:EnderOre"); renderer.renderStandardBlock(block, x, y, z); return false; } @Override public boolean shouldRender3DInInventory() { return false; } @Override public int getRenderId() { return RenderingRegistry.getNextAvailableRenderId(); } public String getOreTexture(){ if(Minecraft.getMinecraft().thePlayer.getCurrentArmor(0).itemID == EnderLore.EnderLore.HelmetOfSeeing.itemID){ return "EnderLore:EnderOre"; } else { return "stone"; } } } The block and the renderer are both registered in the main class also.
October 23, 201311 yr Hi Every time you call RenderingRegistry.getNextAvailableRenderID, it returns a new number. Your code should call it once only for your new Block + Renderer, store it, and return this value instead of calling getNextAvailableRenderID every time. -TGG
October 25, 201311 yr Author OK... not sure how I missed that Anyway, now they render the the missing texture thing if there is a block within a seemingly random area around them that isn't one of them, otherwise they are invisible... weird. I will take another look at my code I guess.
October 26, 201311 yr Author OK, so now the custom blocks always render as stone, and any blocks within a certain area of them (it seems to be different for every one) is also rendered as stone. weird, eh? I guess I'll dump my code again Render Class package EnderLore.render; import EnderLore.block.BlockEnderOre; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.RenderingRegistry; public class RenderEnderOre implements ISimpleBlockRenderingHandler { Icon icon; @Override public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { renderer.renderBlockAsItem(block, 0, 0); } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { getOreTexture((BlockEnderOre) block); renderer.overrideBlockTexture = icon; renderer.renderStandardBlock(block, x, y, z); return false; } @Override public boolean shouldRender3DInInventory() { // TODO Auto-generated method stub return false; } @Override public int getRenderId() { // TODO Auto-generated method stub return BlockEnderOre.EnderOreID; } public void getOreTexture(BlockEnderOre block){ if(Minecraft.getMinecraft().thePlayer.getCurrentArmor(0).itemID == EnderLore.EnderLore.HelmetOfSeeing.itemID){ icon = block.oreIcon; } else { icon = block.stoneIcon; } } } Block Class package EnderLore.block; import java.util.Random; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import EnderLore.EnderLore; import EnderLore.tileentity.TileEntityEnderOre; import net.minecraft.block.material.Material; import net.minecraft.block.Block; import net.minecraft.block.BlockOre; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; public class BlockEnderOre extends Block { public Icon stoneIcon; public Icon oreIcon; public static int EnderOreID = RenderingRegistry.getNextAvailableRenderId(); public BlockEnderOre(int id, Material material) { super(id, material); } @Override public int getRenderType(){ return EnderOreID; } protected boolean canSilkHarvest() { return true; } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { oreIcon = par1IconRegister.registerIcon("EnderLore:EnderOre"); stoneIcon = par1IconRegister.registerIcon("stone"); } } EDIT: Fixed the issue thanks to some awesome coder guys on IRC. If you have a similar issue PM me and I can give you my solution.
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.