[1.7.10] Лазер

Ну мне нужно было в когда-то рисовать веревку, вот и пришлось перевести метод на умеренно-человеческий. ЕМНИП, аналогичный код в майне лежит в коде RenderLivingEntity или где-то рядом.
 
у вас тут прям не майнкрафт а высшая математика какая-то, формулы, рендер, классы....
Хорошо что я только моделированием занимаюсь =)
 
Это меня ободрило. :)
Весь день парюсь с этой проверкой чексум, параллельно делая верёвку
 
А можно что-бы энтити рендерился даже сзади?)
Или мне придется делать лазер из кусочков, спавнить энтити от А до Б, через определённый промежуток. А то, если растягивать, то лазер пропадает целиком, если отвернуться, даже если он рядом от тебя пролетел :)
 
Это называется Frustrum Check. Если объект не в фруструме, он просто не рисуется. Вроде бы в энтити был метод, где это можно отключить.
 
1) можно поиграться с AABB сущности (не рендерится сущность тогда, когда ее ААВВ не попадает в камеру), но это чревато проблемами с рассчетом столкновения
2) не могу сходу сказать, но наверняка в классе рендера сущности или в классе самой сущности можно переписать какой-нибудь метод с названием вроде ignoreRenderBounds (точно не так, но что-то вроде), и если в этом метода возвращать true, то лазер будет рендерится всегда.

UPD: на заметил ответа Дракона. Он сказал то же самое, что я во втором варианте.
 
У меня тут ещё 1 трабла, не работает поиск энтити(
Код:
package com.svk.industrialGuns.entity;

import java.util.List;

import com.svk.industrialGuns.particle.ColoredParticleCubeHeap;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class EntityLaser extends EntityBulletVisible
{
    public float speed = 0;
    public float gravity = 0;
    public int damage = 0;
    public double bylletMotionX = 0;
    public double bylletMotionY = 0;
    public double bylletMotionZ = 0;
    private EntityPlayer player = null;
    public byte texture = 0;
    
    public double endX = 0;
    public double endY = 0;
    public double endZ = 0;
    public double startX = 0;
    public double startY = 0;
    public double startZ = 0;
    
    public EntityLaser(World world, boolean render) 
    {
        super(world);
    }

    public EntityLaser(World world, EntityLivingBase entity) 
    {
        super(world, entity);
        this.texture = (byte) (world.rand.nextInt(3) + 1);
        this.render = true;
        this.prevRotationYaw = (this.rotationYaw = (float)Math.toDegrees(Math.atan2(motionX, motionZ)));
        this.prevRotationPitch = (this.rotationPitch = (float)Math.toDegrees(Math.atan2(motionY, MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ))));
        this.player = (EntityPlayer) entity;
    }
    
    public void setPosition()
    {
        double posX = player.posX;
        double posY = player.posY;
        double posZ = player.posZ;
        
        startX = posX;
        startY = posY;
        startZ = posZ;
        
        Vec3 vec3 = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
        Vec3 vec31 = Vec3.createVectorHelper(player.posX + this.bylletMotionX * 300, player.posY + this.bylletMotionY * 300, player.posZ + this.bylletMotionZ * 300);
        MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
        vec3 = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
        vec31 = Vec3.createVectorHelper(player.posX + this.bylletMotionX * 300, player.posY + this.bylletMotionY * 300, player.posZ + this.bylletMotionZ * 300);

        if (movingobjectposition != null)
        {
            vec31 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
        }
        
        Entity entity = null;
        List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.bylletMotionX, this.bylletMotionY, this.bylletMotionZ).expand(1.0D, 1.0D, 1.0D));
        double d0 = 0.0D;
        EntityLivingBase entitylivingbase = this.getThrower();

        for (int j = 0; j < list.size(); ++j)
        {
            Entity entity1 = (Entity)list.get(j);

            if (entity1.canBeCollidedWith() && entity1 != entitylivingbase)
            {
                float f = 0.3F;
                AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double)f, (double)f, (double)f);
                MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);

                if (movingobjectposition1 != null)
                {
                    double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

                    if (d1 < d0 || d0 == 0.0D)
                    {
                        entity = entity1;
                        d0 = d1;
                    }
                }
            }
        }

        if (entity != null)
        {
            movingobjectposition = new MovingObjectPosition(entity);
        }

        if (movingobjectposition != null)
        {
            if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlock(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ) == Blocks.portal)
            {
                this.setInPortal();
            }
            else
            {
                setPoint(movingobjectposition);
            }
        }
        else
        {
            Vec3 movingobjectpositionP = player.getLookVec();
            endX = player.posX + movingobjectpositionP.xCoord * 100;
            endY = player.posY + movingobjectpositionP.yCoord * 100;
            endZ = player.posZ + movingobjectpositionP.zCoord * 100;
            this.setPosition(posX + (endX - posX)/2, posY + (endY - posY)/2, posZ + (endZ - posZ)/2);
        }
    }
    
    private void setPoint(MovingObjectPosition mop)
    {
        endX = mop.hitVec.xCoord;
        endY = mop.hitVec.yCoord;
        endZ = mop.hitVec.zCoord;
        
        if(mop.entityHit != null)
        {
            endX = mop.entityHit.posX;
            endY = mop.entityHit.posY;
            endZ = mop.entityHit.posZ;
        }
        
        this.setPosition(posX + (endX - posX)/2, posY + (endY - posY)/2, posZ + (endZ - posZ)/2);
    }
    
    @Override
    public void onUpdate()
    {
        super.onUpdate();
        
        this.motionX = bylletMotionX * 0.0001;
        this.motionY = bylletMotionY * 0.0001;
        this.motionZ = bylletMotionZ * 0.0001;
    }

    protected float getVelocity()
    {
        return speed;
    }
    
    protected float getGravityVelocity()
    {
        return gravity;
    }

    @Override
    protected void onImpact(MovingObjectPosition mop) 
    {
        if(mop.entityHit != null && !(mop.entityHit instanceof EntityLaser))
        {
            mop.entityHit.hurtResistantTime = 0;
            mop.entityHit.attackEntityFrom(DamageSource.cactus, 5);
            this.setDead();
        }
        if(!(mop.entityHit instanceof EntityLaser))
        {
            this.setDead();
        }
    }
}

