- 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);
}
}
}