Search in sources :

Example 6 with EntityPlayer

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);
}
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

EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)6 Entity (io.xol.chunkstories.api.entity.Entity)5 Vector3d (org.joml.Vector3d)5 Location (io.xol.chunkstories.api.Location)4 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)4 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)2 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)2 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)2 Vector3dc (org.joml.Vector3dc)2 EntityComponentRotation (io.xol.chunkstories.api.entity.components.EntityComponentRotation)1 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)1 EntityWithInventory (io.xol.chunkstories.api.entity.interfaces.EntityWithInventory)1 EventHandler (io.xol.chunkstories.api.events.EventHandler)1 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)1 Voxel (io.xol.chunkstories.api.voxel.Voxel)1 WorldCell (io.xol.chunkstories.api.world.World.WorldCell)1 WorldClient (io.xol.chunkstories.api.world.WorldClient)1 CellData (io.xol.chunkstories.api.world.cell.CellData)1 EditableCell (io.xol.chunkstories.api.world.cell.EditableCell)1 EntityGroundItem (io.xol.chunkstories.core.entity.EntityGroundItem)1