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 everyone,

 

I created a block with PropertyInteger of 0 - 4, and almost everything works fine.

But when leave the world and join again, the block is set on 4, dosn´t matter which value was there before.

example: Before relog: anyblock:0 .After relog: anyblock:4

Which methods defines the value?

 

thanks for the answer

  • Author

public class BlockMold extends Block

{

 

public static final PropertyInteger MOLD_STATE = PropertyInteger.create("mold_state", 0, 4);

protected static final AxisAlignedBB AABB_BOTTOM_HALF = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D);

 

public BlockMold(String uname)

{

super(Material.IRON);

this.setCreativeTab(Main.planttech);

this.setUnlocalizedName(uname);

this.setHardness(0.8F);

this.setTickRandomly(true);

                this.setDefaultState(this.blockState.getBaseState().withProperty(MOLD_STATE, 0));

}

 

@Override

    protected BlockStateContainer createBlockState()

{

        return new BlockStateContainer(this, new IProperty[] { MOLD_STATE });

    }

 

@Override

public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)

{

        return state;   

}

 

@Override

    public int getMetaFromState(final IBlockState state) {

        return 0;

    }

 

@Override

public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)

{

return AABB_BOTTOM_HALF;

}

 

@Override

public boolean isOpaqueCube(IBlockState state) {

return false;

 

}

 

@Override

public BlockRenderLayer getBlockLayer() {

return BlockRenderLayer.CUTOUT;

}

 

@Override

public boolean isFullCube(IBlockState state) {

 

return false;

}

@Override

public boolean isFullyOpaque(IBlockState state) {

 

return false;

}

 

 

@Override

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)

{

System.out.println(this.getMetaFromState(state));

if(state.getValue(MOLD_STATE) != 4)

{

if(heldItem != null)

{

if(heldItem.isItemEqual(new ItemStack(Moditems.plantophen)) && !plantophen)

{

if(state.getValue(MOLD_STATE) == 0)

{

worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(MOLD_STATE, 1));

if(!playerIn.isCreative())

{

if(heldItem.stackSize > 1)

{

heldItem.stackSize--;

}

else if(heldItem.stackSize == 1)

{

playerIn.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);;

}

}

}

if(state.getValue(MOLD_STATE) == 2)

{

worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(MOLD_STATE, 3));

if(!playerIn.isCreative())

{

if(heldItem.stackSize > 1)

{

heldItem.stackSize--;

}

else if(heldItem.stackSize == 1)

{

playerIn.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);;

}

}

}

}

if(heldItem.isItemEqual(new ItemStack(Moditems.plantodur))  && !plantodur)

{

 

if(state.getValue(MOLD_STATE) == 0)

{

worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(MOLD_STATE, 2));

if(!playerIn.isCreative())

{

if(heldItem.stackSize > 1)

{

heldItem.stackSize--;

}

else if(heldItem.stackSize == 1)

{

playerIn.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);;

}

}

}

if(state.getValue(MOLD_STATE) == 1)

{

worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(MOLD_STATE, 3));

if(!playerIn.isCreative())

{

if(heldItem.stackSize > 1)

{

heldItem.stackSize--;

}

else if(heldItem.stackSize == 1)

{

playerIn.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);;

}

}

}

 

}

}

}

else

{

worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(MOLD_STATE, 0));

if(!worldIn.isRemote)

{

worldIn.spawnEntityInWorld(new EntityItem(worldIn, pos.getX()+ 0.5D , pos.getY() + 1.0D, pos.getZ() + 0.5D, new ItemStack(Items.ELYTRA)));

}

}

 

return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);

}

 

 

@Override

public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {

 

if(state.getValue(MOLD_STATE) == 3)

{

System.out.println("test2 ");

worldIn.setBlockState(pos, this.blockState.getBaseState().withProperty(MOLD_STATE, 4));

}

}

 

 

}

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.