package com.jenny.advancedarrows.entities; import com.jenny.advancedarrows.config.ConfigClient; import com.jenny.advancedarrows.items.items; import com.jenny.advancedarrows.particles.particles; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; public class breachingArrow extends baseArrow{ static final int range = 4; static final Item item = items.ARROW_BREACHING.get(); public breachingArrow(EntityType pEntityType, Level pLevel) { super(pEntityType, pLevel, item); } public breachingArrow(Level pLevel, LivingEntity pShooter) { super(pLevel, pShooter, entities.ARROW_BREACHING.get(), item); } @Override public void tick() { super.tick(); if (level().isClientSide && inGround && inGroundTime == 1) { spawnBreachParticles(); } } @Override protected void onHit(@NotNull HitResult pResult) { for (Entity entity : getEntities()) { onHitEntity(new EntityHitResult(entity)); } super.onHit(pResult); } protected List getEntities() { List ret_list = new ArrayList<>(); Vec3 corner1 = position().subtract(range, range, range); Vec3 corner2 = position().add(range, range, range); AABB boundingBox = new AABB(corner1, corner2); for (Entity entity : level().getEntitiesOfClass(LivingEntity.class, boundingBox)) { if (entity.getBoundingBox().intersects(position(), position().add(getDeltaMovement().normalize().scale(range)))) { ret_list.add(entity); } } return ret_list; } protected void spawnBreachParticles() { int max = ConfigClient.calcPCount(20); Vec3 delta = getDeltaMovement().normalize().scale(range); for (int i = 0; i < max; i++) { Vec3 pos = position().add(delta.scale((float) i / (max - 1))); level().addParticle(particles.PARTICLE_BREACHING_ARROW.get(), pos.x, pos.y, pos.z, 0, 0, 0); } } @Override public void spawnParticles() { for (int i = 1; i <= ConfigClient.calcPCount(5); i++) { Vec3 pos = createParticlePos(1f); level().addParticle(particles.PARTICLE_BREACHING_ARROW.get(), pos.x, pos.y, pos.z, 0, 0, 0); } } }