use of net.minecraft.inventory.IInventory 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;
}
use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.
the class FlickerOperatorItemTransport method DoOperation.
@Override
public boolean DoOperation(World worldObj, IFlickerController controller, boolean powered, Affinity[] flickers) {
if (worldObj.isRemote) {
return false;
}
//Gets the habitat running this operation
TileEntityFlickerHabitat habitat = null;
if (controller instanceof TileEntityFlickerHabitat) {
habitat = (TileEntityFlickerHabitat) controller;
} else {
//if the habitat couldn't be found, bail
return false;
}
int toMove = 0;
//if(powered){
for (int i = 0; i < 6; i++) {
if (flickers[i] == Affinity.ARCANE) {
toMove += 32;
}
}
//}
//ensure toMove is at least 1
toMove = Math.max(toMove, 1);
//initiate the arrays for any input crystals
ArrayList<ItemStack> itemsToTransfer = new ArrayList<ItemStack>();
ArrayList<AMVector3> removeFromInList = new ArrayList<AMVector3>();
boolean itemFound = false;
//if the in list position has exceeded the size of the list reset it
if (habitat.getInListPosition() >= habitat.getInListSize()) {
habitat.setInListPosition(0);
}
for (int inIterator = habitat.getInListPosition(); inIterator < habitat.getInListSize(); ++inIterator) {
//Gets the tile entity for the attached crystal marker at the specified location
AMVector3 vector = habitat.getInListAt(inIterator);
TileEntity te = null;
TileEntityCrystalMarker crystalMarkerTE = GetCrystalMarkerTileEntity(worldObj, (int) vector.x, (int) vector.y, (int) vector.z);
if (crystalMarkerTE == null) {
//crystal marker no longer exists, remove it from the list
removeFromInList.add(vector);
break;
}
te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
if (te != null && te instanceof IInventory) {
//if the crystal is attached to an inventory
itemFound = moveItem(worldObj, (IInventory) te, crystalMarkerTE, habitat, toMove);
if (itemFound) {
//if an item was found the break out of the current loop
habitat.setInListPosition(inIterator + 1);
break;
} else if (te instanceof TileEntityChest) {
//This is to handle the special case of double chests
TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
if (adjacent != null) {
itemFound = moveItem(worldObj, adjacent, crystalMarkerTE, habitat, toMove);
if (itemFound) {
habitat.setInListPosition(inIterator + 1);
}
}
}
}
}
if (itemFound == false) {
//if no items were found to move then reset the input list position
habitat.setInListPosition(0);
}
for (AMVector3 vector : removeFromInList) {
//remove the invalid in list positions from the maintained in list
habitat.removeInListAt(vector);
}
return itemFound;
}
use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.
the class FlickerOperatorFelledOak method getSaplingFromNearbyChest.
/**
* Gets a single sapling from an adjacent chest
*
* @return
*/
private ItemStack getSaplingFromNearbyChest(World worldObj, IFlickerController habitat) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
IInventory inv = getOffsetInventory(worldObj, habitat, dir);
if (inv == null)
continue;
int index = InventoryUtilities.getInventorySlotIndexFor(inv, new ItemStack(Blocks.sapling, 1, Short.MAX_VALUE));
if (index > -1) {
ItemStack stack = inv.getStackInSlot(index).copy();
stack.stackSize = 1;
return stack;
}
}
return null;
}
use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.
the class FlickerOperatorFelledOak method deductSaplingFromNearbyChest.
private void deductSaplingFromNearbyChest(World worldObj, IFlickerController habitat) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
IInventory inv = getOffsetInventory(worldObj, habitat, dir);
if (inv == null)
continue;
int index = InventoryUtilities.getInventorySlotIndexFor(inv, new ItemStack(Blocks.sapling, 1, Short.MAX_VALUE));
if (index > -1) {
InventoryUtilities.decrementStackQuantity(inv, index, 1);
return;
}
}
}
use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.
the class FlickerOperatorFelledOak method getOffsetInventory.
/**
* Gets an instance of the adjacent IInventory at direction offset. Returns null if not found or invalid type adjacent.
*/
private IInventory getOffsetInventory(World worldObj, IFlickerController habitat, ForgeDirection direction) {
TileEntity te = (TileEntity) habitat;
TileEntity adjacent = worldObj.getTileEntity(te.xCoord + direction.offsetX, te.yCoord + direction.offsetY, te.zCoord + direction.offsetZ);
if (adjacent != null && adjacent instanceof IInventory)
return (IInventory) adjacent;
return null;
}
Aggregations