Search in sources :

Example 1 with IConfigurableTool

use of blusunrize.immersiveengineering.api.tool.IConfigurableTool in project ImmersiveEngineering by BluSunrize.

the class GuiModWorkbench method mouseReleased.

@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
    super.mouseReleased(mouseX, mouseY, state);
    Slot s = inventorySlots.getSlot(0);
    if (s != null && s.getHasStack() && s.getStack().getItem() instanceof IConfigurableTool) {
        ItemStack stack = s.getStack();
        IConfigurableTool tool = ((IConfigurableTool) stack.getItem());
        NBTTagCompound message = new NBTTagCompound();
        ToolConfigBoolean[] boolArray = tool.getBooleanOptions(stack);
        int iBool = 0;
        ToolConfigFloat[] floatArray = tool.getFloatOptions(stack);
        int iFloat = 0;
        for (GuiButton button : this.buttonList) {
            if (button instanceof GuiButtonCheckbox && boolArray != null)
                message.setBoolean("b_" + boolArray[iBool++].name, ((GuiButtonCheckbox) button).state);
            if (button instanceof GuiSliderIE && floatArray != null)
                message.setFloat("f_" + floatArray[iFloat++].name, (float) ((GuiSliderIE) button).sliderValue);
        }
        if (//Only send packets when values have changed
        lastMessage == null || !lastMessage.equals(message))
            ImmersiveEngineering.packetHandler.sendToServer(new MessageTileSync(this.workbench, message));
        lastMessage = message;
    }
}
Also used : ToolConfigBoolean(blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigBoolean) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GuiButton(net.minecraft.client.gui.GuiButton) GuiSliderIE(blusunrize.immersiveengineering.client.gui.elements.GuiSliderIE) IESlot(blusunrize.immersiveengineering.common.gui.IESlot) Slot(net.minecraft.inventory.Slot) IConfigurableTool(blusunrize.immersiveengineering.api.tool.IConfigurableTool) ToolConfigFloat(blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigFloat) GuiButtonCheckbox(blusunrize.immersiveengineering.client.gui.elements.GuiButtonCheckbox) ItemStack(net.minecraft.item.ItemStack) MessageTileSync(blusunrize.immersiveengineering.common.util.network.MessageTileSync)

Example 2 with IConfigurableTool

use of blusunrize.immersiveengineering.api.tool.IConfigurableTool in project ImmersiveEngineering by BluSunrize.

the class ContainerModWorkbench method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    ItemStack stack = null;
    Slot slotObject = inventorySlots.get(slot);
    if (slotObject != null && slotObject.getHasStack()) {
        ItemStack stackInSlot = slotObject.getStack();
        stack = stackInSlot.copy();
        if (slot < slotCount) {
            if (!this.mergeItemStack(stackInSlot, slotCount, (slotCount + 36), true))
                return null;
        } else if (stackInSlot != null) {
            if (stackInSlot.getItem() instanceof IUpgradeableTool && ((IUpgradeableTool) stackInSlot.getItem()).canModify(stackInSlot)) {
                if (!this.mergeItemStack(stackInSlot, 0, 1, true))
                    return null;
            } else if (stackInSlot.getItem() instanceof IConfigurableTool && ((IConfigurableTool) stackInSlot.getItem()).canConfigure(stackInSlot)) {
                if (!this.mergeItemStack(stackInSlot, 0, 1, true))
                    return null;
            } else if (slotCount > 1) {
                boolean b = true;
                for (int i = 1; i < slotCount; i++) {
                    Slot s = inventorySlots.get(i);
                    if (s != null && s.isItemValid(stackInSlot))
                        if (this.mergeItemStack(stackInSlot, i, i + 1, true)) {
                            b = false;
                            break;
                        } else
                            continue;
                }
                if (b)
                    return null;
            }
        }
        if (stackInSlot.stackSize == 0)
            slotObject.putStack(null);
        else
            slotObject.onSlotChanged();
        if (stackInSlot.stackSize == stack.stackSize)
            return null;
        slotObject.onPickupFromSlot(player, stack);
    }
    return stack;
}
Also used : Slot(net.minecraft.inventory.Slot) IUpgradeableTool(blusunrize.immersiveengineering.api.tool.IUpgradeableTool) IConfigurableTool(blusunrize.immersiveengineering.api.tool.IConfigurableTool) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IConfigurableTool

use of blusunrize.immersiveengineering.api.tool.IConfigurableTool in project ImmersiveEngineering by BluSunrize.

the class GuiModWorkbench method initGui.

@Override
public void initGui() {
    this.buttonList.clear();
    super.initGui();
    Slot s = inventorySlots.getSlot(0);
    if (s != null && s.getHasStack() && s.getStack().getItem() instanceof IConfigurableTool) {
        ItemStack stack = s.getStack();
        IConfigurableTool tool = ((IConfigurableTool) stack.getItem());
        int buttonid = 0;
        ToolConfigBoolean[] boolArray = tool.getBooleanOptions(stack);
        if (boolArray != null)
            for (ToolConfigBoolean b : boolArray) this.buttonList.add(new GuiButtonCheckbox(buttonid++, guiLeft + b.x, guiTop + b.y, tool.fomatConfigName(stack, b), b.value));
        ToolConfigFloat[] floatArray = tool.getFloatOptions(stack);
        if (floatArray != null)
            for (ToolConfigFloat f : floatArray) this.buttonList.add(new GuiSliderIE(buttonid++, guiLeft + f.x, guiTop + f.y, 80, tool.fomatConfigName(stack, f), f.value));
    }
}
Also used : ToolConfigBoolean(blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigBoolean) GuiSliderIE(blusunrize.immersiveengineering.client.gui.elements.GuiSliderIE) IESlot(blusunrize.immersiveengineering.common.gui.IESlot) Slot(net.minecraft.inventory.Slot) IConfigurableTool(blusunrize.immersiveengineering.api.tool.IConfigurableTool) ToolConfigFloat(blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigFloat) GuiButtonCheckbox(blusunrize.immersiveengineering.client.gui.elements.GuiButtonCheckbox) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IConfigurableTool (blusunrize.immersiveengineering.api.tool.IConfigurableTool)3 Slot (net.minecraft.inventory.Slot)3 ItemStack (net.minecraft.item.ItemStack)3 ToolConfigBoolean (blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigBoolean)2 ToolConfigFloat (blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigFloat)2 GuiButtonCheckbox (blusunrize.immersiveengineering.client.gui.elements.GuiButtonCheckbox)2 GuiSliderIE (blusunrize.immersiveengineering.client.gui.elements.GuiSliderIE)2 IESlot (blusunrize.immersiveengineering.common.gui.IESlot)2 IUpgradeableTool (blusunrize.immersiveengineering.api.tool.IUpgradeableTool)1 MessageTileSync (blusunrize.immersiveengineering.common.util.network.MessageTileSync)1 GuiButton (net.minecraft.client.gui.GuiButton)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1