Jump to content

[SOLVED] applyBonemeal grass/flower in radius doesn't show in client


viveleroi

Recommended Posts

 

 

I've designed a custom bonemeal item, which onItemUse calls "applyBonemeal":

 

@Override
    public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        // Run only on logical server
        if (worldIn.isRemote) {
            return EnumActionResult.PASS;
        }

        // Copy the item so we give garbage to applyBonemeal - it does
        // things to the item damage we don't like
        ItemStack phantomBonemeal = player.getHeldItem(hand).copy();

        if (ItemDye.applyBonemeal(phantomBonemeal, worldIn, pos)) {
            player.getHeldItem(hand).damageItem(1, player);
        } else {
            player.sendMessage(new TextComponentTranslation("text.scroll.incorrect_poison"));

            // Curse them
            Curses.applyMinorPoisonCurse(player);
        }

        return EnumActionResult.FAIL;
    }

 

It works as intended, except when used on grass I've noticed that the client doesn't render all updated blocks. The clicked block updates fine (a grass/flower appears) but the grass/flowers which appear in a radius don't show up until I save and quit and re-open the game. 

 

I'm not sure if I've done something or there's an issue?

Edited by viveleroi
solved
Link to comment
Share on other sites

On 12/12/2018 at 4:58 PM, viveleroi said:

// Run only on logical server

 

On 12/12/2018 at 4:58 PM, viveleroi said:

the client doesn't render all updated blocks

?

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.

Link to comment
Share on other sites

I thought that any world changes had to be made server-side and it would then update the client. The docs say "Applying game logic to the logical client can cause desynchronization issues" and running logic like this on both sides in another project lead to "doubling" of the all the logic which I was then directed to run on the logical server only.

 

The docs aren't clearly explaining why some things need to happen when the world isRemote. Clearly one block is sent to the client, but not the others? If I run this on the logical client too, how does the growth produce the same results?

Link to comment
Share on other sites

On 12/13/2018 at 1:58 AM, viveleroi said:

ItemDye.applyBonemeal(phantomBonemeal, worldIn, pos)

Use the overload that takes additional parameters - the player and the hand.

Don't return a FAIL/PASS action result - you did something, so tell the game that something happened.

Apart from that your code seems fine. Bonemeal growth only happens on the server anyway. 

Link to comment
Share on other sites

10 hours ago, viveleroi said:

I thought that any world changes had to be made server-side and it would then update the client. The docs say "Applying game logic to the logical client can cause desynchronization issues" and running logic like this on both sides in another project lead to "doubling" of the all the logic which I was then directed to run on the logical server only.

 

The docs aren't clearly explaining why some things need to happen when the world isRemote. Clearly one block is sent to the client, but not the others? If I run this on the logical client too, how does the growth produce the same results?

Often, when in doubt, the best bet is to consult the source and see how vanilla does it.  In this case, take a look atItemDye#onItemUse().  Looking at the code there, it appears that applyBonemeal() (the overload that V0idWa1k3r mentioned) gets called both on server and client.  Indeed, a perusal of ItemDye#applyBonemeal() shows some checks for server/client, so it's clearly intended to be called on both sides.

Link to comment
Share on other sites

Taking out the check for world.isRemote doesn't solve this either. The code runs twice, both on the logical client and server but the grass/flowers grown don't appear except for the single block clicked. I'll have to study the original further, something is missing or I'm doing it wrong. Even just simplifying it, using the other recommended method, etc.

 

@Override
    public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

        ItemDye.applyBonemeal(player.getHeldItem(hand), worldIn, pos, player, hand);
        
        return EnumActionResult.PASS;
    }

 

Link to comment
Share on other sites

15 hours ago, V0idWa1k3r said:

Don't return a FAIL/PASS action result - you did something, so tell the game that something happened.

*SUCCESS*

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

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.