Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
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 написал(а):Аааа, ну я же тебе рассказывал про наследывания!
Нафига ты в дочерном классе объявляешь новые переменные, которые есть в родителе!?
И не надо вести себя так, будто ты мне рассказывал про наследования, а я ничего не понимал и до этого не знал -_-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 с гравитацией (Родительский)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;
Upsvk написал(а):У меня тут ещё 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(); } } }
Поиск блока работает, а энтити не хочет( Не подскажите, в чём может быть проблема? Может чем-то заменить мой код поиска энтити?
Я из оружия эти параметры задаюDragon2488 написал(а):А что мешает наследнику класса работать с protected полями родителя?
Да? Я думал protected только для наследников доступен 0_0Dragon2488 написал(а):Опять же, если у тебя энтити в одном пакете с оружием то ничего не мешает.
What? Я и делаю так: ставлю переменные, а переменные в методах используются.Crowbar написал(а):Можно из оружия передавать свои параметры, а в энтити уже передавать полям.
Upsvk написал(а):У меня тут ещё 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(); } } }
Поиск блока работает, а энтити не хочет( Не подскажите, в чём может быть проблема? Может чем-то заменить мой код поиска энтити?