use of io.xol.chunkstories.core.entity.EntityPlayer in project chunkstories-core by Hugobros3.
the class ItemsLogicListener method onDroppedItem.
@EventHandler
public void onDroppedItem(EventItemDroppedToWorld event) {
// Create an EntityGroundItem and add it to the event
Location throwLocation = event.getLocation();
Vector3d throwForce = new Vector3d(0.0);
// Throw it when dropping it from a player's inventory ?
System.out.println(event.getInventoryFrom());
if (event.getInventoryFrom() != null && event.getInventoryFrom().getHolder() != null && event.getInventoryFrom().getHolder() instanceof Entity) {
System.out.println("from som 1");
EntityWithInventory entity = ((EntityWithInventory) event.getInventoryFrom().getHolder());
Location pos = entity.getLocation();
if (entity instanceof EntityLiving) {
System.out.println("he l i v e s");
EntityLiving owner = (EntityLiving) entity;
throwLocation = new Location(pos.getWorld(), pos.x(), pos.y() + ((EntityPlayer) owner).eyePosition, pos.z());
throwForce = new Vector3d(((EntityPlayer) owner).getDirectionLookingAt()).mul(0.15 - Math2.clampd(((EntityPlayer) owner).getEntityRotationComponent().getVerticalRotation(), -45, 20) / 45f * 0.0f);
throwForce.add(((EntityPlayer) owner).getVelocityComponent().getVelocity());
}
}
EntityGroundItem thrownItem = (EntityGroundItem) core.getPluginExecutionContext().getContent().entities().getEntityDefinition("groundItem").create(throwLocation);
thrownItem.positionComponent.setPosition(throwLocation);
thrownItem.velocityComponent.setVelocity(throwForce);
thrownItem.setItemPile(event.getItemPile());
// EntityGroundItem entity = new EntityGroundItem(core.getPluginExecutionContext().getContent().entities().getEntityDefinitionByName("groundItem"), event.getLocation(), event.getItemPile());
event.setItemEntity(thrownItem);
}
Aggregations