Search in sources :

Example 1 with TileEntityCrystalMarker

use of am2.blocks.tileentities.TileEntityCrystalMarker 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 2 with TileEntityCrystalMarker

use of am2.blocks.tileentities.TileEntityCrystalMarker 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 3 with TileEntityCrystalMarker

use of am2.blocks.tileentities.TileEntityCrystalMarker 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 4 with TileEntityCrystalMarker

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

the class AMClientEventHandler method renderPriorityText.

private void renderPriorityText(DrawBlockHighlightEvent event, TileEntityCrystalMarker te) {
    int meta = event.player.worldObj.getBlockMetadata(event.target.blockX, event.target.blockY, event.target.blockZ);
    if (// no priority for these blocks
    meta == BlockCrystalMarker.META_IN)
        return;
    Block block = event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ);
    float yOff = 0.5f;
    String priString = String.format(StatCollector.translateToLocal("am2.tooltip.priority"), String.format("%d", te.getPriority()));
    AMVector3 boundsOffset = new AMVector3(block.getBlockBoundsMinX() + (block.getBlockBoundsMaxX() - block.getBlockBoundsMinX()) / 2, block.getBlockBoundsMinY() + (block.getBlockBoundsMaxY() - block.getBlockBoundsMinY()) / 2, block.getBlockBoundsMinZ() + (block.getBlockBoundsMaxZ() - block.getBlockBoundsMinZ()) / 2);
    AMVector3 offset = new AMVector3(event.target.blockX + boundsOffset.x, event.target.blockY + boundsOffset.y, event.target.blockZ + boundsOffset.z).sub(new AMVector3((event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks), (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) + event.player.getEyeHeight(), (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks)));
    offset = offset.normalize();
    AMVector3 drawPos = new AMVector3(event.target.blockX + block.getBlockBoundsMaxX() - offset.x - (event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks), event.target.blockY + yOff - (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) + block.getBlockBoundsMaxY() * 0.8f, event.target.blockZ + block.getBlockBoundsMaxZ() - offset.z - (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks));
    if (event.target.blockY > event.player.posY - 0.5) {
        drawPos.y = (float) (event.target.blockY - yOff - (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) - block.getBlockBoundsMaxY() * 0.2f);
    }
    GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
    RenderUtilities.drawTextInWorldAtOffset(priString, drawPos.x, drawPos.y, drawPos.z, 0xFFFFFF);
    GL11.glPopAttrib();
}
Also used : AMVector3(am2.api.math.AMVector3) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 5 with TileEntityCrystalMarker

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

the class BlockCrystalMarker method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, Block oldBlock, int oldMeta) {
    TileEntityCrystalMarker crystalMarkerTE = GetTileEntity(world, x, y, z);
    TileEntityFlickerHabitat elementalAttunerTE = null;
    if (crystalMarkerTE != null) {
        AMVector3 elementalAttunerVector = crystalMarkerTE.getElementalAttuner();
        if (elementalAttunerVector != null) {
            elementalAttunerTE = GetElementalAttunerTileEntity(world, (int) elementalAttunerVector.x, (int) elementalAttunerVector.y, (int) elementalAttunerVector.z);
            if (elementalAttunerTE != null) {
                int operandType = world.getBlockMetadata(x, y, z);
                if (operandType == META_IN) {
                    elementalAttunerTE.removeInMarkerLocation(x, y, z);
                } else if (isOutputMarker(operandType)) {
                    elementalAttunerTE.removeOutMarkerLocation(x, y, z);
                }
            }
        }
    }
    super.breakBlock(world, x, y, z, oldBlock, oldMeta);
}
Also used : AMVector3(am2.api.math.AMVector3) TileEntityCrystalMarker(am2.blocks.tileentities.TileEntityCrystalMarker) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat)

Aggregations

TileEntityCrystalMarker (am2.blocks.tileentities.TileEntityCrystalMarker)8 TileEntity (net.minecraft.tileentity.TileEntity)8 AMVector3 (am2.api.math.AMVector3)5 ItemStack (net.minecraft.item.ItemStack)5 Block (net.minecraft.block.Block)3 IKeystoneLockable (am2.api.blocks.IKeystoneLockable)2 TileEntityFlickerHabitat (am2.blocks.tileentities.TileEntityFlickerHabitat)2 ArrayList (java.util.ArrayList)2 IInventory (net.minecraft.inventory.IInventory)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 IPowerNode (am2.api.power.IPowerNode)1 TileEntityParticleEmitter (am2.blocks.tileentities.TileEntityParticleEmitter)1 GetFirstStackStartingFromSlotResult (am2.utility.GetFirstStackStartingFromSlotResult)1 HashMap (java.util.HashMap)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemBlock (net.minecraft.item.ItemBlock)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagString (net.minecraft.nbt.NBTTagString)1 ChatComponentText (net.minecraft.util.ChatComponentText)1