Jump to content

Recommended Posts

Posted

So I am working on a wand in 1.19.2 forge and for the event it is the 

InteractionResultHolder<>

event...

I created a particle beam but it is not showing up here is my code

    public ElementalWand(Properties properties) {
        super(properties);
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
        if (!level.isClientSide()) { // only execute on server side
            // get player's position and facing direction
            Vec3 pos = player.getEyePosition(1.0f);
            Vec3 dir = player.getLookAngle();

            // get the block in front of the player
            BlockPos blockPos = new BlockPos(pos.add(dir.scale(2.0)));
            BlockState blockState = level.getBlockState(blockPos);

            // create particle beam
            for (int i = 0; i < 40; i++) { // spawn 40 particles along beam
                Vec3 particlePos = pos.add(dir.scale(i * 0.2)); // spawn particles every 0.2 blocks
                level.addParticle(ParticleTypes.DRAGON_BREATH, particlePos.x(), particlePos.y(), particlePos.z(), 0.0, 0.0, 0.0);
            }

            // schedule particle beam to dissipate after 2 seconds
            int particleCount = 40;
            double x = pos.x();
            double y = pos.y();
            double z = pos.z();
            ClientboundLevelParticlesPacket particlePacket = new ClientboundLevelParticlesPacket(
                    ParticleTypes.DRAGON_BREATH,
                    true,
                    (float) x,
                    (float) y,
                    (float) z,
                    0.0f,
                    0.0f,
                    0.0f,
                    0.0f,
                    particleCount
            );
            ((ServerPlayer) player).connection.send(particlePacket);

            // return success
            return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand));
        }

        // return pass if executed on client side
        return new InteractionResultHolder<>(InteractionResult.PASS, player.getItemInHand(hand));
    }

 

Posted
Quote

// return pass if executed on client side

return new InteractionResultHolder<>(InteractionResult.PASS, player.getItemInHand(hand));

"PASS" means you are not interested in this interaction and so it won't send a network packet to the server, making the other code pointless.

Use InteractionResult.sidedSuccess(), e.g. see EggItem.use() for a simple example.

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.

Posted (edited)

That is what the method I proposed does on the client side.

But you will find it easier and less error prone to use Mojang's intended way of writing simple handlers:
 

if (!checkConditionsAreRelevant()) {
   return "PASS";
}
if (!level.isClientSide) {
// server code that actually does stuff
}
// Code common to server and client here, e.g. playing sounds
return InteractionResult.sidedSuccess(itemStack, level.isClientSide);

 

If you don't want to follow similar code patterns used in vanilla code that is your choice.

But don't expect to get much help in this forum, beyond  "you are doing it wrong" or just being ignored.

Edited by warjort

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.

Posted

By the way, this is rubbish

Quote

((ServerPlayer) player).connection.send(particlePacket);

Only the player using the item will see the particles.

Use the sendParticles() which will broadcast the particles to all players in range. See for example PotionItem.

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.