Search in sources :

Example 1 with IKeystoneLockable

use of am2.api.blocks.IKeystoneLockable in project ArsMagica2 by Mithion.

the class BlockSpellSealedDoor method onBlockHarvested.

@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {
    if (world.isRemote)
        return;
    if (world.getBlock(x, y - 1, z) == BlocksCommonProxy.keystoneDoor)
        y--;
    IKeystoneLockable lockable = (IKeystoneLockable) world.getTileEntity(x, y, z);
    if (lockable == null)
        return;
    if (!KeystoneUtilities.instance.canPlayerAccess(lockable, player, KeystoneAccessType.BREAK))
        return;
    super.onBlockHarvested(world, x, y, z, meta, player);
}
Also used : IKeystoneLockable(am2.api.blocks.IKeystoneLockable)

Example 2 with IKeystoneLockable

use of am2.api.blocks.IKeystoneLockable 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 3 with IKeystoneLockable

use of am2.api.blocks.IKeystoneLockable in project ArsMagica2 by Mithion.

the class BlockAstralBarrier method onBlockActivated.

@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
    TileEntity te = par1World.getTileEntity(par2, par3, par4);
    TileEntityAstralBarrier abte = null;
    if (te != null && te instanceof TileEntityAstralBarrier) {
        abte = (TileEntityAstralBarrier) te;
    } else {
        return true;
    }
    if (HandleSpecialItems(par1World, par5EntityPlayer, par2, par3, par4)) {
        return true;
    }
    if (!par1World.isRemote)
        if (KeystoneUtilities.HandleKeystoneRecovery(par5EntityPlayer, ((IKeystoneLockable) par1World.getTileEntity(par2, par3, par4))))
            return true;
    if (KeystoneUtilities.instance.canPlayerAccess((IKeystoneLockable) par1World.getTileEntity(par2, par3, par4), par5EntityPlayer, KeystoneAccessType.USE)) {
        if (par5EntityPlayer.isSneaking()) {
            if (par1World.isRemote) {
                abte.ToggleAuraDisplay();
                par5EntityPlayer.addChatMessage(new ChatComponentText("Barrier Aura Toggled"));
            }
        } else {
            if (!par1World.isRemote) {
                super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
                FMLNetworkHandler.openGui(par5EntityPlayer, AMCore.instance, ArsMagicaGuiIdList.GUI_ASTRAL_BARRIER, par1World, par2, par3, par4);
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityAstralBarrier(am2.blocks.tileentities.TileEntityAstralBarrier) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 4 with IKeystoneLockable

use of am2.api.blocks.IKeystoneLockable in project ArsMagica2 by Mithion.

the class KeystoneUtilities method canPlayerAccess.

@Override
public boolean canPlayerAccess(IKeystoneLockable inventory, EntityPlayer player, KeystoneAccessType accessMode) {
    ItemStack[] runes = inventory.getRunesInKey();
    long key = getKeyFromRunes(runes);
    if (// no key combo set?  No lock!  Access granted!
    key == 0)
        return true;
    if (inventory.keystoneMustBeHeld()) {
        if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == ItemsCommonProxy.keystone) {
            return ((ItemKeystone) player.getCurrentEquippedItem().getItem()).getKey(player.getCurrentEquippedItem()) == key;
        }
    } else if (inventory.keystoneMustBeInActionBar()) {
        for (int i = 0; i < 9; ++i) {
            ItemStack stack = player.inventory.getStackInSlot(i);
            if (stack == null || stack.getItem() != ItemsCommonProxy.keystone)
                continue;
            if (((ItemKeystone) stack.getItem()).getKey(stack) == key) {
                return true;
            }
        }
    } else {
        for (int i = 0; i < player.inventory.mainInventory.length; ++i) {
            ItemStack stack = player.inventory.getStackInSlot(i);
            if (stack == null || stack.getItem() != ItemsCommonProxy.keystone)
                continue;
            if (((ItemKeystone) stack.getItem()).getKey(stack) == key) {
                return true;
            }
        }
    }
    if (accessMode == KeystoneAccessType.USE) {
        player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.wrongKeystoneUse")));
    } else if (accessMode == KeystoneAccessType.BREAK) {
        player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.wrongKeystoneBreak")));
    }
    return false;
}
Also used : ItemKeystone(am2.items.ItemKeystone) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 5 with IKeystoneLockable

use of am2.api.blocks.IKeystoneLockable 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)

Aggregations

IKeystoneLockable (am2.api.blocks.IKeystoneLockable)6 TileEntity (net.minecraft.tileentity.TileEntity)6 ItemStack (net.minecraft.item.ItemStack)4 ChatComponentText (net.minecraft.util.ChatComponentText)2 AMVector3 (am2.api.math.AMVector3)1 TileEntityAstralBarrier (am2.blocks.tileentities.TileEntityAstralBarrier)1 TileEntityMagiciansWorkbench (am2.blocks.tileentities.TileEntityMagiciansWorkbench)1 ItemKeystone (am2.items.ItemKeystone)1 DummyEntityPlayer (am2.utility.DummyEntityPlayer)1 Block (net.minecraft.block.Block)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 BreakEvent (net.minecraftforge.event.world.BlockEvent.BreakEvent)1