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've created a block that utilizes IBlockState to iterate between models/textures and a different type of block on right-click, but the blockstates file is using a PropertyBool. Without overriding the

Block#getStateFromMeta

and

Block#getMetaFromState

the launcher returns an error, but I'm not quite sure how to override those methods with a PropertyBool. I don't want to make two different blocks, because that would just be annoying, but I'm getting stuck on those methods. Here's my class:

 

package lordmastodon.miscal.blocks;

import java.util.Random;

import lordmastodon.miscal.block.MiscalBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class LightationBlock extends Block {

public static final PropertyBool LIGHTED_UP = PropertyBool.create("lighted");

public LightationBlock() {
	super(Material.iron);

	this.setDefaultState(this.blockState.getBaseState().withProperty(LIGHTED_UP, false));
}

public Item getItemDropped(IBlockState state, Random rand, int fortune) {
	return Item.getItemFromBlock(MiscalBlocks.lightation);
}

public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) {
	if (!world.isRemote) {
		boolean lightedUp = (Boolean) state.getValue(LIGHTED_UP);

		if (lightedUp == true) {
			lightedUp = false;

			this.setLightLevel(1.0F);
		} else {
			lightedUp = true;

			this.setLightLevel(0.0F);
		}

		world.setBlockState(pos, state.withProperty(LIGHTED_UP, lightedUp));
	}

	return true;
}

public IBlockState getStateFromMeta(int meta) {
	EnumFacing enumFacing = EnumFacing.getFront(meta);

	if (enumFacing.getAxis() == EnumFacing.Axis.Y) {
		enumFacing = EnumFacing.NORTH;
	}

	return this.getDefaultState().withProperty(LIGHTED_UP, enumFacing);
}

public int getMetaFromState(IBlockState state) {
	return ((EnumFacing) state.getValue(LIGHTED_UP)).getIndex();
}

@SideOnly(Side.CLIENT)
public IBlockState getStateForEntityRender(IBlockState state) {
	return this.getDefaultState().withProperty(LIGHTED_UP, false);
}

protected BlockState createBlockState() {
	return new BlockState(this, new IProperty[] {LIGHTED_UP});
}

@Override
public int getRenderType() {
	return 3; 
}

@Override
public boolean isOpaqueCube() {
	return false;
}

@SideOnly(Side.CLIENT)
@Override
public EnumWorldBlockLayer getBlockLayer() {
	return EnumWorldBlockLayer.CUTOUT_MIPPED;
}

@Override
public boolean isFullCube() {
	return false;
}

}

 

Any help? Thanks in advance!

Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*.

 

Also this. Check it out.

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

You need to think about how each property's value will be stored in the metadata and then convert to and from the metadata appropriately. For a single boolean, you can just use metadata values 0 and 1.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Ok thanks! That seemed to work. I was considering using something like that, but I wasn't sure whether that was how meta actually worked.

Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*.

 

Also this. Check it out.

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

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.