Posted June 8, 20232 yr hello, i'm trying to make a sword that when used, fires a sonic boom (the one the warden makes) in the direction the player is facing, dealing damage in the process. my current code is able to create particles, but it only creates one, at the location of the player. also, i'm not sure how to damage the enemies caught in the boom. previously, i used AABB to find the targets, but as far as i know, it only works with cubes, not lines. if you could give me a hand on either, i would really appreciate it. my code: package net.grandfish.mod.item.custom; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; public class WardenSwordItem extends LightningSwordItem { public WardenSwordItem(Tier pTier, int pAttackDamageModifier, float pAttackSpeedModifier, Properties properties) { super(pTier, pAttackDamageModifier, pAttackSpeedModifier, properties); } private void locateTargetExecute(LivingEntity player, Level level, InteractionHand hand) { if (!level.isClientSide()) { Vec3 pos = player.getEyePosition(1.0f); Vec3 dir = player.getLookAngle(); for (int i = 0; i < 40; i++) { Vec3 particlePos = pos.add(dir.scale(i)); level.addParticle(ParticleTypes.SONIC_BOOM, particlePos.x(), particlePos.y(), particlePos.z(), 0.0, 0.0, 0.0); } ClientboundLevelParticlesPacket particlePacket = new ClientboundLevelParticlesPacket( ParticleTypes.SONIC_BOOM, true, (float) pos.x(), (float) pos.y(), (float) pos.z(), 0.0f, 0.0f, 0.0f, 0.0f, 8 ); ((ServerPlayer) player).connection.send(particlePacket); } } public InteractionResultHolder<ItemStack> use (Level level, Player player, InteractionHand hand){ if (!level.isClientSide() && hand == InteractionHand.MAIN_HAND) { locateTargetExecute(player, level, hand); player.getCooldowns().addCooldown(this, 40); } return (super.use(level, player, hand)); } } thank you for taking a look at my post ❤️
June 9, 20232 yr 16 hours ago, Grqndfish said: i used AABB to find the targets, but as far as i know, it only works with cubes, not lines. if you could give me a hand on either, i would really appreciate it. I mean, you could use AABB to target people in the relevant range and then check if the entity is in front of the player. Since you know the player's y rotation, you can just check if the entity direction vector is between two vectors that make up your field of view.
June 25, 20232 yr Author huh, i didn't think of doing that. ill give it a try, and in the meantime, does anyone have any ideas about the particles?
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.