Jump to content

Recommended Posts

Posted

Hey folks,

I am triing to rework how crops work.

What I am triing to achieve is that crops, that are fully grown and dont get harvested go bad after a specific time.

Sadly Im not sure how to do that.

One idea I had was to subscribe to the event that was fired when IGrowable groes, and start a timer there (mb TickEvent or MinecraftQueue) that will check if the crop is still there after x seconds, but Im not sure if that is the correct approach.

 

Any help is appreciated.

 

Greetz Fail

Posted

You will need ASM.

 

Alternatively you can try basing your mood off of AppleCore (which does that for you) and hiking into the appropriate events.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Download Recommended 1.8.9 - 11.15.1.1722

 

BTW, Have you looked at how crops grow in the first place? Can you see a way to override a method so that the final stage has a chance to roll around to the 1st stage?

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.

Posted

Can you see a way to override a method so that the final stage has a chance to roll around to the 1st stage?

I would assume the term 'spoil', even in Minecraft terms, doesn't mean returning to seedling stage, but I could be wrong :P

 

Crops generally use a metadata-based growing system with the block's age (i.e. metadata, typically using the first 3 of the 4 available bits) incrementing randomly during the block's update tick.

 

I'm not aware of any global notification that occurs for metadata / state changes, so without introducing your own via ASM or using an existing API that does so as Draco suggested, I don't think it would be possible.

 

EDIT: Actually, there is the Forge block snapshot system that was added somewhat recently (recently being within the last year or so...). That might be the hook you are looking for.

Posted

@SubscribeEvent
public void onPlantGrowth(GrowthTick event) {
	if(event.world.isRemote) return;
	if(event.block instanceof IGrowable) {
		IGrowable growable = (IGrowable) event.block;
		if(!growable.canGrow(event.world, event.pos, event.currentState, false)) {
			addDecayer(new PlantDecayer(event.currentState, event.pos, event.world, TIME_TO_DECAY_MIN+event.world.rand.nextInt(TIME_TO_DECAY_RND)));

		}
	}


}

This is what I am doing right now. The add decayer is registering the position to a watcher that is a tick handler that checks after x seconds if the plant is still there.

There you could just go ahead and get the blockstate with metadata 0, because thats normally the seed stage. Even if thats not what im triing to accomplish :b

Posted

Question for you: does it persist across the save-load boundary?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.