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.
Там по всем осям инверт идёт, я и с блоком так могу, а мне лишь 1 ось нужна.Yarik написал(а):В ванильном луке/стреле это есть. Ну к примеру. Стреляй луком в Визера - будет точно отскакивать.
public void onUpdate(){
super.onUpdate();
double prevMotionX = motionX;
double prevMotionY = motionY;
double prevMotionZ = motionZ;
prevPosX = posX;
prevPosY = posY;
prevPosZ = posZ;
moveEntity(motionX, motionY, motionZ);
if(motionX == 0.0D && prevMotionX != 0.0D){
motionX = -bounceFactor * prevMotionX;
motionY = bounceSlowFactor * prevMotionY;
motionZ = bounceSlowFactor * prevMotionZ;
}
if(motionY == 0.0D && prevMotionY != 0.0D){
motionX = bounceSlowFactor * prevMotionX;
motionY = -bounceFactor * prevMotionY;
motionZ = bounceSlowFactor * prevMotionZ;
}
if(motionZ == 0.0D && prevMotionZ != 0.0D){
motionX = bounceSlowFactor * prevMotionX;
motionY = bounceSlowFactor * prevMotionY;
motionZ = -bounceFactor * prevMotionZ;
}
}
package com.svk.industrialGuns.entity;
import com.svk.industrialGuns.client.particle.ColoredParticleCube;
import com.svk.industrialGuns.client.particle.ColoredParticleCubeHeap;
import com.svk.industrialGuns.client.particle.ColoredParticleSoundwave;
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.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class EntitySonnicShell extends EntityBullet
{
public float knockback = 0;
private int reload = 0;
public EntitySonnicShell(World world, EntityLivingBase entity)
{
super(world, entity);
}
@Override
public void onUpdate()
{
super.onUpdate();
if(reload > 0)
{
reload--;
}
life++;
if(life > 120)
{
this.setDead();
}
if(this.worldObj.isRemote)
{
Minecraft.getMinecraft().effectRenderer.addEffect(new ColoredParticleSoundwave(Minecraft.getMinecraft().renderEngine, this.worldObj, this.posX, this.posY, this.posZ, this.motionX, this.motionY, this.motionZ, new int[]{0, 255, 36}, super.addSize + 0.3F));
}
double prevMotionX = motionX;
double prevMotionY = motionY;
double prevMotionZ = motionZ;
prevPosX = posX;
prevPosY = posY;
prevPosZ = posZ;
this.motionX = this.bylletMotionX * getVelocity();
this.motionY = this.bylletMotionY * getVelocity();
this.motionZ = this.bylletMotionZ * getVelocity();
double bounceFactor = 0.2;
double bounceSlowFactor = 0.2;
if(motionX == 0.0D && prevMotionX != 0.0D)
{
bylletMotionX = -bounceFactor * prevMotionX;
bylletMotionY = bounceSlowFactor * prevMotionY;
bylletMotionZ = bounceSlowFactor * prevMotionZ;
}
if(motionY == 0.0D && prevMotionY != 0.0D)
{
bylletMotionX = bounceSlowFactor * prevMotionX;
bylletMotionY = -bounceFactor * prevMotionY;
bylletMotionZ = bounceSlowFactor * prevMotionZ;
}
if(motionZ == 0.0D && prevMotionZ != 0.0D)
{
bylletMotionX = bounceSlowFactor * prevMotionX;
bylletMotionY = bounceSlowFactor * prevMotionY;
bylletMotionZ = -bounceFactor * prevMotionZ;
}
}
protected float getVelocity()
{
return speed;
}
protected float getGravityVelocity()
{
return gravity;
}
@Override
protected void onImpact(MovingObjectPosition mop)
{
if(mop.entityHit != null && !(mop.entityHit instanceof EntitySonnicShell))
{
mop.entityHit.hurtResistantTime = 0;
mop.entityHit.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) this.getThrower()), damage);
mop.entityHit.addVelocity(motionX * 0.1 * knockback, motionY * 0.1 * knockback + 0.1F, motionZ * 0.1 * knockback);
this.setDead();
}
if(!(mop.hitInfo instanceof Entity))
{
if(!(mop.hitInfo instanceof Block))
{
if(reload == 0)
{
reload += 40;
this.bylletMotionX = 0;
this.bylletMotionY = 0;
this.bylletMotionZ = 0;
}
}
else
{
this.setDead();
}
}
}
}