winnetrie Posted April 9, 2016 Share Posted April 9, 2016 Hello, I checked the BlockWall class and made my own. How would i check for other walls that have metadata? For example i have made walls based on the minecraft clayblocks. so 16 colors. I have this now: @Override public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4) { Block block = par1.getBlock(par2, par3, par4); if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall || block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall || block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall || block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall || block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall ){ return true; } return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true; } This works exactly how it should, but i wonder how i check for a block with metadata! I really have no clue how to do that. I have tried TemBlocks.claywall but that doesn't work Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
winnetrie Posted April 9, 2016 Author Share Posted April 9, 2016 what do you mean with update? update what? I have also no idea how to use this: IBlockAccess#getBlockMetadata I know getBlockMetadata, but .... I'll try some stuff Edit: I understand you don't want us to present chewed code. I do not ask for that either. But some vague words do not help me at all, i'm sorry. I'm 32 years old and i like programming, but i'm not that good skilled. I came to this forum desperately searching for help for things i really can't figure out! I know how to look into the minecraft classes and make my own extending them etc etc. I almost did everything by myself, except by following tutorials I hope you understand this thank you Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
winnetrie Posted April 9, 2016 Author Share Posted April 9, 2016 I'm using 1.7.10 because i like to have my own modded Cauldron server. Just because cauldron support both mods and plugins. Because there aren't any good enough (my opinion) antigriefing mods for 1.8 and higher, i'm forced to use GriefPrevention (plugin). I have already looked into how to mod in 1.8. I have set up a workspace for that. Now i'm being offtopic, so back to the topic: I know this is a method :getBlockMetadata I know it returns the meta when called. I also know how to use it. It returns an integer and that's my problem. I just don't know how the pieces fit together block==TemBlocks.claywalls for example an itemstack is much easier then you would do this: block == new ItemStack(TemBlocks.claywalls,1,0) But since i can't use itemstacks(ofc not) i can't check specific for that block with metadata 0 (in this example it's 0) Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
coolAlias Posted April 9, 2016 Share Posted April 9, 2016 for example an itemstack is much easier then you would do this: block == new ItemStack(TemBlocks.claywalls,1,0) That wouldn't work. For one, I assume 'block' is an instance of Block, which you are trying to test equality against an ItemStack. Totally different things. For another, ItemStack equality does not compare will with the '==' operator - that actually checks identity (Google it). If you want to test equality of a block + metadata, that is exactly what you do: // let's assume 'World world', 'Block block', int 'x', 'y', and 'z' are given as method parameters int meta = world.getBlockMetadata(x, y, z); if (block == TemBlocks.claywalls && meta == 0) { // there you go } Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
winnetrie Posted April 9, 2016 Author Share Posted April 9, 2016 Well first of all, what i said about that ItemStack stuff was just an example. I know you can't use that in there. I thought i made that clear. Sorry but my english isn't that good, wich results is bad explanations sometimes. ok so second i tried this already before and it doesn't work: @Override public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4) { Block block = par1.getBlock(par2, par3, par4); int meta = par1.getBlockMetadata(par2, par3, par4); //int meta = par1.getBlockMetadata(par2, par3, par4); if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall || block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall || block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall || block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall || block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall ){ return true; } if ((block==TemBlocks.claywalls && meta ==0) || (block==TemBlocks.claywalls && meta ==1) || (block==TemBlocks.claywalls && meta ==2) || (block==TemBlocks.claywalls && meta ==3) || (block==TemBlocks.claywalls && meta ==4) || (block==TemBlocks.claywalls && meta ==5)){ return true; } return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true; } I haven't provided a World parameter because i'm overriding the method. It doesn't ask me for a world. So i used the first parameter. For me it seems like it doesn't do anything. This code was what i came up by myself, but since it didn't worked i came asking help here Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
coolAlias Posted April 9, 2016 Share Posted April 9, 2016 IBlockAccess is roughly equivalent to a World object. Instead of that mess of conditions, you could greatly simplify it: if (block instanceof BlockWall) { return true; // this should cover almost that entire wall of text } // this one: if ((block==TemBlocks.claywalls && meta ==0) || (block==TemBlocks.claywalls && meta ==1) || (block==TemBlocks.claywalls && meta ==2) || (block==TemBlocks.claywalls && meta ==3) || (block==TemBlocks.claywalls && meta ==4) || (block==TemBlocks.claywalls && meta ==5)){ return true; } // can be changed to: if (block==TemBlocks.claywalls && meta < 6) { return true; } // you'll want to check that one before the instanceof BlockWall check, however, or meta will be ignored // and this part: block != this // do you not want your wall blocks to be able to connect to themselves? Seems weird, but okay If it's not working as you expect, try something simpler at first: always return true. Does your block connect to everything? Good, at least you know that part is working, and now you can start introducing some logic into it one piece at a time. If it didn't work, then you can rule out your #canConnectWallTo implementation as the problem and begin looking elsewhere for issues. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
jeffryfisher Posted April 9, 2016 Share Posted April 9, 2016 Using "instanceof" means that your walls will connect to any other mod's walls that extend BlockWall. That would mean that yours would connect to mine (see Uncle Jeff's Anystone Walls at CurseForge), and mine would connect to yours. Also: Don't forget gates (using the same "instanceof" so you connect to my iron gate etc). Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting. Link to comment Share on other sites More sharing options...
coolAlias Posted April 9, 2016 Share Posted April 9, 2016 Using "instanceof" means that your walls will connect to any other mod's walls that extend BlockWall. That would mean that yours would connect to mine (see Uncle Jeff's Anystone Walls at CurseForge), and mine would connect to yours. Also: Don't forget gates (using the same "instanceof" so you connect to my iron gate etc). 'instanceof BlockWall' means that yes, but not 'instanceof' - he can use 'instanceof CustomBlockWall' or whatever his Block class is and restrict the connections to his custom wall blocks instead of allowing all, if that's what he wants, but I assumed he would want them to connect to other walls as well (the logical thing to allow in most cases). Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
winnetrie Posted April 9, 2016 Author Share Posted April 9, 2016 Ok i found the problem.... For some reason i made my metawalls having each a different id, so i remade my CustomWallsColored.class so it has metadata. Really i facepalmed when i figured that out lol. So now it works perfectly and it looks like this: @Override public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4) { Block block = par1.getBlock(par2, par3, par4); int meta = par1.getBlockMetadata(par2, par3, par4); //int meta = par1.getBlockMetadata(par2, par3, par4); if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall || block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall || block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall || block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall || block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall){ return true; } for(int i=0; i<16; i++){ if ((block==TemBlocks.claywalls && meta ==i) || (block==TemBlocks.claybrickwalls && meta ==i) || (block==TemBlocks.brickswalls && meta ==i) ){ return true; } } return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true; } I also made a for loop to shorten the code. I will take a look at that "instanceof", it would be much better if it can connect to any wall of any mod. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
coolAlias Posted April 9, 2016 Share Posted April 9, 2016 Your for loop is kinda... pointless. for(int i=0; i<16; i++){ if ((block==TemBlocks.claywalls && meta ==i) || (block==TemBlocks.claybrickwalls && meta ==i) || (block==TemBlocks.brickswalls && meta ==i) ){ return true; } } If you think about what that is doing, i starts at 0 and goes all the way to 15, so every value less than 16, which is every possible metadata value for a Block... why even check? And if you DO want to check meta for some reason, why do it in a for loop when you can just check it like this: if (meta < 16 && (block==TemBlocks.claywalls || block==TemBlocks.claybrickwalls || block==TemBlocks.brickswalls)) { // the block is one of the ones you want and the meta is from 0 to 15... // same exact logic as your for loop, but far more efficient and succinct } Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
winnetrie Posted April 9, 2016 Author Share Posted April 9, 2016 I don't think my for loop is pointless, because it cycles trough all the metadata. That's the point of it. If i don't make that check the walls do not connect to eachother. I tried that before! Ofc your stuff works also. Mine code checks every metadata and your checks is it's smaller than 16. I agree to the "same exact logic" but not the far more efficient. Perhaps yours is a bit more efficient. I learned to use for loops in c++ because they are very powerfull and fast. So why would that be different in java? Besides that i like to use for loops and my code works. Even more important is knowing what the code does and so i do! Anyway i thank you for posting your variant Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
Draco18s Posted April 10, 2016 Share Posted April 10, 2016 I don't think my for loop is pointless, because it cycles trough all the metadata. And then doesn't give a shit what the actual value of the metadata was, because it performed the same check on all of them: meta == i It doesn't matter what value meta was from the world (because it can only be 0 to 15), at some point during that loop that check will be true. Following that, because you are doing return true in the block-check, as soon as it determines that yes, one of these blocks is what we're looking for it never even fucking checks your loop. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given. Link to comment Share on other sites More sharing options...
coolAlias Posted April 10, 2016 Share Posted April 10, 2016 To be fair, the blocks in the for loop are not included in the preceding if statement, but that does not mean the for loop has a point. Just think about it step by step: for loop breaks down to this, basically: if (block correct and 0 == meta) return true; if (block correct and 1 == meta) return true; if (block correct and 2 == meta) return true; // and on up to 15 So, if at any point the metadata value is the same as i, you return true. The metadata value can only be a value from 0 to 15, and you check ALL of those values, so by very nature of the code, at some point i has to equal the metadata value, making the metadata value and thus your for loop completely unnecessary. It literally does nothing different than simply checking if (block == clayWall) for those 3 blocks. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
jeffryfisher Posted April 10, 2016 Share Posted April 10, 2016 Just use the elegant block instanceof BlockWall expression already so you won't need this discussion of loops and meta values. And don't forget what I said about gates. For that matter, you might want to think about fences too. Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting. Link to comment Share on other sites More sharing options...
winnetrie Posted April 10, 2016 Author Share Posted April 10, 2016 I removed the for loop and changed it to this: block==TemBlocks.claywalls || block==TemBlocks.claybrickwalls || block==TemBlocks.brickswalls So apparently i do not need to check metadata. I tried this before and it didn't worked, but that's because i created the walls wrong (they had no metadata at all, and now they do) Thanks for those who helped me out, i really appreciate it. @Draco18s : I think you "shit" and "fucks" to much. You can talk to me like a normal person. I would appreciate that. I'm just a normal guy 32 years old who likes to learn something new. If you want to talk to me like a 12 year old wannebecoolboy, srry i don't have time for this. If you wanne help me out like an adult or (if you aren't an adult) like a child with good manners, i will be very happy to hear from you. thank you for understanding. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
Draco18s Posted April 11, 2016 Share Posted April 11, 2016 @Draco18s : I think you "shit" and "fucks" to much. You can talk to me like a normal person. I would appreciate that. I'm just a normal guy 32 years old who likes to learn something new. If you want to talk to me like a 12 year old wannebecoolboy, srry i don't have time for this. And we don't have time to have you ignore what we tell you three times. You know, like this bit: So apparently i do not need to check metadata. That was pointed out to you at least twice, this is not a surprise revelation. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given. Link to comment Share on other sites More sharing options...
winnetrie Posted April 11, 2016 Author Share Posted April 11, 2016 So let's call it a communication issue I didn't understood at first that this was your point. There was also made a mistake by me, created a block without meta while i was convinced it had meta. It works now, so thnx all for the help. This case is solved now. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
jeffryfisher Posted April 11, 2016 Share Posted April 11, 2016 Your expression does not address gates. Shouldn't your walls connect to gates? And what about other mods? Don't you want to connect to other extensions of BlockWall? And what about torches? Can you put a torch on top of your wall? Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting. Link to comment Share on other sites More sharing options...
winnetrie Posted April 26, 2016 Author Share Posted April 26, 2016 Your expression does not address gates. Shouldn't your walls connect to gates? And what about other mods? Don't you want to connect to other extensions of BlockWall? And what about torches? Can you put a torch on top of your wall? Srry, i didn't saw your post untill now. Even when it's fixed now, i can still post what i have. You'll never know if someone could find his answers here. So here it is: package winnetrie.tem.block; import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockFence; import net.minecraft.block.BlockFenceGate; import net.minecraft.block.BlockWall; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class CustomWalls extends BlockWall { private Block icon; private int metaType; public CustomWalls(Block block, int meta) { super(block); this.useNeighborBrightness=true; this.setCreativeTab(TemBlocks.extrawalls); this.icon=block; this.metaType=meta; } @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int meta) { return icon.getIcon(side, metaType); } @Override @SideOnly(Side.CLIENT) public void getSubBlocks(Item itemstack, CreativeTabs tabs, List list) { list.add(new ItemStack(itemstack, 1, 0)); } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister p_149651_1_) {} public int getRenderType() { return 32; } public boolean renderAsNormalBlock() { return false; } @Override public boolean canPlaceTorchOnTop(World world, int x, int y, int z){ return true; } @Override public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4) { Block block = par1.getBlock(par2, par3, par4); int meta = par1.getBlockMetadata(par2, par3, par4); return block== this || block instanceof BlockWall || block.isOpaqueCube() || block instanceof BlockFenceGate || block instanceof BlockFence ; } } Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization Link to comment Share on other sites More sharing options...
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.