EntityThrowable

Версия Minecraft
1.7.10
Добрый день, форумчане!
Вопрос состоит в следующем...
Сделал значит я entity bullet вроде всё работает, но сама пуля достаёт до живого энтити дальше чем нужно.
Уже 2 недели ломаю голову почему, пробовал найти информацию о хитбоксах запускаемой пули, но вроде ничего нет, а this.setSize не помогло.
Вот костыль кому нужен -
Вот видео - Тут

Java:
package mods.ru.bloomvoltio.stalker.entity;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityBullet extends EntityThrowable {

    public float damage;
    public float damageFactor;
    public float speedBullet = 4.0F;
    public float gravityBullet = 0.0F;
  
    public EntityBullet(World world) {
        super(world);
        this.setSize(0.0F, 0.0F);
    }
  
    public EntityBullet(World world, EntityLivingBase shooter, float damage) {
        super(world, shooter);
        this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, speedBullet, gravityBullet);
        this.damage = damage;
    }
  
    @Override
    public void onUpdate() {
        super.onUpdate();
        this.motionX *= (double)this.speedBullet;
        this.motionY *= (double)this.speedBullet;
        this.motionZ *= (double)this.speedBullet;
        this.setPosition(this.posX, this.posY, this.posZ);
    }

    @Override
    protected void onImpact(MovingObjectPosition mop) {
        if(!worldObj.isRemote) {
            if(mop.typeOfHit.equals(mop.typeOfHit.ENTITY)) {
                mop.entityHit.attackEntityFrom(new DamageSource("bullet"), damage);
                mop.entityHit.hurtResistantTime = 0;
                this.setDead();
            } else {
                this.setDead();
            }
        }
    }
}
 
Последнее редактирование:

tox1cozZ

aka Agravaine
8,455
598
2,892
Ты в setThrowableHeading передаешь неправильные аргументы.
Последние два - это разброс. Не очень понял чем они отличаются, поиграйся. По идее, если передать туда 0.0F то разброса не будет вовсе.
 
Java:
public class EntityBullet extends EntityThrowable {

    public float damage;
    public float damageFactor;
    public float velocity = 1.0F;
    public float gravityVelocity = 0.0F;
   
    public EntityBullet(World world) {
        super(world);
        this.setSize(0.1F, 0.1F);
    }
   
    public EntityBullet(World world, EntityLivingBase shooter, float damage) {
        super(world, shooter);
        this.damage = damage;
    }
   
    protected float getVelocity() {
        return velocity;
    }
   
    protected float getGravityVelocity() {
        return gravityVelocity;
    }
   
    @Override
    public void onUpdate() {
        super.onUpdate();
        this.motionX *= (double)this.getVelocity();
        this.motionY *= (double)this.getVelocity();
        this.motionZ *= (double)this.getVelocity();
        this.setPosition(this.posX, this.posY, this.posZ);
    }
Допустим мы уберём вообще setThrowableHeading, и сделаем отдельно гравитацию и скорость, но всё равно даже при минимальном разбросе всё так же, для достоверности я включил видимость пули
Вот видео с демонстрацией - тут
 
Последнее редактирование:
Java:
    @Override
    public void onUpdate() {
        super.onUpdate();
        this.motionX *= (double)this.getVelocity();
        this.motionY *= (double)this.getVelocity();
        this.motionZ *= (double)this.getVelocity();
        this.setPosition(this.posX, this.posY, this.posZ);
        Vec3 vec1 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
        Vec3 vec2 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        MovingObjectPosition mop = this.worldObj.rayTraceBlocks(vec1, vec2);
        vec1 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
        vec2 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        if (mop != null) {
            vec2 = Vec3.createVectorHelper(mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord);
        }
        Entity entity = null;
        List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
        double d0 = 0.0D;
        for (int i = 0; i < list.size(); ++i) {
            Entity entityBox = (Entity)list.get(i);
            if (entityBox.canBeCollidedWith() && (!entityBox.isEntityEqual(this.shooter))) {
                float f = 0.3F;
                AxisAlignedBB axis = entityBox.boundingBox.expand((double)f, (double)f, (double)f);
                MovingObjectPosition mop2 = axis.calculateIntercept(vec1, vec2);
                if (mop2 != null) {
                    double d1 = vec2.distanceTo(mop2.hitVec);
                    if (d1 < d0 || d0 == 0.0D) {
                        entity = entityBox;
                        d0 = d1;
                    }
                }
            }
        }
    }
Окей, почему то это не работает
 
7,099
324
1,510
Наверное, потому что пуля, которую делает ТС слишком медленно летит, чтобы юзать аппроксимацию мгновенного попадания
 
Сверху