Search in sources :

Example 11 with EntityLiving

use of io.xol.chunkstories.api.entity.EntityLiving 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);
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) EntityGroundItem(io.xol.chunkstories.core.entity.EntityGroundItem) Vector3d(org.joml.Vector3d) EntityWithInventory(io.xol.chunkstories.api.entity.interfaces.EntityWithInventory) EntityPlayer(io.xol.chunkstories.core.entity.EntityPlayer) Location(io.xol.chunkstories.api.Location) EventHandler(io.xol.chunkstories.api.events.EventHandler)

Aggregations

EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)11 Entity (io.xol.chunkstories.api.entity.Entity)7 Location (io.xol.chunkstories.api.Location)6 Vector3d (org.joml.Vector3d)5 EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)4 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)3 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)3 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)3 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)3 CellData (io.xol.chunkstories.api.world.cell.CellData)3 Vector3dc (org.joml.Vector3dc)3 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)2 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)2 Vector4f (org.joml.Vector4f)2 EntityComponentRotation (io.xol.chunkstories.api.entity.components.EntityComponentRotation)1 EntityNameable (io.xol.chunkstories.api.entity.interfaces.EntityNameable)1 EntityWithInventory (io.xol.chunkstories.api.entity.interfaces.EntityWithInventory)1 EntityWithSelectedItem (io.xol.chunkstories.api.entity.interfaces.EntityWithSelectedItem)1 EventHandler (io.xol.chunkstories.api.events.EventHandler)1 PlayerChatEvent (io.xol.chunkstories.api.events.player.PlayerChatEvent)1