Jump to content

placing a block only places a ghost block which is not visible on the client


Recommended Posts

Posted

using a item i am placing some blocks on nearby entities using Level.setBlock(). but when doing so it only creates a ghost block which is not there to the client, when trying to place a block in the place where the block should be the block apears.

 

Posted (edited)
    @Override
    public void onUse(Level pLevel, ItemStack pWand, LivingEntity pPlayer) {
            List<Entity> list = pLevel.getEntities(pPlayer, AABB.ofSize(pPlayer.position(), this.getSize(), this.getSize(), this.getSize()));
            if (!pLevel.isClientSide) {
                if (pPlayer.getItemInHand(InteractionHand.OFF_HAND).getItem() instanceof SpellItem) {
                    SpellItem spellItem = (SpellItem) pPlayer.getItemInHand(InteractionHand.OFF_HAND).getItem();
                    spellItem.cooldown(pPlayer, this.getCooldown());
                }
                for (Entity entity : list) {
                    if (entity.isAlive()) {
                        if (!pLevel.isClientSide()) {
                            LivingEntity livingentity = (LivingEntity) entity;
                            livingentity.addEffect(new MobEffectInstance(MobEffects.WEAKNESS, 200, 1), entity);
                            livingentity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 200, 5), entity);
                            BlockPos pos = new BlockPos(entity.position());
                            pLevel.setBlock(pos, Blocks.ICE.defaultBlockState(), 0);
                        }
                    }
                }
            }
            else {
                ParticleGen.spheremove(pPlayer.position().x, pPlayer.position().y+(pPlayer.getBbHeight()/2), pPlayer.position().z, 1, pLevel, ParticleTypes.SNOWFLAKE, 0, 0, 0, 1, 50, -3, true);
            }
            super.onUse(pLevel, pWand, pPlayer);
    }

 

Edited by Just_EmSee
Posted
Quote

pLevel.setBlock(pos, Blocks.ICE.defaultBlockState(), 0);

Passing 0 here means no updates are performed.

Using the value 2 will send updates to the client. See ServerLevel.markAndNotify() used by setBlock()

or you could just use setBlockAndUpdate() which passes the value 3 (so it also notifies neighbouring blocks of the change).

 

There is supposed to be a vanilla class somewhere that holds the values of these bits, but I don't know the name of it. 🙂

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.