Search in sources :

Example 6 with TileEntityFlickerHabitat

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

the class ServerGuiManager method getServerGuiElement.

@Override
public Object getServerGuiElement(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 ContainerEssenceRefiner(player.inventory, (TileEntityEssenceRefiner) te);
        case ArsMagicaGuiIdList.GUI_SPELL_BOOK:
            ItemStack bookStack = player.getCurrentEquippedItem();
            if (bookStack.getItem() == null || !(bookStack.getItem() instanceof ItemSpellBook)) {
                return null;
            }
            ItemSpellBook item = (ItemSpellBook) bookStack.getItem();
            return new ContainerSpellBook(player.inventory, player.getCurrentEquippedItem(), item.ConvertToInventory(bookStack));
        case ArsMagicaGuiIdList.GUI_CALEFACTOR:
            if (!(te instanceof TileEntityCalefactor)) {
                return null;
            }
            return new ContainerCalefactor(player, (TileEntityCalefactor) te);
        case ArsMagicaGuiIdList.GUI_KEYSTONE_LOCKABLE:
            if (!(te instanceof IKeystoneLockable)) {
                return null;
            }
            return new ContainerKeystoneLockable(player.inventory, (IKeystoneLockable) te);
        case ArsMagicaGuiIdList.GUI_ASTRAL_BARRIER:
            if (!(te instanceof TileEntityAstralBarrier)) {
                return null;
            }
            return new ContainerAstralBarrier(player.inventory, (TileEntityAstralBarrier) te);
        case ArsMagicaGuiIdList.GUI_SEER_STONE:
            if (!(te instanceof TileEntitySeerStone)) {
                return null;
            }
            return new ContainerSeerStone(player.inventory, (TileEntitySeerStone) te);
        case ArsMagicaGuiIdList.GUI_KEYSTONE_CHEST:
            if (!(te instanceof TileEntityKeystoneChest)) {
                return null;
            }
            return new ContainerKeystoneChest(player.inventory, (TileEntityKeystoneChest) te);
        case ArsMagicaGuiIdList.GUI_KEYSTONE:
            ItemStack keystoneStack = player.getCurrentEquippedItem();
            if (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 ContainerKeystone(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 ContainerEssenceBag(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 ContainerRuneBag(player.inventory, player.getCurrentEquippedItem(), runebag.ConvertToInventory(bagStack));
        case ArsMagicaGuiIdList.GUI_ARCANE_RECONSTRUCTOR:
            if (!(te instanceof TileEntityArcaneReconstructor)) {
                return null;
            }
            return new ContainerArcaneReconstructor(player.inventory, (TileEntityArcaneReconstructor) te);
        case ArsMagicaGuiIdList.GUI_INSCRIPTION_TABLE:
            if (!(te instanceof TileEntityInscriptionTable)) {
                return null;
            }
            return new ContainerInscriptionTable((TileEntityInscriptionTable) te, player.inventory);
        case ArsMagicaGuiIdList.GUI_SUMMONER:
            if (!(te instanceof TileEntitySummoner)) {
                return null;
            }
            return new ContainerSummoner(player.inventory, (TileEntitySummoner) te);
        case ArsMagicaGuiIdList.GUI_MAGICIANS_WORKBENCH:
            if (!(te instanceof TileEntityMagiciansWorkbench)) {
                return null;
            }
            return new ContainerMagiciansWorkbench(player.inventory, (TileEntityMagiciansWorkbench) te);
        case ArsMagicaGuiIdList.GUI_RIFT:
            return new ContainerRiftStorage(player.inventory, RiftStorage.For(player));
        case ArsMagicaGuiIdList.GUI_SPELL_CUSTOMIZATION:
            return new ContainerSpellCustomization(player);
        case ArsMagicaGuiIdList.GUI_CRYSTAL_MARKER:
            if (!(te instanceof TileEntityCrystalMarker)) {
                return null;
            }
            return new ContainerCrystalMarker(player, (TileEntityCrystalMarker) te);
        case ArsMagicaGuiIdList.GUI_OBELISK:
            if (!(te instanceof TileEntityObelisk)) {
                return null;
            }
            return new ContainerObelisk((TileEntityObelisk) te, player);
        case ArsMagicaGuiIdList.GUI_FLICKER_HABITAT:
            if (!(te instanceof TileEntityFlickerHabitat)) {
                return null;
            }
            return new ContainerFlickerHabitat(player, (TileEntityFlickerHabitat) te);
        case ArsMagicaGuiIdList.GUI_ARMOR_INFUSION:
            if (!(te instanceof TileEntityArmorImbuer)) {
                return null;
            }
            return new ContainerArmorInfuser(player, (TileEntityArmorImbuer) te);
        case ArsMagicaGuiIdList.GUI_ARCANE_DECONSTRUCTOR:
            if (!(te instanceof TileEntityArcaneDeconstructor)) {
                return null;
            }
            return new ContainerArcaneDeconstructor(player.inventory, (TileEntityArcaneDeconstructor) te);
        case ArsMagicaGuiIdList.GUI_INERT_SPAWNER:
            if (!(te instanceof TileEntityInertSpawner)) {
                return null;
            }
            return new ContainerInertSpawner(player, (TileEntityInertSpawner) te);
        case ArsMagicaGuiIdList.GUI_SPELL_SEALED_DOOR:
            if (!(te instanceof TileEntitySpellSealedDoor)) {
                return null;
            }
            return new ContainerSpellSealedDoor(player.inventory, (TileEntitySpellSealedDoor) te);
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IKeystoneLockable(am2.api.blocks.IKeystoneLockable) ItemStack(net.minecraft.item.ItemStack)

Example 7 with TileEntityFlickerHabitat

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

the class FlickerOperatorItemTransport method FindOutput.

/**
	 * Will try to find a place to move the item stack
	 *
	 * @param stack The item stack to move
	 * @return Returns true if the item can be moved, returns false otherwise
	 */
private boolean FindOutput(World worldObj, TileEntityFlickerHabitat attuner, ItemStack stack, IInventory source) {
    HashMap<Integer, ArrayList<AMVector3>> removeFromOutList = new HashMap<Integer, ArrayList<AMVector3>>();
    boolean itemMoved = false;
    for (int priority = 0; priority <= TileEntityFlickerHabitat.PRIORITY_FINAL; ++priority) {
        if (attuner.getOutListPosition(priority) >= attuner.getOutListSize(priority)) {
            //if the out list position has gone outside the list size reset it to 0
            attuner.setOutListPosition(priority, 0);
        }
        int start = attuner.getOutListPosition(priority);
        int pos = start;
        boolean fullLoop = false;
        while (!fullLoop) {
            //get the crystal marker tile entity for the specified position
            AMVector3 vector = attuner.getOutListAt(priority, pos);
            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
                if (!removeFromOutList.containsKey(priority))
                    removeFromOutList.put(priority, new ArrayList<AMVector3>());
                removeFromOutList.get(priority).add(vector);
                break;
            }
            te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
            int markerType = worldObj.getBlockMetadata((int) vector.x, (int) vector.y, (int) vector.z);
            if (te != null && te instanceof IInventory) {
                IInventory inventory = (IInventory) te;
                itemMoved = outputItem(markerType, new IInventory[] { inventory }, stack, crystalMarkerTE, new IInventory[] { source });
                if (itemMoved) {
                    attuner.setOutListPosition(priority, pos + 1);
                }
            }
            if (!itemMoved && te instanceof TileEntityChest) {
                //This handles the special case of double chests
                TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
                if (adjacent != null) {
                    IInventory inventory = adjacent;
                    itemMoved = outputItem(markerType, new IInventory[] { inventory, (IInventory) te }, stack, crystalMarkerTE, new IInventory[] { source });
                    if (itemMoved) {
                        attuner.setOutListPosition(priority, pos + 1);
                    }
                }
            }
            if (itemMoved)
                break;
            pos++;
            pos %= attuner.getOutListSize(priority);
            if (pos == start)
                fullLoop = true;
        }
        for (int i : removeFromOutList.keySet()) {
            for (AMVector3 vector : removeFromOutList.get(i)) {
                attuner.removeOutListAt(i, vector);
            }
        }
        if (!itemMoved) {
            attuner.setOutListPosition(priority, 0);
        } else {
            break;
        }
    }
    return itemMoved;
}
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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 8 with TileEntityFlickerHabitat

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

the class BlockFlickerHabitat method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, Block oldBlockID, int oldMetadata) {
    TileEntityFlickerHabitat habitat = (TileEntityFlickerHabitat) world.getTileEntity(x, y, z);
    //if there is no habitat at the location break out
    if (habitat == null)
        return;
    //if the habitat has a flicker throw it on the ground
    if (habitat.hasFlicker()) {
        ItemStack stack = habitat.getStackInSlot(0);
        float offsetX = world.rand.nextFloat() * 0.8F + 0.1F;
        float offsetY = world.rand.nextFloat() * 0.8F + 0.1F;
        float offsetZ = world.rand.nextFloat() * 0.8F + 0.1F;
        float force = 0.05F;
        EntityItem entityItem = new EntityItem(world, x + offsetX, y + offsetY, z + offsetZ, stack);
        entityItem.motionX = (float) world.rand.nextGaussian() * force;
        entityItem.motionY = (float) world.rand.nextGaussian() * force + 0.2F;
        entityItem.motionZ = (float) world.rand.nextGaussian() * force;
        world.spawnEntityInWorld(entityItem);
    }
    if (!habitat.isUpgrade()) {
        for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
            TileEntity te = world.getTileEntity(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ);
            if (te != null && te instanceof TileEntityFlickerHabitat) {
                TileEntityFlickerHabitat upgHab = (TileEntityFlickerHabitat) te;
                if (upgHab.isUpgrade()) {
                    world.func_147480_a(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ, true);
                    world.setTileEntity(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ, null);
                }
            }
        }
    }
    super.breakBlock(world, x, y, z, oldBlockID, oldMetadata);
    return;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 9 with TileEntityFlickerHabitat

use of am2.blocks.tileentities.TileEntityFlickerHabitat 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)

Example 10 with TileEntityFlickerHabitat

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

the class BlockFlickerHabitat method setBlockMode.

protected void setBlockMode(World world, int x, int y, int z) {
    if (world.isRemote)
        return;
    TileEntity ent = world.getTileEntity(x, y, z);
    int habCount = 0;
    if (ent instanceof TileEntityFlickerHabitat) {
        TileEntityFlickerHabitat hab = (TileEntityFlickerHabitat) ent;
        for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
            Block block = world.getBlock(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ);
            TileEntity te = world.getTileEntity(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ);
            if (block == BlocksCommonProxy.elementalAttuner && te != null && te instanceof TileEntityFlickerHabitat) {
                TileEntityFlickerHabitat foundHab = (TileEntityFlickerHabitat) te;
                if (foundHab.isUpgrade() == false) {
                    habCount++;
                    if (habCount == 1) {
                        hab.setUpgrade(true, direction);
                    } else {
                        world.func_147480_a(x, y, z, true);
                    }
                } else {
                    world.func_147480_a(x, y, z, true);
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block)

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