Search in sources :

Example 1 with TileEntityFlickerHabitat

use of am2.blocks.tileentities.TileEntityFlickerHabitat in project ArsMagica2 by Mithion.

the class ItemCrystalWrench method storePairLocation.

private void storePairLocation(World world, TileEntity te, ItemStack stack, EntityPlayer player, double hitX, double hitY, double hitZ) {
    AMVector3 destination = new AMVector3(te);
    if (!world.isRemote) {
        if (te instanceof TileEntityFlickerHabitat) {
            NBTTagCompound habLoc = new NBTTagCompound();
            destination.writeToNBT(habLoc);
            stack.stackTagCompound.setTag(HAB_PAIRLOC, habLoc);
        } else {
            NBTTagCompound pairLoc = new NBTTagCompound();
            destination.writeToNBT(pairLoc);
            stack.stackTagCompound.setTag(KEY_PAIRLOC, pairLoc);
        }
        if (player.isSneaking()) {
            stack.stackTagCompound.setBoolean(KEEP_BINDING, true);
        }
    } else {
        spawnLinkParticles(world, hitX, hitY, hitZ);
    }
}
Also used : AMVector3(am2.api.math.AMVector3) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with TileEntityFlickerHabitat

use of am2.blocks.tileentities.TileEntityFlickerHabitat in project ArsMagica2 by Mithion.

the class FlickerOperatorItemTransport method moveItem.

private boolean moveItem(World worldObj, IInventory inventory, TileEntityCrystalMarker crystalMarkerTE, TileEntityFlickerHabitat habitat, int toMove) {
    boolean itemFound = false;
    ItemStack orgStack = null;
    int currentSlot = 0;
    GetFirstStackStartingFromSlotResult result = InventoryUtilities.getFirstStackStartingFromSlot(inventory, orgStack, currentSlot, crystalMarkerTE.getFacing());
    orgStack = result.stack;
    currentSlot = result.slot;
    while (orgStack != null) {
        if (orgStack != null && InputCanMove(crystalMarkerTE, orgStack, inventory)) {
            ItemStack stackCopy = orgStack.copy();
            int amountToMove = Math.min(toMove, stackCopy.stackSize);
            ItemStack mergeStack = stackCopy.splitStack(amountToMove);
            if (FindOutput(worldObj, habitat, mergeStack, inventory)) {
                //if a valid item was found in input, and a valid output for it was found remove the item from the source
                InventoryUtilities.deductFromInventory(inventory, orgStack, amountToMove - mergeStack.stackSize);
                itemFound = true;
                break;
            } else {
                currentSlot++;
            }
        } else {
            currentSlot++;
        }
        result = InventoryUtilities.getFirstStackStartingFromSlot(inventory, orgStack, currentSlot, crystalMarkerTE.getFacing());
        orgStack = result.stack;
        currentSlot = result.slot;
        if (currentSlot == -1) {
            orgStack = null;
        }
    }
    return itemFound;
}
Also used : GetFirstStackStartingFromSlotResult(am2.utility.GetFirstStackStartingFromSlotResult) ItemStack(net.minecraft.item.ItemStack)

Example 3 with TileEntityFlickerHabitat

use of am2.blocks.tileentities.TileEntityFlickerHabitat 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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityChest(net.minecraft.tileentity.TileEntityChest) TileEntityCrystalMarker(am2.blocks.tileentities.TileEntityCrystalMarker) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 4 with TileEntityFlickerHabitat

use of am2.blocks.tileentities.TileEntityFlickerHabitat in project ArsMagica2 by Mithion.

