- 29
- 2
- 2
Создал я летящий предмет на основе EntityThrowable.
при правом клике и держа определенный item предмет вылетает.
При контакте можно сделать все кроме нанесения урона, он просто не зачитывается и анимация не воспроизводится.
при правом клике и держа определенный item предмет вылетает.
При контакте можно сделать все кроме нанесения урона, он просто не зачитывается и анимация не воспроизводится.
Java:
public class EntityShot extends EntityThrowable {
// Урон от попадания
int damage;
public EntityShot(World world) {
super(world);
}
// Наш кастомный конструктор для пули
// par1world - мир в котором будет пуля
// par2EntityLivingBase - тот, кто осуществил выстрел
// par3Velocity - скорость полёта пули
// par4Accuracy - разброс при стрельбе
// par5Damage - урон от попадания
public EntityShot(World par1world, EntityLivingBase par2EntityLivingBase, float par3Velocity, float par4Accuracy, int par5Damage) {
super(par1world, par2EntityLivingBase);
this.motionX = par2EntityLivingBase.getLookVec().x;
this.motionY = par2EntityLivingBase.getLookVec().y;
this.motionZ = par2EntityLivingBase.getLookVec().z;
this.damage = par5Damage;
// this.setVelocity(par3Velocity, par3Velocity, par3Velocity);
this.shoot(this.motionX, this.motionY, this.motionZ, par3Velocity, par4Accuracy);
}
@Override
protected void onImpact(RayTraceResult result) {
Console.println("onImpact " + result.typeOfHit);
Console.println(result.hitInfo + " " + result.entityHit + " " + result.hitVec);
if (result.typeOfHit == result.typeOfHit.ENTITY) {
if (result.entityHit instanceof EntityLivingBase) {
Console.println("not_null " + result.entityHit.height);
result.entityHit.attackEntityFrom(new DamageSource("damage_by_my_mod"), 5f);
result.entityHit.hurtResistantTime = 0;
}
} else if (result.typeOfHit == result.typeOfHit.BLOCK)
world.setBlockState(result.getBlockPos(), Blocks.AIR.getDefaultState());
this.setDead();
}
}
Java:
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
if (!duwnclick) {
// if (!worldIn.isRemote) {
worldIn.spawnEntity(new EntityShot(worldIn, playerIn, 3.0f, 0.001f, 1));
// }
duwnclick = !duwnclick;
} else {
duwnclick = !duwnclick;
}
return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
}
Java:
public class CommonProxy {
public void preInit(FMLPreInitializationEvent event) {
ModConfig.load(event);
RegistryItem.register();
EntityRegistry.registerModEntity(new ResourceLocation(MyMod.MODID, "mymod"), EntityShot.class, "shot", 0, MyMod.modInstance, 64, 1, true);
}
public void init(FMLInitializationEvent event) {
}
public void postInit(FMLPostInitializationEvent event) {
}
}