Jump to content

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


Recommended Posts

Posted (edited)

 

 

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
Posted
  On 12/12/2018 at 10:58 PM, viveleroi said:

// Run only on logical server

Expand  

 

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

the client doesn't render all updated blocks

Expand  

?

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

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?

Posted
  On 12/12/2018 at 10:58 PM, viveleroi said:

ItemDye.applyBonemeal(phantomBonemeal, worldIn, pos)

Expand  

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. 

Posted
  On 12/14/2018 at 1:31 AM, 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?

Expand  

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.

Posted

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;
    }

 

Posted
  On 12/14/2018 at 7:22 AM, V0idWa1k3r said:

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

Expand  

*SUCCESS*

About Me

  Reveal hidden contents

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)

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Different problem now. https://paste.ee/p/iDo8lS35
    • I would like to have a BoP sapling drop from my block if it is also installed. I think I have done everything and I cannot pinpoint the problem, which is the error in the logs that appears when joining a world:   [Worker-Main-11/ERROR] [ne.mi.co.ForgeHooks/]: Couldn't parse element loot_tables:grasses:blocks/leaves_block com.google.gson.JsonSyntaxException: Expected name to be an item, was unknown string 'biomesoplenty:magic_sapling' My code:   LootItemConditions.CONDITIONS.register(modEventBus); public class LootItemConditions { public static final DeferredRegister<LootItemConditionType> CONDITIONS = DeferredRegister.create(Registries.LOOT_CONDITION_TYPE, Grasses.MOD_ID); public static final RegistryObject<LootItemConditionType> IS_MOD_LOADED = CONDITIONS.register("is_mod_loaded", () -> new LootItemConditionType(new IsModLoaded.ConditionSerializer())); } public class IsModLoaded implements LootItemCondition { private final boolean exists; private final String modID; public IsModLoaded(String modID) { this.exists = ModList.get().isLoaded(modID); this.modID = modID; } @Override public LootItemConditionType getType() { return LootItemConditions.IS_MOD_LOADED.get(); } @Override public boolean test(LootContext context) { return this.exists; } public static LootItemCondition.Builder builder(String modid) { return () -> new IsModLoaded(modid); } public static class ConditionSerializer implements Serializer<IsModLoaded> { @Override public void serialize(JsonObject json, IsModLoaded instance, JsonSerializationContext ctx) { json.addProperty("modid", instance.modID); } @Override public IsModLoaded deserialize(JsonObject json, JsonDeserializationContext ctx) { return new IsModLoaded(GsonHelper.getAsString(json, "modid")); } } } protected LootTable.Builder createLeavesDropsWithModIDCheck(Block selfBlock, Item sapling, Property<?>[] properties, String modIDToCheck, float... chances) { CopyBlockState.Builder blockStateCopyBuilder = CopyBlockState.copyState(selfBlock); for(Property<?> property : properties) { blockStateCopyBuilder.copy(property); } return LootTable.lootTable() .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(LootItem.lootTableItem(selfBlock) .when(HAS_SHEARS_OR_SILK_TOUCH) .apply(blockStateCopyBuilder))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionCondition(selfBlock, LootItem.lootTableItem(sapling)) .when(IsModLoaded.builder(modIDToCheck))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, chances)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH)) .withPool(LootPool.lootPool().name("sticks").setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionDecay(selfBlock, LootItem.lootTableItem(Items.STICK). apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F)))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, NORMAL_LEAVES_STICK_CHANCES)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH))); } I don't know. Am I making a mistake somewhere? Am I forgetting something? Should there be something else?
    • https://paste.ee/p/h1JX9bbl
    • Add the latest.log from your logs-folder
  • Topics

×
×
  • Create New...

Important Information

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