Jump to content

Recommended Posts

Posted

I have encountered two problems, each of which only happen on their own when I attempt to fix the other. My object is an animating fan which is meant to get turned on and off by right-clicking it. The object has a boolean state which is false by default, and when right-clicked it is meant to become true.

 

Problem #1

When the boolean becomes true, it instantly turns back to false for some reason.

 

private boolean isOn = false;
@Override
	public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { 
		actualState = state.withProperty(ON, this.isOn);
		return actualState;
	}
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
		this.isOn = !isOn;
		getActualState(state, worldIn, pos);
		return true;
    }

 

I tried changing the isOn variable to just be set to true in the onBlockActivated method instead of using the !isOn logic, but then I get the other problem. 

 

Problem #2

Animation only works when I place the fan down after it has been turned on. The state changes to 'on' successfully when I right-click it, but the animation of the fan doesn't begin until I put down another fan.

Posted

You can't store booleans inside the Block class, you need to store it in metadata/properties.

 

And what is actualState?  And why do you call getActualState in onBlockActivated?

  • Like 1

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 (edited)

Realize that there's only one block instance to represent all of the blocks of each block class everywhere in the world. In that respect, all class fields act sort of as if they were static, so those fields had better describe the whole class of blocks. For individual block variation, one must put data into the world. That's why we go through the contortions to use properties translated into and out of metadata (limited to 4-bits, the values 0..15) and tile entities. In essence, Minecraft hoists a feature of the object-oriented language up to its our code level to allow it to super-compress the long-term storage requirement of each block. Coding and storing millions of blocks "normally" would bust bandwidth, RAM, and maybe disks.

Edited by jeffryfisher
  • Like 1

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.