* Drops the item specified into the direction the player looks, with slight randomness
*
* @param item to drop
*/
public void dropItem(ItemStack item) {
final Transform dropFrom;
EntityHead head = getHead();
if (head != null) {
dropFrom = head.getHeadTransform();
} else {
dropFrom = getOwner().getPhysics().getTransform();
}
// Some constants
final double impulseForce = 0.3;
final float maxXZForce = 0.02f;
final float maxYForce = 0.1f;
// Create a velocity vector using the transform, apply (random) force
Vector3f impulse = dropFrom.getRotation().getDirection().mul(impulseForce);
// Random rotational offset to avoid dropping at the same position
Random rand = GenericMath.getRandom();
float xzLength = maxXZForce * rand.nextFloat();
float yLength = maxYForce * (rand.nextFloat() - rand.nextFloat());
impulse = impulse.add(Vector2f.createRandomDirection(rand).mul(xzLength).toVector3(yLength));
// Slightly dropping upwards
impulse = impulse.add(0.0, 0.1, 0.0);
// Conversion factor, some sort of unit problem
//TODO: This needs an actual value and this value might change when gravity changes!
impulse = impulse.mul(100);
// Finally drop using a 4 second pickup delay
Item spawnedItem = Item.drop(dropFrom.getPosition(), item, impulse);
spawnedItem.setUncollectableDelay(4000);
}