Search in sources :

Example 1 with EntityBroom

use of am2.entities.EntityBroom in project ArsMagica2 by Mithion.

the class ItemRune method spawnBroom.

public void spawnBroom(ItemStack stack, World world, EntityPlayer player) {
    if (!world.isRemote) {
        MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, true);
        if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
            TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (te instanceof IInventory) {
                EntityBroom broom = new EntityBroom(world);
                broom.setPosition(player.posX, player.posY, player.posZ);
                broom.setChestLocation(new AMVector3(mop.blockX, mop.blockY, mop.blockZ));
                world.spawnEntityInWorld(broom);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3)

Example 2 with EntityBroom

use of am2.entities.EntityBroom in project ArsMagica2 by Mithion.

the class ItemMagicBroom method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, true);
        if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
            TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (te instanceof IInventory) {
                EntityBroom broom = new EntityBroom(world);
                broom.setPosition(player.posX, player.posY, player.posZ);
                broom.setChestLocation(new AMVector3(mop.blockX, mop.blockY, mop.blockZ));
                world.spawnEntityInWorld(broom);
                stack.stackSize--;
                if (stack.stackSize == 0) {
                    player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityBroom(am2.entities.EntityBroom)

Aggregations

AMVector3 (am2.api.math.AMVector3)2 IInventory (net.minecraft.inventory.IInventory)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EntityBroom (am2.entities.EntityBroom)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1