Search in sources :

Example 1 with ISensorSetting

use of me.desht.pneumaticcraft.api.universalSensor.ISensorSetting in project pnc-repressurized by TeamPneumatic.

the class TileEntityUniversalSensor method onEvent.

public void onEvent(Event event) {
    ISensorSetting sensor = SensorHandler.getInstance().getSensorFromPath(sensorSetting);
    if (sensor != null && sensor instanceof IEventSensorSetting && getPressure() > PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR) {
        int newRedstoneStrength = ((IEventSensorSetting) sensor).emitRedstoneOnEvent(event, this, getRange(), sensorGuiText);
        if (newRedstoneStrength != 0)
            eventTimer = ((IEventSensorSetting) sensor).getRedstonePulseLength();
        if (invertedRedstone)
            newRedstoneStrength = 15 - newRedstoneStrength;
        if (eventTimer > 0 && ThirdPartyManager.computerCraftLoaded) {
            if (event instanceof PlayerInteractEvent) {
                PlayerInteractEvent e = (PlayerInteractEvent) event;
                notifyComputers(newRedstoneStrength, e.getPos().getX(), e.getPos().getY(), e.getPos().getZ());
            } else {
                notifyComputers(newRedstoneStrength);
            }
        }
        if (newRedstoneStrength != redstoneStrength) {
            redstoneStrength = newRedstoneStrength;
            updateNeighbours();
        }
    }
}
Also used : IEventSensorSetting(me.desht.pneumaticcraft.api.universalSensor.IEventSensorSetting) ISensorSetting(me.desht.pneumaticcraft.api.universalSensor.ISensorSetting) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent)

Example 2 with ISensorSetting

use of me.desht.pneumaticcraft.api.universalSensor.ISensorSetting in project pnc-repressurized by TeamPneumatic.

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.getInstance().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;
                if (args[0] instanceof String) {
                    sensor = SensorHandler.getInstance().getSensorForName((String) args[0]);
                } else {
                    sensor = SensorHandler.getInstance().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.getInstance().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.getInstance().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.getInstance().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 = upgradeHandler.getStackInSlot(((Double) args[0]).intValue() - 1);
                if (stack.getItem() == Itemss.GPS_TOOL) {
                    ItemGPSTool.setGPSLocation(stack, new BlockPos((Double) args[1], (Double) args[2], (Double) args[3]));
                    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 = upgradeHandler.getStackInSlot(((Double) args[0]).intValue() - 1);
                if (stack.getItem() == Itemss.GPS_TOOL) {
                    BlockPos pos = ItemGPSTool.getGPSLocation(stack);
                    if (pos != null) {
                        return new Object[] { pos.getX(), pos.getY(), pos.getZ() };
                    } else {
                        return new Object[] { 0, 0, 0 };
                    }
                } else {
                    return null;
                }
            } else {
                throw new IllegalArgumentException("setGPSToolCoordinate needs 1 argument: slot");
            }
        }
    });
}
Also used : IEventSensorSetting(me.desht.pneumaticcraft.api.universalSensor.IEventSensorSetting) IPollSensorSetting(me.desht.pneumaticcraft.api.universalSensor.IPollSensorSetting) ISensorSetting(me.desht.pneumaticcraft.api.universalSensor.ISensorSetting) LuaMethod(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod) LuaConstant(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaConstant) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ISensorSetting

use of me.desht.pneumaticcraft.api.universalSensor.ISensorSetting in project pnc-repressurized by TeamPneumatic.

the class TileEntityUniversalSensor method update.

@Override
public void update() {
    oldDishRotation = dishRotation;
    if (isSensorActive) {
        dishSpeed = Math.min(dishSpeed + 0.2F, 10);
    } else {
        dishSpeed = Math.max(dishSpeed - 0.2F, 0);
    }
    dishRotation += dishSpeed;
    if (getWorld().isRemote) {
        int sensorRange = getRange();
        if (oldSensorRange != sensorRange || oldSensorRange == 0) {
            oldSensorRange = sensorRange;
            if (!firstRun)
                rangeLineRenderer.resetRendering(sensorRange);
        }
        rangeLineRenderer.update();
    }
    super.update();
    if (!getWorld().isRemote) {
        ticksExisted++;
        ISensorSetting sensor = SensorHandler.getInstance().getSensorFromPath(sensorSetting);
        if (sensor != null && getPressure() > PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR) {
            isSensorActive = true;
            addAir(-PneumaticValues.USAGE_UNIVERSAL_SENSOR);
            if (sensor instanceof IPollSensorSetting) {
                if (ticksExisted % ((IPollSensorSetting) sensor).getPollFrequency(this) == 0) {
                    int newRedstoneStrength = ((IPollSensorSetting) sensor).getRedstoneValue(getWorld(), getPos(), 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(me.desht.pneumaticcraft.api.universalSensor.ISensorSetting) IPollSensorSetting(me.desht.pneumaticcraft.api.universalSensor.IPollSensorSetting)

Example 4 with ISensorSetting

use of me.desht.pneumaticcraft.api.universalSensor.ISensorSetting in project pnc-repressurized by TeamPneumatic.

the class GuiUniversalSensor method drawGuiContainerBackgroundLayer.

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

Example 5 with ISensorSetting

use of me.desht.pneumaticcraft.api.universalSensor.ISensorSetting in project pnc-repressurized by TeamPneumatic.

the class GuiUniversalSensor method getSensorInfo.

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

Aggregations

ISensorSetting (me.desht.pneumaticcraft.api.universalSensor.ISensorSetting)6 IEventSensorSetting (me.desht.pneumaticcraft.api.universalSensor.IEventSensorSetting)2 IPollSensorSetting (me.desht.pneumaticcraft.api.universalSensor.IPollSensorSetting)2 ItemStack (net.minecraft.item.ItemStack)2 ArrayList (java.util.ArrayList)1 LuaConstant (me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaConstant)1 LuaMethod (me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod)1 GuiButton (net.minecraft.client.gui.GuiButton)1 Item (net.minecraft.item.Item)1 BlockPos (net.minecraft.util.math.BlockPos)1 PlayerInteractEvent (net.minecraftforge.event.entity.player.PlayerInteractEvent)1