Posted December 13, 201212 yr Sorry if this question has already been asked a thousand times. I was not able to find anything with the search function. I am making a mod that includes blocks reacting to redstone. One (very) basic type of reaction to redstone is changing the block texture. So, this is the way I implemented it: @Override public void onNeighborBlockChange(World world, int xCoord, int yCoord, int zCoord, int neighborID) { isRedstonePowered = world.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); if (isRedstonePowered) { this.blockIndexInTexture = 0; } else { this.blockIndexInTexture = 1; } } where isRedstonePowered is a boolean declared in TestBlock.java (the block class from which this code is taken). This code works perfectly, changing the texture of the block if it is activated and changing it back when it loses the redstone signal. But it works a bit too much, it actually changes the texture for all the same blocks in the world and even the block in the hotbar (by powering a single block, all the blocks of the same kind change texture) and i obviously do not want that, i only want the powered block to change... Is there a way to do that? EDIT: i might end up using the vanilla furnace code if i don't find any other solution, but i don't like it very much because it implies adding some more blocks... (code in spoiler) public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4) { int var5 = par1World.getBlockMetadata(par2, par3, par4); TileEntity var6 = par1World.getBlockTileEntity(par2, par3, par4); keepFurnaceInventory = true; if (par0) { par1World.setBlockWithNotify(par2, par3, par4, Block.stoneOvenActive.blockID); } else { par1World.setBlockWithNotify(par2, par3, par4, Block.stoneOvenIdle.blockID); } keepFurnaceInventory = false; par1World.setBlockMetadataWithNotify(par2, par3, par4, var5); if (var6 != null) { var6.validate(); par1World.setBlockTileEntity(par2, par3, par4, var6); } }
December 14, 201212 yr When you do either this.blockIndexInTexture = 0 or this.blockIndexInTexture = 1 What class is "this". If it is changing the texture of every block in the world, you need to be selecting a specific block (x,y,z coords) and then changing the texture. If I helped you, thank me. If I didn't, let me know.
December 14, 201212 yr you could use metadata to signify whether or not it is powered and have the block change texture depending on the metadata, using getBlockTexture
December 14, 201212 yr Author thanks for the answers, i actually ended up using a code similar to the one used in the furnace. i have 2 blocks and switch between them with setblockwithnotify(), and they have different textures. @jammas615: i found out that it was exactly the "this" that was causing problem, because it pointed at TestBlock class which is the class for every Test Block in the world, not a single instance... thanks for making me understand that
December 14, 201212 yr thanks for the answers, i actually ended up using a code similar to the one used in the furnace. i have 2 blocks and switch between them with setblockwithnotify(), and they have different textures. @jammas615: i found out that it was exactly the "this" that was causing problem, because it pointed at TestBlock class which is the class for every Test Block in the world, not a single instance... thanks for making me understand that It would probably be better to switch between metadata in this case, unless you change stuff like light level. It'll save a block id for something else
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.