Jump to content

[SOLVED] [1.19.4] explosion sword crashing game with exit value -1


Grqndfish

Recommended Posts

hi

so basically, i'm trying to make a sword that when used, creates an explosion that deals damage at the block/entity that the player is targeting. however, when i tried to right-click with it, it caused the game to crash with "exit value -1";

i have a decent knowledge of java, but i'm new to modding. there are no errors btw.

 

have a nice day!

package net.sac.rpgmod.item.custom;


import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import java.util.List;

public class ExplosionSwordItem extends SwordItem {
    public ExplosionSwordItem(Tier pTier, int pAttackDamageModifier, float pAttackSpeedModifier, Properties properties) {
        super(pTier, pAttackDamageModifier, pAttackSpeedModifier, properties);
    }
    private void locateTargetExecute(LivingEntity user, Level world) {
        Vec3 eyePos = user.getEyePosition();
        Vec3 lookVec = user.getLookAngle();

        Vec3 targetPos = eyePos.add(lookVec.scale(25)).add(0, -1 * user.getEyeHeight(), 0);


        ((ServerLevel) world).sendParticles(ParticleTypes.EXPLOSION_EMITTER, targetPos.x, targetPos.y, targetPos.z, 3, 5, 5, 5, 0.0);

        AABB minMax = new AABB(targetPos.x, targetPos.y, targetPos.z, 10, 10, 10);
        List<Entity> ent = world.getEntities(user, minMax);
        for (Entity target : ent) {
            target.hurt(DamageSource.MAGIC, 20);
        }
    }
    public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
        if(!world.isClientSide() && hand == InteractionHand.MAIN_HAND) {
            locateTargetExecute(player, world);
            player.getCooldowns().addCooldown(this, 20);
        }
        return(null);
    }

}

 

Edited by Grqndfish
solved
Link to comment
Share on other sites

  • Grqndfish changed the title to [1.19.4] explosion sword crashing game with exit value -1
  • Grqndfish changed the title to [SOLVED] [1.19.4] explosion sword crashing game with exit value -1

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.



×
×
  • Create New...

Important Information

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