Поиск блока работает, а энтити не хочет( Не подскажите, в чём может быть проблема? Может чем-то заменить мой код поиска энтити?
 
Agravaine написал(а):
Аааа, ну я же тебе рассказывал про наследывания!
Нафига ты в дочерном классе объявляешь новые переменные, которые есть в родителе!?
Например?)
[merge_posts_bbcode]Добавлено: 16.04.2015 21:19:26[/merge_posts_bbcode]

Agravaine написал(а):
Аааа, ну я же тебе рассказывал про наследывания!
Нафига ты в дочерном классе объявляешь новые переменные, которые есть в родителе!?
И не надо вести себя так, будто ты мне рассказывал про наследования, а я ничего не понимал и до этого не знал -_-
 
Я уверен, что эти переменные есть в родителе:
Код:
public float speed = 0;
    public float gravity = 0;
    public int damage = 0;
    public double bylletMotionX = 0;
    public double bylletMotionY = 0;
    public double bylletMotionZ = 0;
    private EntityPlayer player = null;
    public byte texture = 0;
 
Agravaine написал(а):
Я уверен, что эти переменные есть в родителе:
Код:
public float speed = 0;
    public float gravity = 0;
    public int damage = 0;
    public double bylletMotionX = 0;
    public double bylletMotionY = 0;
    public double bylletMotionZ = 0;
    private EntityPlayer player = null;
    public byte texture = 0;
Не знаю, bylletMotion делал для того, что-бы иметь чистый motion и motion с гравитацией (Родительский)
gravity и speed, по-моему методами устанавливается...
player thrower по-моему или как-то так...
Ну texture уж точно нет...

