Search in sources :

Example 1 with IGuiTile

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile in project Immersive-Tech by FerroO2000.

the class BlockITTileProvider method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = player.getHeldItem(hand);
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IConfigurableSides && Utils.isHammer(heldItem) && !world.isRemote) {
        int iSide = player.isSneaking() ? side.getOpposite().ordinal() : side.ordinal();
        if (((IConfigurableSides) tile).toggleSide(iSide, player))
            return true;
    }
    if (tile instanceof IDirectionalTile && Utils.isHammer(heldItem) && ((IDirectionalTile) tile).canHammerRotate(side, hitX, hitY, hitZ, player) && !world.isRemote) {
        EnumFacing f = ((IDirectionalTile) tile).getFacing();
        int limit = ((IDirectionalTile) tile).getFacingLimitation();
        if (limit == 0)
            f = EnumFacing.VALUES[(f.ordinal() + 1) % EnumFacing.VALUES.length];
        else if (limit == 1)
            f = player.isSneaking() ? f.rotateAround(side.getAxis()).getOpposite() : f.rotateAround(side.getAxis());
        else if (limit == 2 || limit == 5)
            f = player.isSneaking() ? f.rotateYCCW() : f.rotateY();
        ((IDirectionalTile) tile).setFacing(f);
        tile.markDirty();
        world.notifyBlockUpdate(pos, state, state, 3);
        world.addBlockEvent(tile.getPos(), tile.getBlockType(), 255, 0);
        return true;
    }
    if (tile instanceof IHammerInteraction && Utils.isHammer(heldItem) && !world.isRemote) {
        boolean b = ((IHammerInteraction) tile).hammerUseSide(side, player, hitX, hitY, hitZ);
        if (b)
            return b;
    }
    if (tile instanceof IPlayerInteraction) {
        boolean b = ((IPlayerInteraction) tile).interact(side, player, hand, heldItem, hitX, hitY, hitZ);
        if (b)
            return b;
    }
    if (tile instanceof IGuiTile && hand == EnumHand.MAIN_HAND && !player.isSneaking()) {
        TileEntity master = ((IGuiTile) tile).getGuiMaster();
        if (((IGuiTile) tile).canOpenGui(player)) {
            if (!world.isRemote && master != null)
                CommonProxy.openGuiForTile(player, (TileEntity & IGuiTile) master);
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IHammerInteraction(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction) IGuiTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile) EnumFacing(net.minecraft.util.EnumFacing) IConfigurableSides(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides) IPlayerInteraction(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction) ItemStack(net.minecraft.item.ItemStack) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)

Example 2 with IGuiTile

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile in project ImmersiveEngineering by BluSunrize.

