Search in sources :

Example 1 with CoverDigitalInterface

use of gregtech.common.covers.CoverDigitalInterface in project GregTech by GregTechCEu.

the class MetaTileEntityMonitorScreen method getCoverFromPosSide.

public CoverDigitalInterface getCoverFromPosSide(BlockPosFace posFacing) {
    if (posFacing == null)
        return null;
    ICoverable mte = null;
    MetaTileEntityHolder holder = getHolderFromPos(posFacing.pos);
    if (holder == null) {
        TileEntity te = this.getWorld() == null ? null : this.getWorld().getTileEntity(posFacing.pos);
        if (te instanceof TileEntityPipeBase) {
            mte = ((TileEntityPipeBase<?, ?>) te).getCoverableImplementation();
        }
    } else {
        mte = holder.getMetaTileEntity();
    }
    if (mte != null) {
        CoverBehavior cover = mte.getCoverAtSide(posFacing.facing);
        if (cover instanceof CoverDigitalInterface) {
            return (CoverDigitalInterface) cover;
        }
    }
    return null;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ICoverable(gregtech.api.cover.ICoverable) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) CoverDigitalInterface(gregtech.common.covers.CoverDigitalInterface) TileEntityPipeBase(gregtech.api.pipenet.tile.TileEntityPipeBase) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 2 with CoverDigitalInterface

use of gregtech.common.covers.CoverDigitalInterface in project GregTech by GregTechCEu.

the class MetaTileEntityCentralMonitor method checkCovers.

private boolean checkCovers() {
    boolean dirty = false;
    updateNodes();
    Set<BlockPosFace> checkCovers = new HashSet<>();
    World world = this.getWorld();
    for (BlockPos pos : activeNodes) {
        TileEntity tileEntityCable = world.getTileEntity(pos);
        if (!(tileEntityCable instanceof TileEntityPipeBase)) {
            continue;
        }
        for (EnumFacing facing : EnumFacing.VALUES) {
            if (((TileEntityPipeBase<?, ?>) tileEntityCable).isConnected(facing)) {
                TileEntity tileEntity = world.getTileEntity(pos.offset(facing));
                if (tileEntity instanceof MetaTileEntityHolder) {
                    MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
                    if (metaTileEntity != null) {
                        CoverBehavior cover = metaTileEntity.getCoverAtSide(facing.getOpposite());
                        if (cover instanceof CoverDigitalInterface && ((CoverDigitalInterface) cover).isProxy()) {
                            checkCovers.add(new BlockPosFace(metaTileEntity.getPos(), cover.attachedSide));
                        }
                    }
                }
            }
        }
    }
    Iterator<BlockPosFace> iterator = remoteCovers.iterator();
    while (iterator.hasNext()) {
        BlockPosFace blockPosFace = iterator.next();
        TileEntity tileEntity = world.getTileEntity(blockPosFace.pos);
        if (tileEntity instanceof MetaTileEntityHolder) {
            MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
            if (metaTileEntity != null) {
                CoverBehavior cover = metaTileEntity.getCoverAtSide(blockPosFace.facing);
                if (cover instanceof CoverDigitalInterface && ((CoverDigitalInterface) cover).isProxy()) {
                    continue;
                }
            }
        }
        iterator.remove();
        dirty = true;
    }
    if (checkCovers.size() != netCovers.size() || !netCovers.containsAll(checkCovers)) {
        netCovers = checkCovers;
        dirty = true;
    }
    return dirty;
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) BlockPosFace(gregtech.api.util.BlockPosFace) EnumFacing(net.minecraft.util.EnumFacing) CoverDigitalInterface(gregtech.common.covers.CoverDigitalInterface) World(net.minecraft.world.World) TileEntityPipeBase(gregtech.api.pipenet.tile.TileEntityPipeBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) BlockPos(net.minecraft.util.math.BlockPos) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 3 with CoverDigitalInterface

use of gregtech.common.covers.CoverDigitalInterface in project GregTech by GregTechCEu.

the class MetaTileEntityMonitorScreen method setMode.