the class ClientGuiManager method getClientGuiElement.

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileEntity te = world.getTileEntity(x, y, z);
    if (te == null && ID != ArsMagicaGuiIdList.GUI_SPELL_BOOK && ID != ArsMagicaGuiIdList.GUI_KEYSTONE && ID != ArsMagicaGuiIdList.GUI_ESSENCE_BAG && ID != ArsMagicaGuiIdList.GUI_RUNE_BAG && ID != ArsMagicaGuiIdList.GUI_RIFT && ID != ArsMagicaGuiIdList.GUI_SPELL_CUSTOMIZATION) {
        return null;
    }
    switch(ID) {
        case ArsMagicaGuiIdList.GUI_ESSENCE_REFINER:
            if (!(te instanceof TileEntityEssenceRefiner)) {
                return null;
            }
            return new GuiEssenceRefiner(player.inventory, (TileEntityEssenceRefiner) te);
        case ArsMagicaGuiIdList.GUI_SPELL_BOOK:
            ItemStack bookStack = player.getCurrentEquippedItem();
            if (bookStack == null || bookStack.getItem() == null || !(bookStack.getItem() instanceof ItemSpellBook)) {
                return null;
            }
            ItemSpellBook item = (ItemSpellBook) bookStack.getItem();
            return new GuiSpellBook(player.inventory, player.getCurrentEquippedItem(), item.ConvertToInventory(bookStack));
        case ArsMagicaGuiIdList.GUI_CALEFACTOR:
            if (!(te instanceof TileEntityCalefactor)) {
                return null;
            }
            return new GuiCalefactor(player, (TileEntityCalefactor) te);
        case ArsMagicaGuiIdList.GUI_KEYSTONE_LOCKABLE:
            if (!(te instanceof IKeystoneLockable)) {
                return null;
            }
            return new GuiKeystoneLockable(player.inventory, (IKeystoneLockable) te);
        case ArsMagicaGuiIdList.GUI_ASTRAL_BARRIER:
            if (!(te instanceof TileEntityAstralBarrier)) {
                return null;
            }
            return new GuiAstralBarrier(player.inventory, (TileEntityAstralBarrier) te);
        case ArsMagicaGuiIdList.GUI_SEER_STONE:
            if (!(te instanceof TileEntitySeerStone)) {
                return null;
            }
            return new GuiSeerStone(player.inventory, (TileEntitySeerStone) te);
        case ArsMagicaGuiIdList.GUI_KEYSTONE_CHEST:
            if (!(te instanceof TileEntityKeystoneChest)) {
                return null;
            }
            return new GuiKeystoneChest(player.inventory, (TileEntityKeystoneChest) te);
        case ArsMagicaGuiIdList.GUI_KEYSTONE:
            ItemStack keystoneStack = player.getCurrentEquippedItem();
            if (keystoneStack == null || keystoneStack.getItem() == null || !(keystoneStack.getItem() instanceof ItemKeystone)) {
                return null;
            }
            ItemKeystone keystone = (ItemKeystone) keystoneStack.getItem();
            int runeBagSlot = InventoryUtilities.getInventorySlotIndexFor(player.inventory, ItemsCommonProxy.runeBag);
            ItemStack runeBag = null;
            if (runeBagSlot > -1)
                runeBag = player.inventory.getStackInSlot(runeBagSlot);
            return new GuiKeystone(player.inventory, player.getCurrentEquippedItem(), runeBag, keystone.ConvertToInventory(keystoneStack), runeBag == null ? null : ItemsCommonProxy.runeBag.ConvertToInventory(runeBag), runeBagSlot);
        case ArsMagicaGuiIdList.GUI_ESSENCE_BAG:
            ItemStack bagStack = player.getCurrentEquippedItem();
            if (bagStack.getItem() == null || !(bagStack.getItem() instanceof ItemEssenceBag)) {
                return null;
            }
            ItemEssenceBag bag = (ItemEssenceBag) bagStack.getItem();
            return new GuiEssenceBag(player.inventory, player.getCurrentEquippedItem(), bag.ConvertToInventory(bagStack));
        case ArsMagicaGuiIdList.GUI_RUNE_BAG:
            bagStack = player.getCurrentEquippedItem();
            if (bagStack.getItem() == null || !(bagStack.getItem() instanceof ItemRuneBag)) {
                return null;
            }
            ItemRuneBag runebag = (ItemRuneBag) bagStack.getItem();
            return new GuiRuneBag(player.inventory, player.getCurrentEquippedItem(), runebag.ConvertToInventory(bagStack));
        case ArsMagicaGuiIdList.GUI_ARCANE_RECONSTRUCTOR:
            if (!(te instanceof TileEntityArcaneReconstructor)) {
                return null;
            }
            return new GuiArcaneReconstructor(player.inventory, (TileEntityArcaneReconstructor) te);
        case ArsMagicaGuiIdList.GUI_SUMMONER:
            if (!(te instanceof TileEntitySummoner)) {
                return null;
            }
            return new GuiSummoner(player.inventory, (TileEntitySummoner) te);
        case ArsMagicaGuiIdList.GUI_INSCRIPTION_TABLE:
            if (!(te instanceof TileEntityInscriptionTable)) {
                return null;
            }
            return new GuiInscriptionTable(player.inventory, (TileEntityInscriptionTable) te);
        case ArsMagicaGuiIdList.GUI_MAGICIANS_WORKBENCH:
            if (!(te instanceof TileEntityMagiciansWorkbench)) {
                return null;
            }
            return new GuiMagiciansWorkbench(player.inventory, (TileEntityMagiciansWorkbench) te);
        case ArsMagicaGuiIdList.GUI_RIFT:
            return new GuiRiftStorage(player.inventory, RiftStorage.For(player));
        case ArsMagicaGuiIdList.GUI_SPELL_CUSTOMIZATION:
            return new GuiSpellCustomization(player);
        case ArsMagicaGuiIdList.GUI_CRYSTAL_MARKER:
            if (!(te instanceof TileEntityCrystalMarker)) {
                return null;
            }
            return new GuiCrystalMarker(player, (TileEntityCrystalMarker) te);
        case ArsMagicaGuiIdList.GUI_OBELISK:
            if (!(te instanceof TileEntityObelisk)) {
                return null;
            }
            return new GuiObelisk((TileEntityObelisk) te, player);
        case ArsMagicaGuiIdList.GUI_FLICKER_HABITAT:
            if (!(te instanceof TileEntityFlickerHabitat)) {
                return null;
            }
            return new GuiFlickerHabitat(player, (TileEntityFlickerHabitat) te);
        case ArsMagicaGuiIdList.GUI_ARMOR_INFUSION:
            if (!(te instanceof TileEntityArmorImbuer)) {
                return null;
            }
            return new GuiArmorImbuer(player, (TileEntityArmorImbuer) te);
        case ArsMagicaGuiIdList.GUI_ARCANE_DECONSTRUCTOR:
            if (!(te instanceof TileEntityArcaneDeconstructor)) {
                return null;
            }
            return new GuiArcaneDeconstructor(player.inventory, (TileEntityArcaneDeconstructor) te);
        case ArsMagicaGuiIdList.GUI_INERT_SPAWNER:
            if (!(te instanceof TileEntityInertSpawner)) {
                return null;
            }
            return new GuiInertSpawner(player, (TileEntityInertSpawner) te);
        case ArsMagicaGuiIdList.GUI_SPELL_SEALED_DOOR:
            if (!(te instanceof TileEntitySpellSealedDoor)) {
                return null;
            }
            return new GuiSpellSealedDoor(player.inventory, (TileEntitySpellSealedDoor) te);
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IKeystoneLockable(am2.api.blocks.IKeystoneLockable) ItemStack(net.minecraft.item.ItemStack)

Example 5 with TileEntityFlickerHabitat

use of am2.blocks.tileentities.TileEntityFlickerHabitat in project ArsMagica2 by Mithion.

the class TileEntityCrystalMarker method linkToHabitat.

public void linkToHabitat(AMVector3 habLocation, EntityPlayer player) {
    TileEntity te = worldObj.getTileEntity((int) habLocation.x, (int) habLocation.y, (int) habLocation.z);
    if (te instanceof TileEntityFlickerHabitat) {
        AMVector3 myLocation = new AMVector3(this.xCoord, this.yCoord, this.zCoord);
        boolean setElementalAttuner = false;
        if (myLocation.distanceSqTo(habLocation) <= SEARCH_RADIUS) {
            if (BlockCrystalMarker.isInputMarker(worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord))) {
                ((TileEntityFlickerHabitat) te).AddMarkerLocationIn(myLocation);
                setElementalAttuner = true;
            }
            if (BlockCrystalMarker.isOutputMarker(worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord))) {
                ((TileEntityFlickerHabitat) te).AddMarkerLocationOut(myLocation);
                setElementalAttuner = true;
            }
            if (setElementalAttuner)
                this.setElementalAttuner(habLocation);
        } else {
            player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.habitatToFar")));
        }
    }
}
Also used : S35PacketUpdateTileEntity(net.minecraft.network.play.server.S35PacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)7 AMVector3 (am2.api.math.AMVector3)5 TileEntityFlickerHabitat (am2.blocks.tileentities.TileEntityFlickerHabitat)5 ItemStack (net.minecraft.item.ItemStack)5 TileEntityCrystalMarker (am2.blocks.tileentities.TileEntityCrystalMarker)3 IKeystoneLockable (am2.api.blocks.IKeystoneLockable)2 ArrayList (java.util.ArrayList)2 IInventory (net.minecraft.inventory.IInventory)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 GetFirstStackStartingFromSlotResult (am2.utility.GetFirstStackStartingFromSlotResult)1 HashMap (java.util.HashMap)1 Block (net.minecraft.block.Block)1 EntityItem (net.minecraft.entity.item.EntityItem)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 S35PacketUpdateTileEntity (net.minecraft.network.play.server.S35PacketUpdateTileEntity)1 ChatComponentText (net.minecraft.util.ChatComponentText)1