Jump to content

[1.10.2] blockstate question


Kaneka

Recommended Posts

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

Link to comment
Share on other sites

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

}

}

 

 

}

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.



×
×
  • Create New...

Important Information

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