Search in sources :

Example 1 with ISensorSetting

use of pneumaticCraft.api.universalSensor.ISensorSetting in project PneumaticCraft by MineMaarten.

the class GuiUniversalSensor method getSensorInfo.

private List<String> getSensorInfo() {
    List<String> text = new ArrayList<String>();
    ISensorSetting sensor = SensorHandler.instance().getSensorFromPath(te.getSensorSetting());
    if (sensor != null) {
        String[] folders = te.getSensorSetting().split("/");
        text.add(EnumChatFormatting.GRAY + folders[folders.length - 1]);
        text.addAll(sensor.getDescription());
    } else {
        text.add(EnumChatFormatting.BLACK + "No sensor selected.");
    }
    return text;
}
Also used : ISensorSetting(pneumaticCraft.api.universalSensor.ISensorSetting) ArrayList(java.util.ArrayList)

Example 2 with ISensorSetting

use of pneumaticCraft.api.universalSensor.ISensorSetting in project PneumaticCraft by MineMaarten.

the class GuiUniversalSensor method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float opacity, int x, int y) {
    super.drawGuiContainerBackgroundLayer(opacity, x, y);
    nameFilterField.drawTextBox();
    ISensorSetting sensor = SensorHandler.instance().getSensorFromPath(te.getSensorSetting());
    if (sensor != null) {
        sensor.drawAdditionalInfo(fontRendererObj);
    }
}
Also used : ISensorSetting(pneumaticCraft.api.universalSensor.ISensorSetting)

Example 3 with ISensorSetting

use of pneumaticCraft.api.universalSensor.ISensorSetting in project PneumaticCraft by MineMaarten.

the class GuiUniversalSensor method updateButtons.

public void updateButtons() {
    buttonList.clear();
    buttonList.add(redstoneButton);
    if (!te.getSensorSetting().equals("")) {
        buttonList.add(new GuiButton(1, guiLeft + 70, guiTop + 18, 30, 20, "back"));
    } else {
        buttonList.add(new GuiButton(-1, guiLeft + 70, guiTop + 125, 98, 20, I18n.format("gui.universalSensor.button.showRange")));
    }
    String[] directories = SensorHandler.instance().getDirectoriesAtLocation(te.getSensorSetting());
    maxPage = (directories.length - 1) / MAX_SENSORS_PER_PAGE + 1;
    if (page > maxPage)
        page = maxPage;
    if (page < 1)
        page = 1;
    if (maxPage > 1) {
        buttonList.add(new GuiButton(2, guiLeft + 70, guiTop + 40 + 22 * MAX_SENSORS_PER_PAGE, 30, 20, "<--"));
        buttonList.add(new GuiButton(3, guiLeft + 138, guiTop + 40 + 22 * MAX_SENSORS_PER_PAGE, 30, 20, "-->"));
    }
    int buttonsOnPage = MAX_SENSORS_PER_PAGE;
    if (page == maxPage && (directories.length % MAX_SENSORS_PER_PAGE > 0 || directories.length == 0)) {
        buttonsOnPage = directories.length % MAX_SENSORS_PER_PAGE;
    }
    for (int i = 0; i < buttonsOnPage; i++) {
        String buttonText = directories[i + (page - 1) * MAX_SENSORS_PER_PAGE];
        if (SensorHandler.instance().getSensorFromPath(te.getSensorSetting() + "/" + buttonText) != null) {
            buttonText = EnumChatFormatting.YELLOW + buttonText;
        }
        int buttonID = i * 10 + 10 + (page - 1) * MAX_SENSORS_PER_PAGE * 10;
        int buttonX = guiLeft + 70;
        int buttonY = guiTop + 40 + i * 22;
        int buttonWidth = 98;
        int buttonHeight = 20;
        if (te.getSensorSetting().equals("")) {
            ItemStack[] requiredStacks = SensorHandler.instance().getRequiredStacksFromText(buttonText);
            GuiButtonSpecial button = new GuiButtonSpecial(buttonID, buttonX, buttonY, buttonWidth, buttonHeight, "");
            button.setRenderStacks(requiredStacks);
            button.enabled = te.areGivenUpgradesInserted(requiredStacks);
            buttonList.add(button);
        } else {
            buttonList.add(new GuiButton(buttonID, buttonX, buttonY, buttonWidth, buttonHeight, buttonText));
        }
    }
    sensorInfoStat.setText(getSensorInfo());
    ISensorSetting sensor = SensorHandler.instance().getSensorFromPath(te.getSensorSetting());
    boolean textboxEnabled = sensor != null && sensor.needsTextBox();
    nameFilterField.setVisible(textboxEnabled);
    if (!textboxEnabled)
        nameFilterField.setFocused(false);
}
Also used : ISensorSetting(pneumaticCraft.api.universalSensor.ISensorSetting) GuiButton(net.minecraft.client.gui.GuiButton) ItemStack(net.minecraft.item.ItemStack) Point(java.awt.Point)

