Проблема рендера стрелы

Версия Minecraft
1.12+
API
Forge
106
3
7
Здравствуйте, пытаюсь создать кастомный прожектиль в сущности являющийся стрелой с измененной текстурой, звуками, не имеющей предмета, не подбираемой и летящей всегда с максимальной скоростью 1F. Все работает, но в полете ее колбасит как на скринах, а при горизонтальном попадании по блоку ее трясет вверх вниз, но чем больше угол тем меньше трясет. Думаю здесь какие то проблемы с yaw и pitch но не могу понять какие, потому что все переменные из суперклассов.

Класс стрелы:
Код:
public class EntityRCShard extends EntityArrow{
  
    private Block inTile;

    public EntityRCShard(World worldIn) {
        super(worldIn);
    }

    public EntityRCShard(World worldIn, double x, double y, double z) {
        super(worldIn, x, y, z);
    }
    
    public EntityRCShard(World worldIn, EntityLivingBase shooter) {
        this(worldIn, shooter.posX, shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D, shooter.posZ);
        this.shootingEntity = shooter;

    }
    
    @Override
    protected void onHit(RayTraceResult raytraceResultIn) {
        Entity entity = raytraceResultIn.entityHit;

        if (entity != null) {
            float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
            int i = MathHelper.ceil((double)f * super.getDamage());

            if (this.getIsCritical())
            {
                i += this.rand.nextInt(i / 2 + 2);
            }

            DamageSource damagesource;

            /*if (this.shootingEntity == null)
            {
                damagesource = DamageSource.causeArrowDamage(this, this);
            }
            else
            {
                damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity);
            }*/
            damagesource = DamageSource.causeMobDamage((EntityLivingBase) this.shootingEntity);

            if (this.isBurning() && !(entity instanceof EntityEnderman))
            {
                entity.setFire(5);
            }

            if (entity.attackEntityFrom(damagesource, (float)i))
            {
                if (entity instanceof EntityLivingBase)
                {
                    EntityLivingBase entitylivingbase = (EntityLivingBase)entity;

                    if (!this.world.isRemote)
                    {
                        entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
                    }

                    /*if (knockbackStrength > 0)
                    {
                        float f1 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);

                        if (f1 > 0.0F)
                        {
                            entitylivingbase.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1);
                        }
                    }*/

                    if (this.shootingEntity instanceof EntityLivingBase)
                    {
                        EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
                        EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase)this.shootingEntity, entitylivingbase);
                    }

                    entity.attackEntityFrom(damagesource, 5);

                    if (this.shootingEntity != null && entitylivingbase != this.shootingEntity && entitylivingbase instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
                    {
                        ((EntityPlayerMP)this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
                    }
                }

                this.playSound(InitSounds.hit_of_kagune, 0.5F, 1.0F);
                

                if (!(entity instanceof EntityEnderman))
                {
                    this.setDead();
                }
            }
            else
            {
                this.motionX *= -0.10000000149011612D;
                this.motionY *= -0.10000000149011612D;
                this.motionZ *= -0.10000000149011612D;
                this.rotationYaw += 180.0F;
                this.prevRotationYaw += 180.0F;
                //this.ticksInAir = 0;

                if (!this.world.isRemote && this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ < 0.0010000000474974513D)
                {
                    this.setDead();
                }
            }
        }
        else
        {
            /*BlockPos blockpos = raytraceResultIn.getBlockPos();
            this.xTile = blockpos.getX();
            this.yTile = blockpos.getY();
            this.zTile = blockpos.getZ();
            IBlockState iblockstate = this.world.getBlockState(blockpos);
            this.inTile = iblockstate.getBlock();
            this.inData = this.inTile.getMetaFromState(iblockstate);
            this.motionX = (double)((float)(raytraceResultIn.hitVec.x - this.posX));
            this.motionY = (double)((float)(raytraceResultIn.hitVec.y - this.posY));
            this.motionZ = (double)((float)(raytraceResultIn.hitVec.z - this.posZ));
            float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
            this.posX -= this.motionX / (double)f2 * 0.05000000074505806D;
            this.posY -= this.motionY / (double)f2 * 0.05000000074505806D;
            this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D;
            //this.playSound(InitSounds.hit_ground_kagune_2, 0.4F, 1.0F);
            this.inGround = true;
            this.arrowShake = 7;
            this.setIsCritical(false);

            if (iblockstate.getMaterial() != Material.AIR)
            {
                this.inTile.onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
            }*/
            BlockPos blockpos = raytraceResultIn.getBlockPos();
            blockpos.getX();
            blockpos.getY();
            blockpos.getZ();
            IBlockState iblockstate = world.getBlockState(blockpos);
            inTile = iblockstate.getBlock();
            inTile.getMetaFromState(iblockstate);
            motionX = (double)((float)(raytraceResultIn.hitVec.x - posX));
            motionY = (double)((float)(raytraceResultIn.hitVec.y - posY));
            motionZ = (double)((float)(raytraceResultIn.hitVec.z - posZ));
            float f2 = MathHelper.sqrt(motionX * motionX + motionY * motionY + motionZ * motionZ);
            posX -= motionX / (double)f2 * 0.05000000074505806D;
            posY -= motionY / (double)f2 * 0.05000000074505806D;
            posZ -= motionZ / (double)f2 * 0.05000000074505806D;
            //playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
            inGround = true;
            arrowShake = 7;
            setIsCritical(false);

            if (iblockstate.getMaterial() != Material.AIR) inTile.onEntityCollidedWithBlock(world, blockpos, iblockstate, this);
        }
    }

