Jump to content

[1.14.4] [SOLVED] Crop .grow() / BlockState update confusion


Recommended Posts

Posted (edited)

I'm new to modding and I figured I'd play around a bit to try and get a handle on the functionality that exists already in the API. I'm implementing a simple TileEntity block that will (~every 20 ticks) apply a bonemeal effect to a crop directly in front of it. I think I have a slight misunderstanding of how BlockStates / Blocks can be updated. To illustrate this problem, I have:

 

  • BlockPos cropPos -- the XYZ position of the crop block (e.g. the seeds/carrot/potato/etc)
  • BlockState cropState -- the block state of that crop [obtained by world.getBlockState(cropPos)]. (Note: debugging shows it to have one property AGE_0_7 which I'm trying to update)
  • CropsBlock crop -- a (verifiably legal/kosher) casting of cropState.getBlock()

 

Now, inside my TileEntity's tick() function (only on the server, not from a client), I attempt to call crop.grow(), which takes parameters (World, BlockPos, BlockState). Looking inside that API call it seems pretty straightforward: it updates the AGE property towards the maximum age allowed for the particular crop with one (randomized) bonemeal-esque update. It does that by calling something like world.setBlockState(... state.with(updatedAge)...).

 

Visually, the crop seems to grow just fine as it looks like the crop is growing over a short period of time in game. My debugging output will show that if I pull the BlockState of that position from the world after the grow() call, it has an AGE property larger than it started. But it's unfortunately not "real" growth and is just a visual lie: the crop is still only on stage one. This can be verified by breaking the crop when it is supposedly mature (it only gives a single seed, not the regular mature products), or right clicking it with an empty hand, which updates it visually to reveal that it is still just on the initial stage of growth. This is definitely a different effect than what bonemealing a seed does, which leads me to believe I'm not updating the right aspects of the crop block.

 

I believe this is me misunderstanding how BlockState updates can occur, so if anyone can enlighten me on what I'm missing it would be most appreciated.

Edited by ojb
Posted

I think your problem is that you've made the crop grow on the client side (and only the client side) while on the sever side of things, nothing's changed.

 

Show your code.

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
1 hour ago, Draco18s said:

I think your problem is that you've made the crop grow on the client side (and only the client side) while on the sever side of things, nothing's changed.

You're absolutely correct! I was a dummy and had it checking

if (world.isRemote())

instead of

if (!world.isRemote())

inside my tick() function with the grow updates. I guess I didn't read the docs too carefully and just assumed the isRemote flag was reversed. This change fixed my issue, and it works as I would expect. Thank you Draco!

Posted
1 hour ago, ojb said:

I guess I didn't read the docs too carefully and just assumed the isRemote flag was reversed.

This is why it has been renamed to isClient in 1.13+.

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 (edited)
12 hours ago, Draco18s said:

This is why it has been renamed to isClient in 1.13+.

 

It's still isRemote (and probably always will be), see this issue on the MCPBot issue tracker.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
40 minutes ago, Choonster said:

 

It's still isRemote (and probably always will be), see this issue on the MCPBot issue tracker.

Oh? Huh, thought I'd saw that it changed.

*shrug*

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.

Announcements



×
×
  • Create New...

Important Information

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