Posted July 17, 201411 yr Hello, I would like to know how to get a custom block to "absorb" all blocks around it that aren't air. By this i mean that i need it to spread like grass but at a much higher rate and be able to spread down. i have looked at the grass and mycelium classes and the "A block that spreads over every block but air?" topic but i can't seem to get any of them to work. Thank you, Drok
July 17, 201411 yr My tip, would be to look at and possibly utilize the blockGrass code, because that one is close to it. Member of Aerotech Networks, a Multi-Gaming server. Also Currently porting the "Rise of the Automatons" minecraft mod
July 17, 201411 yr Author i have told you that i have looked at it but i cant seem to get it to do what i want this is what i have tried. public void updateTick(World world, int x, int y, int z, Random rand) { if (!world.isRemote) { for (int l = 0; l < 40000; ++l) { int i1 = x + rand.nextInt(3) - 1; int j1 = y + rand.nextInt(5) - 3; int k1 = z + rand.nextInt(3) - 1; Block block = world.getBlock(i1, j1 + 1, k1); if (world.getBlock(i1, j1, k1) != Blocks.air) { world.setBlock(i1, j1, k1, this); } } } }
July 17, 201411 yr Author ah ok i will try that but will my code work at all AND at a higher rate than grass?
July 17, 201411 yr Please show us the complete Block Class. and did you put this.setTickRandomly(true); in the constructor? Here could be your advertisement!
July 17, 201411 yr hmm, well I gotta ask, where exactly did you place "this.setTickRandomly(true);"? Member of Aerotech Networks, a Multi-Gaming server. Also Currently porting the "Rise of the Automatons" minecraft mod
July 17, 201411 yr hmm, well I gotta ask, where exactly did you place "this.setTickRandomly(true);"? thats why i asked for the complete Block class Here could be your advertisement!
July 17, 201411 yr Author Here is the complete block class: package team.flock.drok0920.BOW.Blocks; import scala.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.world.World; public class AlfitarianVirusBlock extends Block { protected AlfitarianVirusBlock(Material mat) { super(mat); this.setCreativeTab(CreativeTabs.tabBlock); this.setTickRandomly(true); } public void updateTick(World world, int x, int y, int z, Random rand) { if (!world.isRemote) { for (int l = 0; l < 40000; ++l) { int i1 = x + rand.nextInt(3) - 1; int j1 = y + rand.nextInt(5) - 3; int k1 = z + rand.nextInt(3) - 1; Block block = world.getBlock(i1, j1 + 1, k1); if (world.getBlock(i1, j1, k1) != Blocks.air) { world.setBlock(i1, j1, k1, BOWBlocks.AVBlock); } } } } }
July 18, 201411 yr Please put some console output in your updateTick(). Here could be your advertisement!
July 18, 201411 yr Just so i get it right, you want, for example if a virus block is next to an iron block, the iron block to become a virus bock?
July 18, 201411 yr Author @Jacky2611 i did that and found out that it doesn't call the method at all @daafganggdg Well sort of i want it to do that but to every block except air(or a new block i will add later).
July 18, 201411 yr You could go with something like this: @Override public void updateTick(World world, int x, int y, int z, Random rand){ if(world.getBlock(x+1, y, z) != Blocks.air) { world.setBlock(x+1, y, z, yourVirusBlock); } if(world.getBlock(x-1, y, z) != Blocks.air) { world.setBlock(x-1, y, z, yourVirusBlock); } if(world.getBlock(x, y+1, z) != Blocks.air) { world.setBlock(x, y+1, z, yourVirusBlock); } if(world.getBlock(x, y-1, z) != Blocks.air) { world.setBlock(x, y-1, z, yourVirusBlock); } if(world.getBlock(x, y, z+1) != Blocks.air) { world.setBlock(x, y, z+1, yourVirusBlock); } if(world.getBlock(x, y, z-1) != Blocks.air) { world.setBlock(x, y, z-1, yourVirusBlock); } } but make sure to put this.setThickRandomly(true) into the constructor ^^
July 18, 201411 yr Author It does not apear to call that method at all and the @Override method gives an error. please help
July 18, 201411 yr Author it does here it is public void updateTick(World world, int x, int y, int z, Random rand){
July 18, 201411 yr Hi You've imported the wrong Random. you need java.util.Random not scala.util.Random. For this reason the signature of updateTick doesn't match the base class, so it's not called as you expected, and is why @Override tells you there is a problem. -TGG
July 19, 201411 yr Author Ah ok thank you Edit: Wait that is the random i imported (java.util.Random) Edit2: Derp never mind i was looking at the wrong class
July 20, 201411 yr And just a tip, instead of having all those if's in your update tick you could use for loops to make it look nicer (although it is completely optional) for(int i = -1; i < 2; i++) { for(int j = -1; j < 2; j++) { for(int k = -1; k < 2; k++) { if(world.getBlock(x+i, y+j, z+k) != Blocks.air || world.getBlock(x+i, y+j, z+k) != this) { world.setBlock(x+i, y+j, z+k, this); } } } } This is generally better practice than a large amount of if statements. Also the != this is there so it doesn't replace itself as that would be pointless. BEFORE ASKING FOR HELP READ THE EAQ! I'll help if I can. Apologies if I do something obviously stupid. If you don't know basic Java yet, go and follow these tutorials.
July 20, 201411 yr And just a tip, instead of having all those if's in your update tick you could use for loops to make it look nicer (although it is completely optional) for(int i = -1; i < 2; i++) { for(int j = -1; j < 2; j++) { for(int k = -1; k < 2; k++) { if(world.getBlock(x+i, y+j, z+k) != Blocks.air || world.getBlock(x+i, y+j, z+k) != this) { world.setBlock(x+i, y+j, z+k, this); } } } } This is generally better practice than a large amount of if statements. Also the != this is there so it doesn't replace itself as that would be pointless. Correct me if I'm wrong, but I think you'v got to use &&, or the if statement will always return true like that. In my opinion the for loops make it actually just look more confusing, but yeah, just my opinion ^^
July 20, 201411 yr You are correct. My mistake BEFORE ASKING FOR HELP READ THE EAQ! I'll help if I can. Apologies if I do something obviously stupid. If you don't know basic Java yet, go and follow these tutorials.
July 21, 201411 yr Author Would changing for(int i = -1; i < 2; i++) { for(int j = -1; j < 2; j++) { for(int k = -1; k < 2; k++) { if(world.getBlock(x+i, y+j, z+k) != Blocks.air || world.getBlock(x+i, y+j, z+k) != this) { world.setBlock(x+i, y+j, z+k, this); } } } } to for(int i = -1; i < 10; i++) { for(int j = -1; j < 10; j++) { for(int k = -1; k < 10; k++) { if(world.getBlock(x+i, y+j, z+k) != Blocks.air || world.getBlock(x+i, y+j, z+k) != this) { world.setBlock(x+i, y+j, z+k, this); } } } } speed up the spread rate? if not how would i speed it up?
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.