    @Override
    protected ItemStack getArrowStack() {
        return null;
    }
}

Стрельба:
Код:
EntityRCShard entityrcshard = createShard(player.world, player);
                entityrcshard.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, ItemKaguneUkaku.arrowVelocity * 3F, 1.0F);
                entityrcshard.setIsCritical(false);
                entityrcshard.setDamage(0);
                entityrcshard.setKnockbackStrength(0);
                entityrcshard.setFire(0);     
                           
                player.world.spawnEntity(entityrcshard);
Код:
public static EntityRCShard createShard(World worldIn, EntityLivingBase shooter)
    {
        EntityRCShard entitytippedrcshard = new EntityRCShard(worldIn, shooter);
        return entitytippedrcshard;
    }

Регистрация:
Код:
@Mod.EventBusSubscriber(modid = "dm")
public class EntityRegistry {
    @SideOnly(Side.CLIENT)
    public static void initModels() {
        RenderingRegistry.registerEntityRenderingHandler(EntityRCShard.class, RenderRCShard.FACTORY);
    }

    private static int ID = 0;
    
    public static EntityEntry RCSHARD = EntityEntryBuilder
            .create()
            .entity(EntityRCShard.class)
            .name("RCShard")
            .id("rc_shard", ID++)
            .tracker(160, 2, false)
            .build();

    @SubscribeEvent
    public static void registryEntity(RegistryEvent.Register<EntityEntry> event) {
        event.getRegistry().registerAll(
                RCSHARD
        );
    }
}

Рендер:
Код:
public class RenderRCShard extends RenderArrow<EntityRCShard>{

    public RenderRCShard(RenderManager manager) {
        super(manager);
    }
    
    public static Factory FACTORY = new Factory();
    
    @Override
    protected ResourceLocation getEntityTexture(EntityRCShard entity) {
        return new ResourceLocation(Reference.MODID + ":textures/entity/projectile/shard.png");
    }
    
    public static class Factory implements IRenderFactory<EntityRCShard> {
        @Override
        public Render<? super EntityRCShard> createRenderFor(RenderManager manager) {
            return new RenderRCShard(manager);
        }
    }
}
 

Вложения

  • 2021-10-20_22.09.39.png
    2021-10-20_22.09.39.png
    52 KB · Просмотры: 29
  • 2021-10-20_22.11.22.png
    2021-10-20_22.11.22.png
    212.8 KB · Просмотры: 29
  • 2021-10-20_22.11.26.png
    2021-10-20_22.11.26.png
    204.4 KB · Просмотры: 29

necauqua

когда-то был anti344
Администратор
1,216
27
172
ну вот это возможно имеет отношение к тряске при попадании в блок, чисто по контексту и названию, попробуй 7 на 0 заменить

У стрел pitch/yaw вычисляется от вектора движения (motionX/Y/Z), и ты с ним ничего эдакого не делал и летит же в нужную сторону изначально - вообще странно что не работает, конечно, рендер ты тоже не трогал 🤷

Если в коде выстрела заменить твою кастомную стрелу на ванильную, то она нормально повёрнута? А то вдруг это мк виноват вообще

new ResourceLocation(Reference.MODID + ":
заменяем + ": на , "
 
106
3
7
Если в коде выстрела заменить твою кастомную стрелу на ванильную, то она нормально повёрнута?
Да, она абсолютно нормально летит. Ещё заметил что если трекер поставить 64 20 как у обычной стрелы, то летит по правильной траектории, а вот рендер очень странный: выглядит как будто она падает в паре блоков от тебя а потом резко появляется в месте падения
 
178
4
42
выглядит как будто она падает в паре блоков от тебя а потом резко появляется в месте падения
проверь, что летит не слишком быстро. Значение motion не должно превышать 4.9D. И что не считаешь движение стрелы на клиенте.
 
Сверху