public void setMode(BlockPosFace cover, CoverDigitalInterface.MODE mode) {
    CoverDigitalInterface last_cover = this.getCoverFromPosSide(coverPos);
    CoverDigitalInterface now_cover = this.getCoverFromPosSide(cover);
    if (this.mode == mode) {
        if (Objects.equals(cover, coverPos) && last_cover == null && cover == null || last_cover != null && last_cover == now_cover) {
            return;
        }
    }
    if (last_cover != null && this.mode != CoverDigitalInterface.MODE.PROXY) {
        last_cover.unSubProxyMode(this.mode);
    }
    if (cover != null && mode != CoverDigitalInterface.MODE.PROXY) {
        now_cover.subProxyMode(mode);
    }
    this.coverPos = cover;
    this.mode = mode;
    updateProxyPlugin();
    writeCustomData(GregtechDataCodes.UPDATE_ALL, this::writeSync);
    this.markDirty();
}
Also used : CoverDigitalInterface(gregtech.common.covers.CoverDigitalInterface)

Example 4 with CoverDigitalInterface

use of gregtech.common.covers.CoverDigitalInterface in project GregTech by GregTechCEu.

the class MetaTileEntityMonitorScreen method createUI.

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
    MultiblockControllerBase controller = this.getController();
    if (controller instanceof MetaTileEntityCentralMonitor && ((MetaTileEntityCentralMonitor) controller).isActive()) {
        int width = 330;
        int height = 260;
        ToggleButtonWidget[] buttons = new ToggleButtonWidget[5];
        buttons[0] = new ToggleButtonWidget(width - 135, 25, 20, 20, GuiTextures.BUTTON_FLUID, () -> this.mode == CoverDigitalInterface.MODE.FLUID, (isPressed) -> {
            if (isPressed)
                setMode(CoverDigitalInterface.MODE.FLUID);
        }).setTooltipText("metaitem.cover.digital.mode.fluid");
        buttons[1] = new ToggleButtonWidget(width - 115, 25, 20, 20, GuiTextures.BUTTON_ITEM, () -> this.mode == CoverDigitalInterface.MODE.ITEM, (isPressed) -> {
            if (isPressed)
                setMode(CoverDigitalInterface.MODE.ITEM);
        }).setTooltipText("metaitem.cover.digital.mode.item");
        buttons[2] = new ToggleButtonWidget(width - 95, 25, 20, 20, GuiTextures.BUTTON_ENERGY, () -> this.mode == CoverDigitalInterface.MODE.ENERGY, (isPressed) -> {
            if (isPressed)
                setMode(CoverDigitalInterface.MODE.ENERGY);
        }).setTooltipText("metaitem.cover.digital.mode.energy");
        buttons[3] = new ToggleButtonWidget(width - 75, 25, 20, 20, GuiTextures.BUTTON_MACHINE, () -> this.mode == CoverDigitalInterface.MODE.MACHINE, (isPressed) -> {
            if (isPressed)
                setMode(CoverDigitalInterface.MODE.MACHINE);
        }).setTooltipText("metaitem.cover.digital.mode.machine");
        buttons[4] = new ToggleButtonWidget(width - 35, 25, 20, 20, GuiTextures.BUTTON_INTERFACE, () -> this.mode == CoverDigitalInterface.MODE.PROXY, (isPressed) -> {
            if (isPressed)
                setMode(CoverDigitalInterface.MODE.PROXY);
        }).setTooltipText("metaitem.cover.digital.mode.proxy");
        List<CoverDigitalInterface> covers = new ArrayList<>();
        ((MetaTileEntityCentralMonitor) controller).getAllCovers().forEach(coverPos -> covers.add(getCoverFromPosSide(coverPos)));
        WidgetPluginConfig pluginWidget = new WidgetPluginConfig();
        WidgetPluginConfig mainGroup = new WidgetPluginConfig().setSize(width, height);
        mainGroup.widget(new LabelWidget(15, 55, "monitor.gui.title.scale", 0xFFFFFFFF)).widget(new ClickButtonWidget(50, 50, 20, 20, "-1", (data) -> setConfig(this.slot, ((float) Math.round((scale - (data.isShiftClick ? 1.0f : 0.1f)) * 10) / 10), this.frameColor))).widget(new ClickButtonWidget(130, 50, 20, 20, "+1", (data) -> setConfig(this.slot, ((float) Math.round((scale + (data.isShiftClick ? 1.0f : 0.1f)) * 10) / 10), this.frameColor))).widget(new ImageWidget(70, 50, 60, 20, GuiTextures.DISPLAY)).widget(new SimpleTextWidget(100, 60, "", 16777215, () -> Float.toString(scale))).widget(new LabelWidget(15, 85, "monitor.gui.title.argb", 0xFFFFFFFF)).widget(new WidgetARGB(50, 80, 20, this.frameColor, (color) -> setConfig(this.slot, this.scale, color))).widget(new LabelWidget(15, 110, "monitor.gui.title.slot", 0xFFFFFFFF)).widget(new ClickButtonWidget(50, 105, 20, 20, "-1", (data) -> setConfig(this.slot - 1, this.scale, this.frameColor))).widget(new ClickButtonWidget(130, 105, 20, 20, "+1", (data) -> setConfig(this.slot + 1, this.scale, this.frameColor))).widget(new ImageWidget(70, 105, 60, 20, GuiTextures.DISPLAY)).widget(new SimpleTextWidget(100, 115, "", 16777215, () -> Integer.toString(slot))).widget(new LabelWidget(15, 135, "monitor.gui.title.plugin", 0xFFFFFFFF)).widget(new SlotWidget(inventory, 0, 50, 130, true, true).setBackgroundTexture(GuiTextures.SLOT).setChangeListener(() -> {
            if (this.getWorld() != null && !this.getWorld().isRemote) {
                MonitorPluginBaseBehavior behavior = MonitorPluginBaseBehavior.getBehavior(inventory.getStackInSlot(0));
                if (behavior == null) {
                    unloadPlugin();
                } else {
                    loadPlugin(behavior);
                }
                writeCustomData(GregtechDataCodes.UPDATE_PLUGIN_ITEM, packetBuffer -> packetBuffer.writeItemStack(inventory.getStackInSlot(0)));
            }
        })).widget(new ClickButtonWidget(80, 130, 40, 20, "monitor.gui.title.config", (data) -> {
            if (plugin != null && mainGroup.isVisible()) {
                plugin.customUI(pluginWidget, this.getHolder(), entityPlayer);
                mainGroup.setVisible(false);
            }
        }) {

            @Override
            protected void triggerButton() {
                super.triggerButton();
                if (plugin != null && mainGroup.isVisible()) {
                    plugin.customUI(pluginWidget, getHolder(), entityPlayer);
                    mainGroup.setVisible(false);
                }
            }
        }).widget(new WidgetCoverList(width - 140, 50, 120, 11, covers, getCoverFromPosSide(this.coverPos), (coverPos) -> {
            if (coverPos == null) {
                this.setMode(null, this.mode);
            } else {
                this.setMode(new BlockPosFace(coverPos.coverHolder.getPos(), coverPos.attachedSide));
            }
        })).widget(buttons[0]).widget(buttons[1]).widget(buttons[2]).widget(buttons[3]).widget(buttons[4]).bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 15, 170);
        return ModularUI.builder(GuiTextures.BOXED_BACKGROUND, width, height).widget(pluginWidget).widget(mainGroup).widget(new WidgetMonitorScreen(330, 0, 150, this)).widget(new LabelWidget(15, 13, "gregtech.machine.monitor_screen.name", 0XFFFFFFFF)).widget(new ClickButtonWidget(15, 25, 40, 20, "monitor.gui.title.back", data -> {
            if (mainGroup.isVisible() && ((MetaTileEntityCentralMonitor) controller).isActive() && controller.isValid()) {
                MetaTileEntityUIFactory.INSTANCE.openUI(controller.getHolder(), (EntityPlayerMP) entityPlayer);
            } else if (!mainGroup.isVisible()) {
                pluginWidget.removePluginWidget();
                mainGroup.setVisible(true);
                if (plugin != null) {
                    plugin.markAsDirty();
                }
            }
        }) {

            @Override
            protected void triggerButton() {
                super.triggerButton();
                if (!mainGroup.isVisible()) {
                    pluginWidget.removePluginWidget();
                    mainGroup.setVisible(true);
                    if (plugin != null) {
                        plugin.markAsDirty();
                    }
                }
            }
        }).bindCloseListener(() -> {
            if (plugin != null) {
                plugin.markAsDirty();
            }
        }).build(this.getHolder(), entityPlayer);
    }
    return null;
}
Also used : net.minecraft.util(net.minecraft.util) MetaTileEntities(gregtech.common.metatileentities.MetaTileEntities) CoverBehavior(gregtech.api.cover.CoverBehavior) CoverDigitalInterface(gregtech.common.covers.CoverDigitalInterface) WidgetMonitorScreen(gregtech.common.gui.widget.monitor.WidgetMonitorScreen) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TileEntityPipeBase(gregtech.api.pipenet.tile.TileEntityPipeBase) I18n(net.minecraft.client.resources.I18n) gregtech.api.gui.widgets(gregtech.api.gui.widgets) Vec3d(net.minecraft.util.math.Vec3d) Pair(org.apache.commons.lang3.tuple.Pair) Side(net.minecraftforge.fml.relauncher.Side) CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) GregtechDataCodes(gregtech.api.capability.GregtechDataCodes) WidgetPluginConfig(gregtech.common.gui.widget.monitor.WidgetPluginConfig) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ProxyHolderPluginBehavior(gregtech.api.items.behavior.ProxyHolderPluginBehavior) GlStateManager(net.minecraft.client.renderer.GlStateManager) ICoverable(gregtech.api.cover.ICoverable) GuiTextures(gregtech.api.gui.GuiTextures) Capability(net.minecraftforge.common.capabilities.Capability) GregtechCapabilities(gregtech.api.capability.GregtechCapabilities) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ModularUI(gregtech.api.gui.ModularUI) NBTUtil(net.minecraft.nbt.NBTUtil) java.util(java.util) MetaTileEntityUIFactory(gregtech.api.metatileentity.MetaTileEntityUIFactory) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) MonitorPluginBaseBehavior(gregtech.api.items.behavior.MonitorPluginBaseBehavior) Minecraft(net.minecraft.client.Minecraft) RenderUtil(gregtech.client.utils.RenderUtil) BlockPosFace(gregtech.api.util.BlockPosFace) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) IBlockState(net.minecraft.block.state.IBlockState) WidgetARGB(gregtech.common.gui.widget.WidgetARGB) WidgetCoverList(gregtech.common.gui.widget.monitor.WidgetCoverList) TileEntity(net.minecraft.tileentity.TileEntity) MetaTileEntityMultiblockPart(gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockPart) PacketBuffer(net.minecraft.network.PacketBuffer) BlockPosFace(gregtech.api.util.BlockPosFace) WidgetMonitorScreen(gregtech.common.gui.widget.monitor.WidgetMonitorScreen) CoverDigitalInterface(gregtech.common.covers.CoverDigitalInterface) WidgetARGB(gregtech.common.gui.widget.WidgetARGB) WidgetCoverList(gregtech.common.gui.widget.monitor.WidgetCoverList) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) MonitorPluginBaseBehavior(gregtech.api.items.behavior.MonitorPluginBaseBehavior) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WidgetPluginConfig(gregtech.common.gui.widget.monitor.WidgetPluginConfig)

