- 1,185
- 3
1 основной класс пули:
http://pastebin.com/cDjNrLqa
В это классе, есть эти строки:
Видимо они отвечают за корректировку движения и расположения при большой скорости.
Если вы делаете энтити, которое не двигается или же делает это не быстро, то лучше эти строки убрать.
2 промежуточный класс:
Переменные можно поставить свои, но их надо сохранять/загружать в SpawnData
Класс пули:
EntityZardiaShell заменить на свой класс.
Спавн пули:
И метод регестрации в базовом классе мода:
64 - дальность апдейта
20 - количество апдейтов в секунду
http://pastebin.com/cDjNrLqa
В это классе, есть эти строки:
Код:
this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F *(float)Math.PI) * f);
this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F *(float)Math.PI) * f);
this.motionY = (double)(-MathHelper.sin((this.rotationPitch + this.func_70183_g()) / 180.0F * (float)Math.PI) * f);
Если вы делаете энтити, которое не двигается или же делает это не быстро, то лучше эти строки убрать.
2 промежуточный класс:
Код:
package com.svk.industrialGuns.entity;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class EntityBullet extends EntityBulletBase
{
public float speed = 0;
public float gravity = 0;
public int damage = 0;
public double bulletMotionX = 0;
public double bulletMotionY = 0;
public double bulletMotionZ = 0;
public int life = 0;
public EntityBullet(World world)
{
super(world);
}
public EntityBullet(World p_i1777_1_, EntityLivingBase p_i1777_2_)
{
super(p_i1777_1_, p_i1777_2_);
}
@Override
protected void onImpact(MovingObjectPosition p_70184_1_) {}
@Override
public void writeSpawnData(ByteBuf buf)
{
buf.writeFloat(speed);
buf.writeFloat(gravity);
buf.writeInt(damage);
buf.writeDouble(bulletMotionX);
buf.writeDouble(bulletMotionY);
buf.writeDouble(bulletMotionZ);
buf.writeInt(life);
buf.writeFloat(addSize);
}
@Override
public void readSpawnData(ByteBuf buf)
{
this.speed = buf.readFloat();
this.gravity = buf.readFloat();
this.damage = buf.readInt();
this.bulletMotionX = buf.readDouble();
this.bulletMotionY = buf.readDouble();
this.bulletMotionZ = buf.readDouble();
this.life = buf.readInt();
this.addSize = buf.readFloat();
}
}
Переменные можно поставить свои, но их надо сохранять/загружать в SpawnData
Класс пули:
Код:
package com.svk.industrialGuns.entity;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import com.svk.industrialGuns.client.particle.ColoredParticleCube;
import com.svk.industrialGuns.client.particle.ColoredParticleCubeHeap;
import com.svk.industrialGuns.client.particle.ParticleLava;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
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.Items;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class EntityZardiaShell extends EntityBullet
{
public EntityZardiaShell(World world)
{
super(world);
super.render = true;
}
public EntityZardiaShell(World world, EntityLivingBase entity)
{
super(world, entity);
super.render = true;
}
@Override
public void onUpdate()
{
super.onUpdate();
life++;
if(life > 100)
{
this.setDead();
}
this.motionX = bulletMotionX * speed;
this.motionY = bulletMotionY * speed;
this.motionZ = bulletMotionZ * speed;
}
@Override
protected void onImpact(MovingObjectPosition mop)
{
if(mop.entityHit != null && !(mop.entityHit instanceof EntityZardiaShell))
{
mop.entityHit.hurtResistantTime = 0;//Счётчик неуязвимости энтити
mop.entityHit.attackEntityFrom(DamageSource.cactus, damage);
this.setDead();
}
if(!(mop.hitInfo instanceof Entity))
{
this.setDead();
}
}
}
EntityZardiaShell заменить на свой класс.
Спавн пули:
Код:
if(!world.isRemote)
{
Vec3 movingobjectposition = player.getLookVec();
EntityBullet bullet = new EntityZardiaShell(world, player);
bullet.setPosition(bullet.posX + movingobjectposition.xCoord * 1.0D, bullet.posY+0.5 + movingobjectposition.yCoord * 1.0D, bullet.posZ + movingobjectposition.zCoord * 1.0D);
bullet.bulletMotionX = movingobjectposition.xCoord + Функция_разброса;
bullet.bulletMotionY = movingobjectposition.yCoord + Функция_разброса;
bullet.bulletMotionZ = movingobjectposition.zCoord + Функция разброса;
bullet.damage = bulletDamage;
bullet.speed = bulletSpeed;
world.spawnEntityInWorld(bullet);
}
И метод регестрации в базовом классе мода:
Код:
public void registerEntity()
{
int entityId = 0;
EntityRegistry.registerModEntity(EntityZardiaShell.class, "EntityZardiaShell", entityId++, this, 64, 20, true);
}
20 - количество апдейтов в секунду