Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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

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

Please show us the complete Block Class.

 

and did you put

this.setTickRandomly(true);

in the constructor?

Here could be your advertisement!

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

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!

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

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

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

  • Author

It does not apear to call that method at all and the @Override method gives an error. please help

  • Author

it does here it is

public void updateTick(World world, int x, int y, int z, Random rand){

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

  • 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

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.

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

  • 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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.