Jump to content

Recommended Posts

Posted

When I right-click on my object it is meant to change the block's model to be open (it's a wardrobe with doors that open). But instead my hand does the interaction animation to indicate that I have right-clicked the block yet the model doesn't change to 'oak_wardrobe_closed'.

 

In the blockstate of the wardrobe I have the 3 different possible situations: the open variable is true, false or does not exist/work for some reason and therefore resorts to the normal tag.  I know that the problem is due to the blockstate not being able to read the open variable's value and therefore resorting to the normal tag. This is confirmed by the fact that I receieve an error when I don't have that tag, and also because the default model in-game is always the same as the tag. 

 

 

{
    "variants": {
        "normal": { "model": "odm:oak_wardrobe_closed" },
        "open=false": { "model": "odm:oak_wardrobe_closed" },
        "open=true": { "model": "odm:oak_wardrobe_open" }
    }
}

 

 

Then in the BlockWardrobe class I have created a public boolean called open which is what I want the blockstate to be checking for the value of.

 

public class BlockWardrobe extends Block {

public boolean open = false;

public BlockWardrobe(Material materialIn) {
	super(materialIn);
	this.setCreativeTab(OddmentsMod.tabOddments);
}

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

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

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
	if (open == true) open = false; else open = true;
	return true;
}
}

 

I don't know whether this is a problem with my lack of Java knowledge or Minecraft method knowledge - or perhaps both.

 

I am aware that I'm not making the open variable unique for each instance and am pretty sure that I should be doing that in the constructor. But for now I'm just trying to get something basic working.

 

Posted

You shouldn't have any variables inside the

Block

class which you don't want to be shared. You'd want to use a

PropertyBool

.

 

You should read this to get a better understanding of block states and how to use them.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Look at the vanilla fence-gate for an example of open and close (but ignore the in-wall property). You will need to override several methods pertaining to properties.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.

Announcements



×
×
  • Create New...

Important Information

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