Example 4 with ISensorSetting

use of pneumaticCraft.api.universalSensor.ISensorSetting in project PneumaticCraft by MineMaarten.

the class TileEntityUniversalSensor method updateEntity.

@Override
public void updateEntity() {
    oldDishRotation = dishRotation;
    if (isSensorActive) {
        dishSpeed = Math.min(dishSpeed + 0.2F, 10);
    } else {
        dishSpeed = Math.max(dishSpeed - 0.2F, 0);
    }
    dishRotation += dishSpeed;
    if (worldObj.isRemote) {
        int sensorRange = getRange();
        if (oldSensorRange != sensorRange || oldSensorRange == 0) {
            oldSensorRange = sensorRange;
            if (!firstRun)
                rangeLineRenderer.resetRendering(sensorRange);
        }
        rangeLineRenderer.update();
    }
    super.updateEntity();
    if (!worldObj.isRemote) {
        ticksExisted++;
        ISensorSetting sensor = SensorHandler.instance().getSensorFromPath(sensorSetting);
        if (sensor != null && getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR) {
            isSensorActive = true;
            addAir(-PneumaticValues.USAGE_UNIVERSAL_SENSOR, ForgeDirection.UNKNOWN);
            if (sensor instanceof IPollSensorSetting) {
                if (ticksExisted % ((IPollSensorSetting) sensor).getPollFrequency(this) == 0) {
                    int newRedstoneStrength = ((IPollSensorSetting) sensor).getRedstoneValue(worldObj, xCoord, yCoord, zCoord, getRange(), sensorGuiText);
                    if (invertedRedstone)
                        newRedstoneStrength = 15 - newRedstoneStrength;
                    if (newRedstoneStrength != redstoneStrength) {
                        redstoneStrength = newRedstoneStrength;
                        if (requestPollPullEvent) {
                            notifyComputers(redstoneStrength);
                        }
                        updateNeighbours();
                    }
                }
                eventTimer = 0;
            } else {
                if (eventTimer > 0) {
                    eventTimer--;
                    if (eventTimer == 0 && redstoneStrength != (invertedRedstone ? 15 : 0)) {
                        redstoneStrength = invertedRedstone ? 15 : 0;
                        updateNeighbours();
                    }
                }
            }
        } else {
            isSensorActive = false;
            if (redstoneStrength != (invertedRedstone ? 15 : 0)) {
                redstoneStrength = invertedRedstone ? 15 : 0;
                updateNeighbours();
            }
        }
    }
}
Also used : ISensorSetting(pneumaticCraft.api.universalSensor.ISensorSetting) IPollSensorSetting(pneumaticCraft.api.universalSensor.IPollSensorSetting)

Example 5 with ISensorSetting

use of pneumaticCraft.api.universalSensor.ISensorSetting in project PneumaticCraft by MineMaarten.

the class TileEntityUniversalSensor method addLuaMethods.

