Jump to content

Recommended Posts

Posted

I have a custom dirt block which the player can plant crops on. It's supposed to give a comparator output based on the growth of the crops planted on it. That works, except when the crops grow (either from bonemeal or naturally), the comparator isn't updated. Looking through the code of various growable plant classes, it looks like every time the crops grow, they update their adjacent blocks. So I thought if I just propagate that update one more block out by putting notifyBlocksofNeighborChange() inside my custom dirt's onNeighborBlockChange() method, it would update the adjacent comparators. However, it's not working; the comparators still won't update until they get a proper block update nearby.

 

Obviously, I'm overriding my block's getComparatorInputOverride() method so adjacent comparators will output a value based on the growth of the crops above the block. But how do I get the comparators to call that method--i.e. update--when the crop above the block grows?

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

A bit of sleuthing later, and I've found that when crops grow, they update their block with notification flag 2, which causes it to skip notifying its neighbors that it's been updated. (It calls World#markBlockForUpdate on its own position rather than .notifyBlockChange.) This is...well, irksome. I'm still trying to find a way to make this work, but meanwhile, perhaps knowing that it uses flag 2 can inspire someone who knows more about the implementation details of Minecraft's block update system to find a way around this?

 

*EDIT* I guess one approach would be, is there any way to hook into some kind of watcher or event listener that'll notice when block metadata has changed, even if it wasn't changed with the "notify neighbors" flag bits set?

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

Well, I got the functionality I wanted by giving the custom block a tile entity which updates the growth value every second, then triggers a block update when it changes. Unfortunately, this has the effects of making the dirt unpushable by pistons (which is a common crop harvesting method) and also means it has a tile entity ticking and processing each second per each dirt block...which can't be good for lag.

 

So although I have mostly what I want, I'm keeping this topic open and will check back occasionally in case anyone finds a better way, preferably a way to only cause a block update when a crop grows.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

I hate recommending this, but:

 

ASM.

 

Make a core mod and replace the 2 with a 3 (this will be relatively easy, you'd be looking for iconst_2 within that function and replacing it with iconst_3).

 

Shieldbug's ASM Helper will make it easy to locate the method and instruction.

 

I also have my own version of printOpcodes() which supplies better information than just the opcode (useful for going "I need to push that same parameter onto the stack....ah, I need

VarInsnNode(ALOAD,1)

because the existing code here has an ALOAD representing that same parameter and it's value is a 1").

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

If you do get it working by changing it to notify neighbors, one thing you will need to be careful of is recursion; if you have crop blocks all next to each other and one updates, it notifies all of its neighbors who then update, and suddenly it's a cluster-f*ck. At best, every crop will instantly mature; at worst, you crash with StackOverflow.

Posted

Its actually not a problem in this case as crops do not grow when a neighbor updates (BlockBush#onNeighborBlockChange calls super and BlockBush#checkAndDropBlock, neither of which schedule an update or call updateTick).

 

Otherwise you could quick-grow crops by causing redstone updates near them.

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

Its actually not a problem in this case as crops do not grow when a neighbor updates (BlockBush#onNeighborBlockChange calls super and BlockBush#checkAndDropBlock, neither of which schedule an update or call updateTick).

 

Otherwise you could quick-grow crops by causing redstone updates near them.

Ah, I didn't re-read the OP carefully enough, thought he was trying to cause crops to grow when a neighbor updates :P

Posted

No, that's what I did :D

 

Or more specifically, I tweaked crops to grow more slowly, but also if they were the "most grown" of the crops around them, they'd forfeit their update to update one of those instead.  There was still a small probability that it'd grow anyway, but due to the increased number of "ticks" and how they were distributed, it averaged things out.

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.