Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


Just_EmSee
 Share

Recommended Posts

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.

 

Link to comment
Share on other sites

    @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
Link to comment
Share on other sites

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. 🙂

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

 Share



×
×
  • Create New...

Important Information

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