Jump to content

[1.7.10] Virus Block


drok0920

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.