После приземления предмета, спавнится итем несколько раз, в чем дело?
Итем ПКМ:
public ItemStack onItemRightClick(ItemStack stack, World world,
EntityPlayer player) {
if (!world.isRemote) {
EntityToolsThrowable tool = new EntityToolsThrowable(world, player,
this);
tool.setOption(this.getGravity(), this.getDamage());
world.spawnEntityInWorld(tool);
}
if (!player.capabilities.isCreativeMode) {
--stack.stackSize;
}
world.playSoundAtEntity(player, "random.bow", 0.5F,
0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
return stack;
}
EntityToolsThrowable:
public class EntityToolsThrowable extends EntityThrowable {
public float gravity;
public int damage;
public Item stack;
public static void registerEntityToolsThrowable(String name) {
EntityRegistry.registerGlobalEntityID(EntityToolsThrowable.class, name,
EntityRegistry.findGlobalUniqueEntityId());
EntityRegistry.registerModEntity(EntityToolsThrowable.class, name, 100,
Core.INSTANCE, 40, 100, true);
}
public void setOption(float gravity, int damage) {
this.setGravity(gravity);
this.setDamage(damage);
}
public EntityToolsThrowable(World world) {
super(world);
}
public EntityToolsThrowable(World world, EntityLivingBase entity, Item stack) {
super(world, entity);
this.setItem(stack);
}
public EntityToolsThrowable(World world, double par2, double par4,
double par6) {
super(world, par2, par4, par6);
}
@Override
protected float getGravityVelocity() {
return 0.09f;
}
protected void onImpact(MovingObjectPosition mop) {
if (mop.entityHit != null) {
mop.entityHit.attackEntityFrom(
DamageSource.causeThrownDamage(this, this.getThrower()),
this.getDamage());
} else if (mop.entityHit == null) {
if (!this.worldObj.isRemote) {
Item item = this.getItem();
ItemStack stack = new ItemStack(item, 1);
float itemDamage = stack.getItemDamage()
- (stack.getItemDamage() * 0.25f);
stack.setItemDamage((int) itemDamage);
EntityItem entity = new EntityItem(this.worldObj, this.posX,
this.posY, this.posZ, stack);
worldObj.spawnEntityInWorld(entity);
System.out.println("SPAWN");
}
}
// if (!this.worldObj.isRemote) {
// this.setDead();
// }
}
public float getGravity() {
return gravity;
}
public void setGravity(float gravity) {
this.gravity = gravity;
}
public int getDamage() {
return damage;
}
public void setDamage(int damage) {
this.damage = damage;
}
// @Override
// public void onCollideWithPlayer(EntityPlayer player) {
// if (inGround && !worldObj.isRemote) {
// player.inventory.addItemStackToInventory(stack);
// setDead();
// }
// }
public Item getItem() {
return stack;
}
public void setItem(Item stack) {
this.stack = stack;
}
}