Example 5 with CoverDigitalInterface

use of gregtech.common.covers.CoverDigitalInterface in project GregTech by GregTechCEu.

the class MetaTileEntityMonitorScreen method isActive.

public boolean isActive() {
    if (this.coverPos != null && this.mode != CoverDigitalInterface.MODE.PROXY) {
        CoverDigitalInterface cover = coverTMP != null ? coverTMP : this.getCoverFromPosSide(this.coverPos);
        if (cover != null) {
            if (cover.isProxy()) {
                coverTMP = cover;
                return true;
            }
        }
        this.coverPos = null;
    }
    return plugin != null;
}
Also used : CoverDigitalInterface(gregtech.common.covers.CoverDigitalInterface)

Aggregations

CoverDigitalInterface (gregtech.common.covers.CoverDigitalInterface)6 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)4 TileEntity (net.minecraft.tileentity.TileEntity)4 CoverBehavior (gregtech.api.cover.CoverBehavior)3 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)3 TileEntityPipeBase (gregtech.api.pipenet.tile.TileEntityPipeBase)3 BlockPos (net.minecraft.util.math.BlockPos)3 ICoverable (gregtech.api.cover.ICoverable)2 BlockPosFace (gregtech.api.util.BlockPosFace)2 IBlockState (net.minecraft.block.state.IBlockState)2 World (net.minecraft.world.World)2 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)1 GregtechCapabilities (gregtech.api.capability.GregtechCapabilities)1 GregtechDataCodes (gregtech.api.capability.GregtechDataCodes)1 GuiTextures (gregtech.api.gui.GuiTextures)1 ModularUI (gregtech.api.gui.ModularUI)1 gregtech.api.gui.widgets (gregtech.api.gui.widgets)1 MonitorPluginBaseBehavior (gregtech.api.items.behavior.MonitorPluginBaseBehavior)1 ProxyHolderPluginBehavior (gregtech.api.items.behavior.ProxyHolderPluginBehavior)1 IFastRenderMetaTileEntity (gregtech.api.metatileentity.IFastRenderMetaTileEntity)1