@Override
public void addLuaMethods() {
    super.addLuaMethods();
    luaMethods.add(new LuaMethod("getSensorNames") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                return SensorHandler.instance().getSensorNames();
            } else {
                throw new IllegalArgumentException("getSensorNames doesn't accept any arguments!");
            }
        }
    });
    luaMethods.add(new LuaMethod("setSensor") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                ISensorSetting sensor = null;
                if (args[0] instanceof String) {
                    sensor = SensorHandler.instance().getSensorForName((String) args[0]);
                } else {
                    sensor = SensorHandler.instance().getSensorByIndex(((Double) args[0]).intValue() - 1);
                }
                if (sensor != null)
                    return new Object[] { setSensorSetting(sensor) };
                throw new IllegalArgumentException("Invalid sensor name/index: " + args[0]);
            } else if (args.length == 0) {
                setSensorSetting("");
                return new Object[] { true };
            } else {
                throw new IllegalArgumentException("setSensor needs one argument(a number as index, or a sensor name).");
            }
        }
    });
    luaMethods.add(new LuaMethod("getSensor") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                ISensorSetting curSensor = SensorHandler.instance().getSensorFromPath(getSensorSetting());
                return curSensor == null ? null : new Object[] { getSensorSetting().substring(getSensorSetting().lastIndexOf('/') + 1) };
            } else {
                throw new IllegalArgumentException("getSensor doesn't take any arguments!");
            }
        }
    });
    luaMethods.add(new LuaMethod("setTextfield") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                setText(0, (String) args[0]);
                return null;
            } else {
                throw new IllegalArgumentException("setTextfield takes one argument (string)");
            }
        }
    });
    luaMethods.add(new LuaMethod("getTextfield") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                return new Object[] { getText(0) };
            } else {
                throw new IllegalArgumentException("getTextfield takes no arguments");
            }
        }
    });
    luaMethods.add(new LuaMethod("isSensorEventBased") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                return new Object[] { SensorHandler.instance().getSensorFromPath(getSensorSetting()) instanceof IEventSensorSetting };
            } else {
                throw new IllegalArgumentException("isSensorEventBased takes no arguments");
            }
        }
    });
    luaMethods.add(new LuaMethod("getSensorValue") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                ISensorSetting s = SensorHandler.instance().getSensorFromPath(getSensorSetting());
                if (s instanceof IPollSensorSetting) {
                    requestPollPullEvent = true;
                    return new Object[] { redstoneStrength };
                } else if (s != null) {
                    throw new IllegalArgumentException("The selected sensor is pull event based. You can't poll the value.");
                } else {
                    throw new IllegalArgumentException("There's no sensor selected!");
                }
            } else {
                throw new IllegalArgumentException("getSensorValue takes no arguments");
            }
        }
    });
    luaMethods.add(new LuaConstant("getMinWorkingPressure", PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR));
    luaMethods.add(new LuaMethod("setGPSToolCoordinate") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 4) {
                //minus one, as lua is 1-oriented.
                ItemStack stack = getStackInSlot(((Double) args[0]).intValue() - 1);
                if (stack != null && stack.getItem() == Itemss.GPSTool) {
                    ItemGPSTool.setGPSLocation(stack, ((Double) args[1]).intValue(), ((Double) args[2]).intValue(), ((Double) args[3]).intValue());
                    return new Object[] { true };
                } else {
                    return new Object[] { false };
                }
            } else {
                throw new IllegalArgumentException("setGPSToolCoordinate needs 4 arguments: slot, x, y, z");
            }
        }
    });
    luaMethods.add(new LuaMethod("getGPSToolCoordinate") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                //minus one, as lua is 1-oriented.
                ItemStack stack = getStackInSlot(((Double) args[0]).intValue() - 1);
                if (stack != null && stack.getItem() == Itemss.GPSTool) {
                    ChunkPosition pos = ItemGPSTool.getGPSLocation(stack);
                    if (pos != null) {
                        return new Object[] { pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ };
                    } else {
                        return new Object[] { 0, 0, 0 };
                    }
                } else {
                    return null;
                }
            } else {
                throw new IllegalArgumentException("setGPSToolCoordinate needs 1 argument: slot");
            }
        }
    });
}
Also used : IEventSensorSetting(pneumaticCraft.api.universalSensor.IEventSensorSetting) IPollSensorSetting(pneumaticCraft.api.universalSensor.IPollSensorSetting) ChunkPosition(net.minecraft.world.ChunkPosition) ISensorSetting(pneumaticCraft.api.universalSensor.ISensorSetting) LuaMethod(pneumaticCraft.common.thirdparty.computercraft.LuaMethod) LuaConstant(pneumaticCraft.common.thirdparty.computercraft.LuaConstant) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ISensorSetting (pneumaticCraft.api.universalSensor.ISensorSetting)6 ItemStack (net.minecraft.item.ItemStack)2 IEventSensorSetting (pneumaticCraft.api.universalSensor.IEventSensorSetting)2 IPollSensorSetting (pneumaticCraft.api.universalSensor.IPollSensorSetting)2 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 GuiButton (net.minecraft.client.gui.GuiButton)1 ChunkPosition (net.minecraft.world.ChunkPosition)1 PlayerInteractEvent (net.minecraftforge.event.entity.player.PlayerInteractEvent)1 LuaConstant (pneumaticCraft.common.thirdparty.computercraft.LuaConstant)1 LuaMethod (pneumaticCraft.common.thirdparty.computercraft.LuaMethod)1