Файербол и его спавн

Версия Minecraft
1.12.2
API
Forge
183
8
16
Здравствуйте! Я хочу заспавнить энтити файербола, но чтобы это как-бы сделал игрок. У гаста в коде подсмотрел кое-что:
Java:
EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
World world = this.parentEntity.world;
Vec3d vec3d = this.parentEntity.getLook(1.0F);
double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3d.x * 4.0D);
double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F));
double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3d.z * 4.0D);
EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4);
entitylargefireball.explosionPower = this.parentEntity.getFireballStrength();
entitylargefireball.posX = this.parentEntity.posX + vec3d.x * 4.0D;
entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D;
entitylargefireball.posZ = this.parentEntity.posZ + vec3d.z * 4.0D;
world.spawnEntity(entitylargefireball);
Но тут используется энтити, в которога гаст стреляет. Во-первых у игрока нет .getAttackTarget хотя он собственно и не нужен. Во-вторых, мне нужно чтобы можно было не только в энтитей кидать, но и в блоки. Так что прошу форум подсказать мне, как правильно реализовать спавн
 
7,099
324
1,510
Можно сделать свой фаербол на основе EntityThrowable и делегировать ванильному фаерболу вызовы методов, поведение которых устраивает
 
183
8
16
Java:
@SubscribeEvent
    public static void onRightClick(PlayerInteractEvent.RightClickItem event) {
        ItemStack stack = event.getItemStack();
        if (stack.getItem().equals(Items.FIRE_CHARGE)) {
            EntityLargeFireball entitylargefireball = new EntityLargeFireball(event.getWorld());
            EntityPlayer player = event.getEntityPlayer();
            shoot(player, player.rotationPitch, player.rotationYawHead, 0.0F, 1.5F, entitylargefireball);
            if (!event.getWorld().isRemote) {
                event.getWorld().spawnEntity(entitylargefireball);
            }
            if (!player.capabilities.isCreativeMode) {
                stack.shrink(1);
            }
            player.getCooldownTracker().setCooldown(stack.getItem(), 20);
            player.addStat(Objects.requireNonNull(StatList.getObjectUseStats(Items.FIRE_CHARGE)));
        }
    }
    public static void shoot(Entity entityThrower, float rotationPitchIn, float rotationYawIn, float pitchOffset, float velocity, Entity projectile)
    {
        float f = -MathHelper.sin(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F);
        float f1 = -MathHelper.sin((rotationPitchIn + pitchOffset) * 0.017453292F);
        float f2 = MathHelper.cos(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F);
        shoot(f, f1, f2, velocity, projectile);
        projectile.motionX += entityThrower.motionX;
        projectile.motionZ += entityThrower.motionZ;

        if (!entityThrower.onGround)
        {
            projectile.motionY += entityThrower.motionY;
        }
    }

    public static void shoot(double x, double y, double z, float velocity, Entity projectile)
    {
        float f = MathHelper.sqrt(x * x + y * y + z * z);
        x = x / (double)f;
        y = y / (double)f;
        z = z / (double)f;
        x = x * (double)velocity;
        y = y * (double)velocity;
        z = z * (double)velocity;
        projectile.motionX = x;
        projectile.motionY = y;
        projectile.motionZ = z;
        float f1 = MathHelper.sqrt(x * x + z * z);
        projectile.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
        projectile.rotationPitch = (float)(MathHelper.atan2(y, f1) * (180D / Math.PI));
        projectile.prevRotationYaw = projectile.rotationYaw;
        projectile.prevRotationPitch = projectile.rotationPitch;
    }
скопировал с EntityTrowable метод shoot, немного подредактировав. кулдаун проигрывается, а файербол не появляется
 
183
8
16
А, спасибо. Только теперь осталась одна проблема. Устанавливая в координаты файербола координаты игрока, я спавню его прямо в игроке, из-за чего он сразу взрывается. Как заспавнить его чуть-чуть дальше по взгляду игрока?
 

tox1cozZ

aka Agravaine
8,455
598
2,892
Умножить вектор взгляда на дистанцию.
Java:
float distance = 0.5F;
float f = -MathHelper.sin(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F) * distance;
float f1 = -MathHelper.sin((rotationPitchIn + pitchOffset) * 0.017453292F) * distance;
float f2 = MathHelper.cos(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F) * distance;
 
183
8
16
Я конечно совсем тупой, но можете подсказать, как это сделать? А, вот, получилось так:
Java:
Vec3d vec3d = player.getLook(1.0F);
entitylargefireball.setPosition(vec3d.x + player.posX,vec3d.y + player.posY + player.height,vec3d.z + player.posZ);
но через какое-то время полёта он просто замирает в воздухе
 
Последнее редактирование:
Сверху