the class ClientProxy method getClientGuiElement.

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    if (ID >= Lib.GUIID_Base_Item) {
        EntityEquipmentSlot slot = EntityEquipmentSlot.values()[ID / 100];
        // Slot determined, get actual ID
        ID %= 100;
        ItemStack item = player.getItemStackFromSlot(slot);
        if (!item.isEmpty() && item.getItem() instanceof IGuiItem && ((IGuiItem) item.getItem()).getGuiID(item) == ID) {
            if (ID == Lib.GUIID_Manual && ManualHelper.getManual() != null && OreDictionary.itemMatches(new ItemStack(IEContent.itemTool, 1, 3), item, false))
                return ManualHelper.getManual().getGui();
            if (ID == Lib.GUIID_Revolver && item.getItem() instanceof IEItemInterfaces.IBulletContainer)
                return new GuiRevolver(player.inventory, world, slot, item);
            if (ID == Lib.GUIID_Toolbox && item.getItem() instanceof ItemToolbox)
                return new GuiToolbox(player.inventory, world, slot, item);
            if (ID == Lib.GUIID_MaintenanceKit && item.getItem() instanceof ItemMaintenanceKit)
                return new GuiMaintenanceKit(player.inventory, world, slot, item);
        }
    }
    if (ID >= Lib.GUIID_Base_Item) {
        ItemStack item = ItemStack.EMPTY;
        for (EnumHand hand : EnumHand.values()) {
            ItemStack held = player.getHeldItem(hand);
            if (!held.isEmpty() && held.getItem() instanceof IGuiItem && ((IGuiItem) held.getItem()).getGuiID(held) == ID)
                item = held;
        }
        if (!item.isEmpty()) {
        }
    } else {
        TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
        if (te instanceof IGuiTile) {
            Object gui = null;
            if (ID == Lib.GUIID_CokeOven && te instanceof TileEntityCokeOven)
                gui = new GuiCokeOven(player.inventory, (TileEntityCokeOven) te);
            if (ID == Lib.GUIID_AlloySmelter && te instanceof TileEntityAlloySmelter)
                gui = new GuiAlloySmelter(player.inventory, (TileEntityAlloySmelter) te);
            if (ID == Lib.GUIID_BlastFurnace && te instanceof TileEntityBlastFurnace)
                gui = new GuiBlastFurnace(player.inventory, (TileEntityBlastFurnace) te);
            if (ID == Lib.GUIID_WoodenCrate && te instanceof TileEntityWoodenCrate)
                gui = new GuiCrate(player.inventory, (TileEntityWoodenCrate) te);
            if (ID == Lib.GUIID_Workbench && te instanceof TileEntityModWorkbench)
                gui = new GuiModWorkbench(player.inventory, world, (TileEntityModWorkbench) te);
            if (ID == Lib.GUIID_Sorter && te instanceof TileEntitySorter)
                gui = new GuiSorter(player.inventory, (TileEntitySorter) te);
            if (ID == Lib.GUIID_Squeezer && te instanceof TileEntitySqueezer)
                gui = new GuiSqueezer(player.inventory, (TileEntitySqueezer) te);
            if (ID == Lib.GUIID_Fermenter && te instanceof TileEntityFermenter)
                gui = new GuiFermenter(player.inventory, (TileEntityFermenter) te);
            if (ID == Lib.GUIID_Refinery && te instanceof TileEntityRefinery)
                gui = new GuiRefinery(player.inventory, (TileEntityRefinery) te);
            if (ID == Lib.GUIID_ArcFurnace && te instanceof TileEntityArcFurnace)
                gui = new GuiArcFurnace(player.inventory, (TileEntityArcFurnace) te);
            if (ID == Lib.GUIID_Assembler && te instanceof TileEntityAssembler)
                gui = new GuiAssembler(player.inventory, (TileEntityAssembler) te);
            if (ID == Lib.GUIID_AutoWorkbench && te instanceof TileEntityAutoWorkbench)
                gui = new GuiAutoWorkbench(player.inventory, (TileEntityAutoWorkbench) te);
            if (ID == Lib.GUIID_Mixer && te instanceof TileEntityMixer)
                gui = new GuiMixer(player.inventory, (TileEntityMixer) te);
            if (ID == Lib.GUIID_Turret && te instanceof TileEntityTurret)
                gui = new GuiTurret(player.inventory, (TileEntityTurret) te);
            if (ID == Lib.GUIID_FluidSorter && te instanceof TileEntityFluidSorter)
                gui = new GuiFluidSorter(player.inventory, (TileEntityFluidSorter) te);
            if (ID == Lib.GUIID_Belljar && te instanceof TileEntityBelljar)
                gui = new GuiBelljar(player.inventory, (TileEntityBelljar) te);
            if (ID == Lib.GUIID_ToolboxBlock && te instanceof TileEntityToolbox)
                gui = new GuiToolboxBlock(player.inventory, (TileEntityToolbox) te);
            if (gui != null)
                ((IGuiTile) te).onGuiOpened(player, true);
            return gui;
        }
    }
    return null;
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) BlockPos(net.minecraft.util.math.BlockPos) IGuiTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile) JsonObject(com.google.gson.JsonObject) PositionedItemStack(blusunrize.lib.manual.ManualPages.PositionedItemStack) IGuiItem(blusunrize.immersiveengineering.common.items.IEItemInterfaces.IGuiItem) TileEntity(net.minecraft.tileentity.TileEntity)

