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

Hi, I was wondering how to make blocks be able to be used in beacon bases. I don't know the specs or anything but it might be an @override so just tell me what the code is or whatever. Thanks!

@Override
public boolean isBeaconBase(IBlockAccess world, int x, int y, int z, int beaconX, int beaconX, int beaconY, int beaconZ) {
    return true;
}

 

Next time, search for beacon in vanilla sources.

@Override
public boolean isBeaconBase(IBlockAccess world, int x, int y, int z, int beaconX, int beaconX, int beaconY, int beaconZ) {
    return true;
}

 

Next time, search for beacon in vanilla sources.

 

What he said but if you use a single block file for all non-special blocks like me I would recommend adding a new method in it:

 

First you need to add a variable at the top:

private Block beaconBase;

after that we simple add a method called setBeaconBase which is going to return a block:

	public Block setBeaconBase(){
	return beaconBase = this;
}

Now we do pretty much what he said with a twist:

	@Override
public boolean isBeaconBase(IBlockAccess worldObj, int x, int y, int z, int beaconX, int beaconY, int beaconZ)
{
	return this == beaconBase;
}

 

Now we simply add ".setBeaconBase()" to make a block a beacon base block:

		blockBronze = new SmBlock(Material.iron, "blockBronze", Block.soundTypeMetal, 5.0F, 8.0F).setBeaconBase();

 

I'm sorry I can't help but make random tutorials in the forums sometimes :/

If I helped please press the Thank You button.

*She.

 

Additionally, why use a

Block

and not a

boolean

as the private flag for whether the block is a beacon base or not?

 

private boolean isBeaconBase;

public void setBeaconBase() {
    isBeaconBase = true;
}

@Override
public boolean isBeaconBase(IBlockAccess worldObj, int x, int y, int z, int beaconX, int beaconY, int beaconZ) {
    return isBeaconBase;
}

*She.

 

Additionally, why use a

Block

and not a

boolean

as the private flag for whether the block is a beacon base or not?

 

private boolean isBeaconBase;

public void setBeaconBase() {
    isBeaconBase = true;
}

@Override
public boolean isBeaconBase(IBlockAccess worldObj, int x, int y, int z, int beaconX, int beaconY, int beaconZ) {
    return isBeaconBase;
}

If you look at all methods which sets stuff in block all of them returns a block i.e. texture name, block name, hardness, resistance, step sound all methods must return a block to be usable.

Ofcourse you can use the boolean as a flag but the method must return a block anyway.

If I helped please press the Thank You button.

You are indeed correct, my mistake.

 

public Block setBeaconBase() {
    isBeaconBase = true;
    return this;
}

 

The reason they return a

Block

is not to make them usable, but chainable.

You are indeed correct, my mistake.

 

public Block setBeaconBase() {
    isBeaconBase = true;
    return this;
}

 

The reason they return a

Block

is not to make them usable, but chainable.

 

I know I just made a bad choice of words I just meant usable as in usable when defining your blocks :)

also using a block instead of a boolean is just like 1 line less of code so thats why I used a block.

If I helped please press the Thank You button.

1 line of code less, maybe - but it is confusing, not indicative of the purpose of the field, as well as taking up 32 or even 64 times more memory.

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.