Jump to content

Recommended Posts

Posted (edited)

Hey,

 

I want to create a double block crop (corn) but the top blockstate isn't updating. (see the screenshots: https://imgur.com/a/ndTM2jk)

 

https://pastebin.com/wvb0X6L5

https://pastebin.com/GcENDYY3

https://pastebin.com/hxVhr473

 

The setBlockState methods return true and the "input" blockstate is correct but the age of the crop is not updated. (also WAILA says that the bottom crop is always "mature" even it's not?)

 

EDIT: Okay, "natural" growing works fine. Using bonemeal causes this problem but I still don't know why.

Edited by Boy132
solved :)
Posted

This is not functionally useful. If the chunk the crop is in is not loaded, then the crop won't update. The blocks above the crop are always in the same chunk as the crop itself.

 

        if(!world.isAreaLoaded(pos, 1))
            return; // Forge: prevent loading unloaded chunks when checking neighbor's light
 
Nice to see you including the crop grow events
 
if(ForgeHooks.onCropsGrowPre(world, pos, state, rand.nextInt((int) (25.0F / f) + 1) == 0))
 
Dollars to doughnuts this line isn't doing what you want:
 
int i = getAge(state);

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)

I copied the chunk loading check and the grow events check from the BlockCrops class. :)

 

getAge is from the super class BlockCrops:

protected int getAge(IBlockState state)
{
    return ((Integer)state.getValue(this.getAgeProperty())).intValue();
}

And this does work, normal growing (updateTick) kind of works but when I use bonemeal (grow) on the lower half the upper one gets not updated.

Edited by Boy132
Posted

Yes, and what I'm saying is, your two-block crop isn't using one block to store its age. Its using two. That method can't deal with that.

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

But I'm doing all of the logic only if it's the lower half and then update both.

Also that doesn't explain why the updateTick method works but the grow method not. (both use the same getAge and only execute on the lower half)

Posted (edited)

By the way:

if(false && !world.isRemote) // Forge: NOP all this.

 

Why do you still have that block it does nothing?

 

Its also a terrible idea to use +10 as your UPPER/LOWER value. Metadata is limited by 16 states, meaning you're limiting your max age to 6, whereas if you used a single bit (+8) you could have max ages up to 8. It also means you can use bitwise logic instead (int age = meta & 7; int halfAsInt = meta & 8).

 

this.seed = new CoreSeedFood(name, 3, this);

 

You can't do this. You are not allowed to create items at this point in the startup process. How do you even register this item?

 

Quote

The setBlockState methods return true

The return value from setBlock is not useful in any capacity that I've ever seen.

 

And after a lot of testing, I've determined the issue. This function is run when you use bonemeal:

 

    @Override
    public void onBlockAdded(World world, BlockPos pos, IBlockState state)
    {
        if(getHalf(state) == EnumCropHalf.LOWER)
            world.setBlockState(pos.up(), getDefaultState().withProperty(HALF, EnumCropHalf.UPPER), 2);
    }

 

It does not run when the block updates.

Edited by Draco18s
  • Thanks 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
12 hours ago, Draco18s said:

By the way:

if(false && !world.isRemote) // Forge: NOP all this.

 

Why do you still have that block it does nothing?

You're right, I removed this part. :)

 

12 hours ago, Draco18s said:

Its also a terrible idea to use +10 as your UPPER/LOWER value. Metadata is limited by 16 states, meaning you're limiting your max age to 6, whereas if you used a single bit (+8) you could have max ages up to 8. It also means you can use bitwise logic instead (int age = meta & 7; int halfAsInt = meta & 8).

Haven't thought so much about it but I changed this too.

 

12 hours ago, Draco18s said:

this.seed = new CoreSeedFood(name, 3, this);

 

You can't do this. You are not allowed to create items at this point in the startup process. How do you even register this item?

Why can't I do this? I add all my Blocks/ Items to Lists in my Init classes and then iterate through these lists in the registry events - and it works. :D

 

12 hours ago, Draco18s said:

And after a lot of testing, I've determined the issue. This function is run when you use bonemeal:

 


    @Override
    public void onBlockAdded(World world, BlockPos pos, IBlockState state)
    {
        if(getHalf(state) == EnumCropHalf.LOWER)
            world.setBlockState(pos.up(), getDefaultState().withProperty(HALF, EnumCropHalf.UPPER), 2);
    }

 

It does not run when the block updates.

Ahhh thank you very much! I changed the if to

if(getHalf(state) == EnumCropHalf.LOWER && getAge(state) == 0)

and now it works.

 

Just one little question: do you now why HWYLA shows that the lower part is "mature" (even if it's not). The upper part is shown correctly and other "normal" crops are correct too?

Posted
8 hours ago, Boy132 said:

Why can't I do this? I add all my Blocks/ Items to Lists in my Init classes and then iterate through these lists in the registry events - and it works. :D

All of them except your seed, which unless you add it to those lists in the constructor (terrible idea).

 

8 hours ago, Boy132 said:

do you now why HWYLA shows that the lower part is "mature" (even if it's not). The upper part is shown correctly and other "normal" crops are correct too?

No. Probably because its using the default crop inspector, which is mature if the metadata value >= 7. You'll have to write your own inspector is my guess.

  • Thanks 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.

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.