А мне нужны speed и gravity публичными, для того, что-бы из пули можно было их доставать.
Насчёт thrower`а - я ещё не знал тогда... Да и сейчас не уверен.
 
Ещё лучше - методы speed и gravity не публичны, а protected
[merge_posts_bbcode]Добавлено: 16.04.2015 22:02:51[/merge_posts_bbcode]

svk написал(а):
У меня тут ещё 1 трабла, не работает поиск энтити(
Код:
package com.svk.industrialGuns.entity;

import java.util.List;

import com.svk.industrialGuns.particle.ColoredParticleCubeHeap;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class EntityLaser extends EntityBulletVisible
{
    public float speed = 0;
    public float gravity = 0;
    public int damage = 0;
    public double bylletMotionX = 0;
    public double bylletMotionY = 0;
    public double bylletMotionZ = 0;
    private EntityPlayer player = null;
    public byte texture = 0;
    
    public double endX = 0;
    public double endY = 0;
    public double endZ = 0;
    public double startX = 0;
    public double startY = 0;
    public double startZ = 0;
    
    public EntityLaser(World world, boolean render) 
    {
        super(world);
    }

    public EntityLaser(World world, EntityLivingBase entity) 
    {
        super(world, entity);
        this.texture = (byte) (world.rand.nextInt(3) + 1);
        this.render = true;
        this.prevRotationYaw = (this.rotationYaw = (float)Math.toDegrees(Math.atan2(motionX, motionZ)));
        this.prevRotationPitch = (this.rotationPitch = (float)Math.toDegrees(Math.atan2(motionY, MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ))));
        this.player = (EntityPlayer) entity;
    }
    
    public void setPosition()
    {
        double posX = player.posX;
        double posY = player.posY;
        double posZ = player.posZ;
        
        startX = posX;
        startY = posY;
        startZ = posZ;
        
        Vec3 vec3 = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
        Vec3 vec31 = Vec3.createVectorHelper(player.posX + this.bylletMotionX * 300, player.posY + this.bylletMotionY * 300, player.posZ + this.bylletMotionZ * 300);
        MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
        vec3 = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
        vec31 = Vec3.createVectorHelper(player.posX + this.bylletMotionX * 300, player.posY + this.bylletMotionY * 300, player.posZ + this.bylletMotionZ * 300);

        if (movingobjectposition != null)
        {
            vec31 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
        }
        
        Entity entity = null;
        List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.bylletMotionX, this.bylletMotionY, this.bylletMotionZ).expand(1.0D, 1.0D, 1.0D));
        double d0 = 0.0D;
        EntityLivingBase entitylivingbase = this.getThrower();

        for (int j = 0; j < list.size(); ++j)
        {
            Entity entity1 = (Entity)list.get(j);

            if (entity1.canBeCollidedWith() && entity1 != entitylivingbase)
            {
                float f = 0.3F;
                AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double)f, (double)f, (double)f);
                MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);

                if (movingobjectposition1 != null)
                {
                    double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

                    if (d1 < d0 || d0 == 0.0D)
                    {
                        entity = entity1;
                        d0 = d1;
                    }
                }
            }
        }

        if (entity != null)
        {
            movingobjectposition = new MovingObjectPosition(entity);
        }

        if (movingobjectposition != null)
        {
            if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlock(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ) == Blocks.portal)
            {
                this.setInPortal();
            }
            else
            {
                setPoint(movingobjectposition);
            }
        }
        else
        {
            Vec3 movingobjectpositionP = player.getLookVec();
            endX = player.posX + movingobjectpositionP.xCoord * 100;
            endY = player.posY + movingobjectpositionP.yCoord * 100;
            endZ = player.posZ + movingobjectpositionP.zCoord * 100;
            this.setPosition(posX + (endX - posX)/2, posY + (endY - posY)/2, posZ + (endZ - posZ)/2);
        }
    }
    
    private void setPoint(MovingObjectPosition mop)
    {
        endX = mop.hitVec.xCoord;
        endY = mop.hitVec.yCoord;
        endZ = mop.hitVec.zCoord;
        
        if(mop.entityHit != null)
        {
            endX = mop.entityHit.posX;
            endY = mop.entityHit.posY;
            endZ = mop.entityHit.posZ;
        }
        
        this.setPosition(posX + (endX - posX)/2, posY + (endY - posY)/2, posZ + (endZ - posZ)/2);
    }
    
    @Override
    public void onUpdate()
    {
        super.onUpdate();
        
        this.motionX = bylletMotionX * 0.0001;
        this.motionY = bylletMotionY * 0.0001;
        this.motionZ = bylletMotionZ * 0.0001;
    }

    protected float getVelocity()
    {
        return speed;
    }
    
    protected float getGravityVelocity()
    {
        return gravity;
    }

    @Override
    protected void onImpact(MovingObjectPosition mop) 
    {
        if(mop.entityHit != null && !(mop.entityHit instanceof EntityLaser))
        {
            mop.entityHit.hurtResistantTime = 0;
            mop.entityHit.attackEntityFrom(DamageSource.cactus, 5);
            this.setDead();
        }
        if(!(mop.entityHit instanceof EntityLaser))
        {
            this.setDead();
        }
    }
}

Поиск блока работает, а энтити не хочет( Не подскажите, в чём может быть проблема? Может чем-то заменить мой код поиска энтити?
Up
 
А что мешает наследнику класса работать с protected полями родителя?
 
Опять же, если у тебя энтити в одном пакете с оружием то ничего не мешает.
 
Можно из оружия передавать свои параметры, а в энтити уже передавать полям.
 
Crowbar написал(а):
Можно из оружия передавать свои параметры, а в энтити уже передавать полям.
What? Я и делаю так: ставлю переменные, а переменные в методах используются.
 
svk написал(а):
У меня тут ещё 1 трабла, не работает поиск энтити(
Код:
package com.svk.industrialGuns.entity;

import java.util.List;

import com.svk.industrialGuns.particle.ColoredParticleCubeHeap;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class EntityLaser extends EntityBulletVisible
{
    public float speed = 0;
    public float gravity = 0;
    public int damage = 0;
    public double bylletMotionX = 0;
    public double bylletMotionY = 0;
    public double bylletMotionZ = 0;
    private EntityPlayer player = null;
    public byte texture = 0;
    
    public double endX = 0;
    public double endY = 0;
    public double endZ = 0;
    public double startX = 0;
    public double startY = 0;
    public double startZ = 0;
    
    public EntityLaser(World world, boolean render) 
    {
        super(world);
    }

    public EntityLaser(World world, EntityLivingBase entity) 
    {
        super(world, entity);
        this.texture = (byte) (world.rand.nextInt(3) + 1);
        this.render = true;
        this.prevRotationYaw = (this.rotationYaw = (float)Math.toDegrees(Math.atan2(motionX, motionZ)));
        this.prevRotationPitch = (this.rotationPitch = (float)Math.toDegrees(Math.atan2(motionY, MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ))));
        this.player = (EntityPlayer) entity;
    }
    
    public void setPosition()
    {
        double posX = player.posX;
        double posY = player.posY;
        double posZ = player.posZ;
        
        startX = posX;
        startY = posY;
        startZ = posZ;
        
        Vec3 vec3 = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
        Vec3 vec31 = Vec3.createVectorHelper(player.posX + this.bylletMotionX * 300, player.posY + this.bylletMotionY * 300, player.posZ + this.bylletMotionZ * 300);
        MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
        vec3 = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
        vec31 = Vec3.createVectorHelper(player.posX + this.bylletMotionX * 300, player.posY + this.bylletMotionY * 300, player.posZ + this.bylletMotionZ * 300);

        if (movingobjectposition != null)
        {
            vec31 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
        }
        
        Entity entity = null;
        List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.bylletMotionX, this.bylletMotionY, this.bylletMotionZ).expand(1.0D, 1.0D, 1.0D));
        double d0 = 0.0D;
        EntityLivingBase entitylivingbase = this.getThrower();

        for (int j = 0; j < list.size(); ++j)
        {
            Entity entity1 = (Entity)list.get(j);

            if (entity1.canBeCollidedWith() && entity1 != entitylivingbase)
            {
                float f = 0.3F;
                AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double)f, (double)f, (double)f);
                MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);

                if (movingobjectposition1 != null)
                {
                    double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

                    if (d1 < d0 || d0 == 0.0D)
                    {
                        entity = entity1;
                        d0 = d1;
                    }
                }
            }
        }

        if (entity != null)
        {
            movingobjectposition = new MovingObjectPosition(entity);
        }

        if (movingobjectposition != null)
        {
            if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlock(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ) == Blocks.portal)
            {
                this.setInPortal();
            }
            else
            {
                setPoint(movingobjectposition);
            }
        }
        else
        {
            Vec3 movingobjectpositionP = player.getLookVec();
            endX = player.posX + movingobjectpositionP.xCoord * 100;
            endY = player.posY + movingobjectpositionP.yCoord * 100;
            endZ = player.posZ + movingobjectpositionP.zCoord * 100;
            this.setPosition(posX + (endX - posX)/2, posY + (endY - posY)/2, posZ + (endZ - posZ)/2);
        }
    }
    
    private void setPoint(MovingObjectPosition mop)
    {
        endX = mop.hitVec.xCoord;
        endY = mop.hitVec.yCoord;
        endZ = mop.hitVec.zCoord;
        
        if(mop.entityHit != null)
        {
            endX = mop.entityHit.posX;
            endY = mop.entityHit.posY;
            endZ = mop.entityHit.posZ;
        }
        
        this.setPosition(posX + (endX - posX)/2, posY + (endY - posY)/2, posZ + (endZ - posZ)/2);
    }
    
    @Override
    public void onUpdate()
    {
        super.onUpdate();
        
        this.motionX = bylletMotionX * 0.0001;
        this.motionY = bylletMotionY * 0.0001;
        this.motionZ = bylletMotionZ * 0.0001;
    }

    protected float getVelocity()
    {
        return speed;
    }
    
    protected float getGravityVelocity()
    {
        return gravity;
    }

    @Override
    protected void onImpact(MovingObjectPosition mop) 
    {
        if(mop.entityHit != null && !(mop.entityHit instanceof EntityLaser))
        {
            mop.entityHit.hurtResistantTime = 0;
            mop.entityHit.attackEntityFrom(DamageSource.cactus, 5);
            this.setDead();
        }
        if(!(mop.entityHit instanceof EntityLaser))
        {
            this.setDead();
        }
    }
}

Поиск блока работает, а энтити не хочет( Не подскажите, в чём может быть проблема? Может чем-то заменить мой код поиска энтити?
Up
 
Назад
Сверху