Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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);
                    }
                }
            }
        }

Posted

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

Posted

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);
                    }
                }
            }
        }
}

Posted

@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).

Posted

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 ^^

Posted

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

Posted

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. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Posted

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 ^^

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.