Example 3 with IGuiTile

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile in project ImmersiveEngineering by BluSunrize.

the class CommonProxy method getServerGuiElement.

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    if (ID >= Lib.GUIID_Base_Item) {
        EntityEquipmentSlot slot = EntityEquipmentSlot.values()[ID / 100];
        // Slot determined, get actual ID
        ID %= 100;
        ItemStack item = player.getItemStackFromSlot(slot);
        if (!item.isEmpty() && item.getItem() instanceof IGuiItem && ((IGuiItem) item.getItem()).getGuiID(item) == ID) {
            if (ID == Lib.GUIID_Revolver && item.getItem() instanceof IEItemInterfaces.IBulletContainer)
                return new ContainerRevolver(player.inventory, world, slot, item);
            if (ID == Lib.GUIID_Toolbox && item.getItem() instanceof ItemToolbox)
                return new ContainerToolbox(player.inventory, world, slot, item);
            if (ID == Lib.GUIID_MaintenanceKit && item.getItem() instanceof ItemMaintenanceKit)
                return new ContainerMaintenanceKit(player.inventory, world, slot, item);
        }
    } else {
        TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
        if (te instanceof IGuiTile) {
            Object gui = null;
            if (ID == Lib.GUIID_CokeOven && te instanceof TileEntityCokeOven)
                gui = new ContainerCokeOven(player.inventory, (TileEntityCokeOven) te);
            if (ID == Lib.GUIID_AlloySmelter && te instanceof TileEntityAlloySmelter)
                gui = new ContainerAlloySmelter(player.inventory, (TileEntityAlloySmelter) te);
            if (ID == Lib.GUIID_BlastFurnace && te instanceof TileEntityBlastFurnace)
                gui = new ContainerBlastFurnace(player.inventory, (TileEntityBlastFurnace) te);
            if (ID == Lib.GUIID_WoodenCrate && te instanceof TileEntityWoodenCrate)
                gui = new ContainerCrate(player.inventory, (TileEntityWoodenCrate) te);
            if (ID == Lib.GUIID_Workbench && te instanceof TileEntityModWorkbench)
                gui = new ContainerModWorkbench(player.inventory, world, (TileEntityModWorkbench) te);
            if (ID == Lib.GUIID_Sorter && te instanceof TileEntitySorter)
                gui = new ContainerSorter(player.inventory, (TileEntitySorter) te);
            if (ID == Lib.GUIID_Squeezer && te instanceof TileEntitySqueezer)
                gui = new ContainerSqueezer(player.inventory, (TileEntitySqueezer) te);
            if (ID == Lib.GUIID_Fermenter && te instanceof TileEntityFermenter)
                gui = new ContainerFermenter(player.inventory, (TileEntityFermenter) te);
            if (ID == Lib.GUIID_Refinery && te instanceof TileEntityRefinery)
                gui = new ContainerRefinery(player.inventory, (TileEntityRefinery) te);
            if (ID == Lib.GUIID_ArcFurnace && te instanceof TileEntityArcFurnace)
                gui = new ContainerArcFurnace(player.inventory, (TileEntityArcFurnace) te);
            if (ID == Lib.GUIID_Assembler && te instanceof TileEntityAssembler)
                gui = new ContainerAssembler(player.inventory, (TileEntityAssembler) te);
            if (ID == Lib.GUIID_AutoWorkbench && te instanceof TileEntityAutoWorkbench)
                gui = new ContainerAutoWorkbench(player.inventory, (TileEntityAutoWorkbench) te);
            if (ID == Lib.GUIID_Mixer && te instanceof TileEntityMixer)
                gui = new ContainerMixer(player.inventory, (TileEntityMixer) te);
            if (ID == Lib.GUIID_Turret && te instanceof TileEntityTurret)
                gui = new ContainerTurret(player.inventory, (TileEntityTurret) te);
            if (ID == Lib.GUIID_FluidSorter && te instanceof TileEntityFluidSorter)
                gui = new ContainerFluidSorter(player.inventory, (TileEntityFluidSorter) te);
            if (ID == Lib.GUIID_Belljar && te instanceof TileEntityBelljar)
                gui = new ContainerBelljar(player.inventory, (TileEntityBelljar) te);
            if (ID == Lib.GUIID_ToolboxBlock && te instanceof TileEntityToolbox)
                gui = new ContainerToolboxBlock(player.inventory, (TileEntityToolbox) te);
            if (gui != null)
                ((IGuiTile) te).onGuiOpened(player, false);
            return gui;
        }
    }
    return null;
}
Also used : TileEntityModWorkbench(blusunrize.immersiveengineering.common.blocks.wooden.TileEntityModWorkbench) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) IGuiItem(blusunrize.immersiveengineering.common.items.IEItemInterfaces.IGuiItem) IEItemInterfaces(blusunrize.immersiveengineering.common.items.IEItemInterfaces) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityCokeOven(blusunrize.immersiveengineering.common.blocks.stone.TileEntityCokeOven) TileEntitySorter(blusunrize.immersiveengineering.common.blocks.wooden.TileEntitySorter) TileEntityBlastFurnace(blusunrize.immersiveengineering.common.blocks.stone.TileEntityBlastFurnace) BlockPos(net.minecraft.util.math.BlockPos) TileEntityFluidSorter(blusunrize.immersiveengineering.common.blocks.wooden.TileEntityFluidSorter) ItemToolbox(blusunrize.immersiveengineering.common.items.ItemToolbox) TileEntityAlloySmelter(blusunrize.immersiveengineering.common.blocks.stone.TileEntityAlloySmelter) IGuiTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile) TileEntityWoodenCrate(blusunrize.immersiveengineering.common.blocks.wooden.TileEntityWoodenCrate) ItemMaintenanceKit(blusunrize.immersiveengineering.common.items.ItemMaintenanceKit) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IGuiTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile)3 TileEntity (net.minecraft.tileentity.TileEntity)3 IGuiItem (blusunrize.immersiveengineering.common.items.IEItemInterfaces.IGuiItem)2 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 IConfigurableSides (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides)1 IDirectionalTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)1 IHammerInteraction (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction)1 IPlayerInteraction (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction)1 TileEntityAlloySmelter (blusunrize.immersiveengineering.common.blocks.stone.TileEntityAlloySmelter)1 TileEntityBlastFurnace (blusunrize.immersiveengineering.common.blocks.stone.TileEntityBlastFurnace)1 TileEntityCokeOven (blusunrize.immersiveengineering.common.blocks.stone.TileEntityCokeOven)1 TileEntityFluidSorter (blusunrize.immersiveengineering.common.blocks.wooden.TileEntityFluidSorter)1 TileEntityModWorkbench (blusunrize.immersiveengineering.common.blocks.wooden.TileEntityModWorkbench)1 TileEntitySorter (blusunrize.immersiveengineering.common.blocks.wooden.TileEntitySorter)1 TileEntityWoodenCrate (blusunrize.immersiveengineering.common.blocks.wooden.TileEntityWoodenCrate)1 IEItemInterfaces (blusunrize.immersiveengineering.common.items.IEItemInterfaces)1 ItemMaintenanceKit (blusunrize.immersiveengineering.common.items.ItemMaintenanceKit)1 ItemToolbox (blusunrize.immersiveengineering.common.items.ItemToolbox)1