Search in sources :

Example 1 with ProgWidgetArea

use of pneumaticCraft.common.progwidgets.ProgWidgetArea in project PneumaticCraft by MineMaarten.

the class GuiProgrammer method generateRelativeOperators.

/**
     * 
     * @param baseWidget
     * @param simulate
     * @return true if successful
     */
private boolean generateRelativeOperators(ProgWidgetCoordinateOperator baseWidget, List<String> tooltip, boolean simulate) {
    ChunkPosition baseCoord = ProgWidgetCoordinateOperator.calculateCoordinate(baseWidget, 0, baseWidget.getOperator());
    Map<ChunkPosition, String> offsetToVariableNames = new HashMap<ChunkPosition, String>();
    for (IProgWidget widget : te.progWidgets) {
        if (widget instanceof ProgWidgetArea) {
            ProgWidgetArea area = (ProgWidgetArea) widget;
            if (area.getCoord1Variable().equals("") && (area.x1 != 0 || area.y1 != 0 || area.z1 != 0)) {
                ChunkPosition offset = new ChunkPosition(area.x1 - baseCoord.chunkPosX, area.y1 - baseCoord.chunkPosY, area.z1 - baseCoord.chunkPosZ);
                String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
                if (!simulate)
                    area.setCoord1Variable(var);
            }
            if (area.getCoord2Variable().equals("") && (area.x2 != 0 || area.y2 != 0 || area.z2 != 0)) {
                ChunkPosition offset = new ChunkPosition(area.x2 - baseCoord.chunkPosX, area.y2 - baseCoord.chunkPosY, area.z2 - baseCoord.chunkPosZ);
                String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
                if (!simulate)
                    area.setCoord2Variable(var);
            }
        } else if (widget instanceof ProgWidgetCoordinate && baseWidget.getConnectedParameters()[0] != widget) {
            ProgWidgetCoordinate coordinate = (ProgWidgetCoordinate) widget;
            if (!coordinate.isUsingVariable()) {
                ChunkPosition c = coordinate.getCoordinate();
                String chunkString = "(" + c.chunkPosX + ", " + c.chunkPosY + ", " + c.chunkPosZ + ")";
                if (PneumaticCraftUtils.distBetween(c, 0, 0, 0) < 64) {
                    //When the coordinate value is close to 0, there's a low chance it means a position, and rather an offset.
                    if (tooltip != null)
                        tooltip.add(I18n.format("gui.programmer.button.convertToRelative.coordIsNotChangedWarning", chunkString));
                } else {
                    if (tooltip != null)
                        tooltip.add(I18n.format("gui.programmer.button.convertToRelative.coordIsChangedWarning", chunkString));
                    if (!simulate) {
                        ChunkPosition offset = new ChunkPosition(c.chunkPosX - baseCoord.chunkPosX, c.chunkPosY - baseCoord.chunkPosY, c.chunkPosZ - baseCoord.chunkPosZ);
                        String var = getOffsetVariable(offsetToVariableNames, baseWidget.getVariable(), offset);
                        if (!simulate) {
                            coordinate.setVariable(var);
                            coordinate.setUsingVariable(true);
                        }
                    }
                }
            }
        }
    }
    if (offsetToVariableNames.size() > 0) {
        ProgWidgetCoordinateOperator firstOperator = null;
        ProgWidgetCoordinateOperator prevOperator = baseWidget;
        int x = baseWidget.getX();
        for (Map.Entry<ChunkPosition, String> entry : offsetToVariableNames.entrySet()) {
            ProgWidgetCoordinateOperator operator = new ProgWidgetCoordinateOperator();
            operator.setVariable(entry.getValue());
            int y = prevOperator.getY() + prevOperator.getHeight() / 2;
            operator.setX(x);
            operator.setY(y);
            if (!isValidPlaced(operator))
                return false;
            ProgWidgetCoordinate coordinatePiece1 = new ProgWidgetCoordinate();
            coordinatePiece1.setX(x + prevOperator.getWidth() / 2);
            coordinatePiece1.setY(y);
            coordinatePiece1.setVariable(baseWidget.getVariable());
            coordinatePiece1.setUsingVariable(true);
            if (!isValidPlaced(coordinatePiece1))
                return false;
            ProgWidgetCoordinate coordinatePiece2 = new ProgWidgetCoordinate();
            coordinatePiece2.setX(x + prevOperator.getWidth() / 2 + coordinatePiece1.getWidth() / 2);
            coordinatePiece2.setY(y);
            coordinatePiece2.setCoordinate(entry.getKey());
            if (!isValidPlaced(coordinatePiece2))
                return false;
            if (!simulate) {
                te.progWidgets.add(operator);
                te.progWidgets.add(coordinatePiece1);
                te.progWidgets.add(coordinatePiece2);
            }
            if (firstOperator == null)
                firstOperator = operator;
            prevOperator = operator;
        }
        if (!simulate) {
            NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
            TileEntityProgrammer.updatePuzzleConnections(te.progWidgets);
        }
        return true;
    } else {
        //When there's nothing to place there's always room.
        return true;
    }
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) HashMap(java.util.HashMap) ChunkPosition(net.minecraft.world.ChunkPosition) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetCoordinateOperator(pneumaticCraft.common.progwidgets.ProgWidgetCoordinateOperator) PacketProgrammerUpdate(pneumaticCraft.common.network.PacketProgrammerUpdate) ProgWidgetCoordinate(pneumaticCraft.common.progwidgets.ProgWidgetCoordinate) Map(java.util.Map) HashMap(java.util.HashMap) Point(java.awt.Point)

Example 2 with ProgWidgetArea

use of pneumaticCraft.common.progwidgets.ProgWidgetArea in project PneumaticCraft by MineMaarten.

the class ProgWidgetCC method getEntityAreaWidget.

private ProgWidgetArea getEntityAreaWidget() {
    ProgWidgetArea widget = new ProgWidgetArea();
    ChunkPosition minPos = getMinPos();
    ChunkPosition maxPos = getMaxPos();
    widget.x1 = minPos.chunkPosX;
    widget.y1 = minPos.chunkPosY;
    widget.z1 = minPos.chunkPosZ;
    widget.x2 = maxPos.chunkPosX;
    widget.y2 = maxPos.chunkPosY;
    widget.z2 = maxPos.chunkPosZ;
    return widget;
}
Also used : ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ChunkPosition(net.minecraft.world.ChunkPosition)

Example 3 with ProgWidgetArea

use of pneumaticCraft.common.progwidgets.ProgWidgetArea in project PneumaticCraft by MineMaarten.

the class ProgrammedDroneUtils method deliverFluidAmazonStyle.

public static EntityCreature deliverFluidAmazonStyle(World world, int x, int y, int z, FluidStack deliveredFluid) {
    if (world.isRemote)
        return null;
    if (deliveredFluid == null)
        throw new IllegalArgumentException("Can't deliver a null FluidStack");
    if (deliveredFluid.amount <= 0)
        throw new IllegalArgumentException("Can't deliver a FluidStack with an amount of <= 0");
    EntityDrone drone = getChargedDispenserUpgradeDrone(world);
    //Program the drone
    int startY = world.getHeightValue(x + 30, z) + 30;
    drone.setPosition(x + 30, startY, z);
    List<IProgWidget> widgets = drone.progWidgets;
    ProgWidgetStart start = new ProgWidgetStart();
    start.setX(92);
    start.setY(41);
    widgets.add(start);
    ProgWidgetLiquidExport export = new ProgWidgetLiquidExport();
    export.setX(92);
    export.setY(52);
    widgets.add(export);
    ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
    gotoPiece.setX(92);
    gotoPiece.setY(74);
    widgets.add(gotoPiece);
    ProgWidgetSuicide suicide = new ProgWidgetSuicide();
    suicide.setX(92);
    suicide.setY(85);
    widgets.add(suicide);
    ProgWidgetArea area = new ProgWidgetArea();
    area.setX(107);
    area.setY(52);
    area.x1 = x;
    area.y1 = y;
    area.z1 = z;
    widgets.add(area);
    area = new ProgWidgetArea();
    area.setX(107);
    area.setY(74);
    area.x1 = x + 30;
    area.y1 = startY;
    area.z1 = z;
    widgets.add(area);
    TileEntityProgrammer.updatePuzzleConnections(widgets);
    drone.getTank().fill(deliveredFluid, true);
    world.spawnEntityInWorld(drone);
    return drone;
}
Also used : IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ProgWidgetGoToLocation(pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetLiquidExport(pneumaticCraft.common.progwidgets.ProgWidgetLiquidExport) ProgWidgetSuicide(pneumaticCraft.common.progwidgets.ProgWidgetSuicide) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 4 with ProgWidgetArea

use of pneumaticCraft.common.progwidgets.ProgWidgetArea in project PneumaticCraft by MineMaarten.

the class ProgrammedDroneUtils method retrieveItemsAmazonStyle.

public static EntityCreature retrieveItemsAmazonStyle(World world, int x, int y, int z, ItemStack... queriedStacks) {
    if (world.isRemote)
        return null;
    if (queriedStacks.length == 0)
        throw new IllegalArgumentException("You need to query at least 1 stack!");
    if (queriedStacks.length > 65)
        throw new IllegalArgumentException("You can only query up to 65 stacks at once!");
    for (ItemStack stack : queriedStacks) {
        if (stack == null)
            throw new IllegalArgumentException("You can't query a null stack!");
        if (stack.getItem() == null)
            throw new IllegalArgumentException("You can't query a stack with a null item!");
    }
    EntityDrone drone = getChargedDispenserUpgradeDrone(world);
    //Program the drone
    int startY = world.getHeightValue(x + 30, z) + 30;
    drone.setPosition(x + 30, startY, z);
    List<IProgWidget> widgets = drone.progWidgets;
    ProgWidgetStart start = new ProgWidgetStart();
    start.setX(92);
    start.setY(41);
    widgets.add(start);
    int yBase = 52;
    for (ItemStack stack : queriedStacks) {
        ProgWidgetInventoryImport im = new ProgWidgetInventoryImport();
        im.setX(92);
        im.setY(yBase);
        im.setCount(stack.stackSize);
        im.setUseCount(true);
        widgets.add(im);
        ProgWidgetArea area = new ProgWidgetArea();
        area.setX(107);
        area.setY(yBase);
        area.x1 = x;
        area.y1 = y;
        area.z1 = z;
        widgets.add(area);
        ProgWidgetItemFilter filter = new ProgWidgetItemFilter();
        filter.setX(107);
        filter.setY(yBase + 11);
        filter.setFilter(stack);
        filter.useMetadata = true;
        filter.useNBT = true;
        widgets.add(filter);
        yBase += 22;
    }
    ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
    gotoPiece.setX(92);
    gotoPiece.setY(yBase);
    widgets.add(gotoPiece);
    ProgWidgetArea area = new ProgWidgetArea();
    area.setX(107);
    area.setY(yBase);
    area.x1 = x + 30;
    area.y1 = startY;
    area.z1 = z;
    widgets.add(area);
    ProgWidgetSuicide suicide = new ProgWidgetSuicide();
    suicide.setX(92);
    suicide.setY(yBase + 11);
    widgets.add(suicide);
    TileEntityProgrammer.updatePuzzleConnections(widgets);
    world.spawnEntityInWorld(drone);
    return drone;
}
Also used : ProgWidgetInventoryImport(pneumaticCraft.common.progwidgets.ProgWidgetInventoryImport) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ProgWidgetItemFilter(pneumaticCraft.common.progwidgets.ProgWidgetItemFilter) ProgWidgetGoToLocation(pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetSuicide(pneumaticCraft.common.progwidgets.ProgWidgetSuicide) ItemStack(net.minecraft.item.ItemStack) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Example 5 with ProgWidgetArea

use of pneumaticCraft.common.progwidgets.ProgWidgetArea in project PneumaticCraft by MineMaarten.

the class ProgrammedDroneUtils method retrieveFluidAmazonStyle.

public static EntityCreature retrieveFluidAmazonStyle(World world, int x, int y, int z, FluidStack queriedFluid) {
    if (world.isRemote)
        return null;
    if (queriedFluid == null)
        throw new IllegalArgumentException("Can't query a null FluidStack");
    if (queriedFluid.amount <= 0)
        throw new IllegalArgumentException("Can't query a FluidStack with an amount of <= 0");
    EntityDrone drone = getChargedDispenserUpgradeDrone(world);
    //Program the drone
    int startY = world.getHeightValue(x + 30, z) + 30;
    drone.setPosition(x + 30, startY, z);
    List<IProgWidget> widgets = drone.progWidgets;
    ProgWidgetStart start = new ProgWidgetStart();
    start.setX(92);
    start.setY(41);
    widgets.add(start);
    int yBase = 52;
    ProgWidgetLiquidImport im = new ProgWidgetLiquidImport();
    im.setX(92);
    im.setY(yBase);
    im.setCount(queriedFluid.amount);
    im.setUseCount(true);
    widgets.add(im);
    ProgWidgetArea area = new ProgWidgetArea();
    area.setX(107);
    area.setY(yBase);
    area.x1 = x;
    area.y1 = y;
    area.z1 = z;
    widgets.add(area);
    ProgWidgetLiquidFilter filter = new ProgWidgetLiquidFilter();
    filter.setX(107);
    filter.setY(yBase + 11);
    filter.setFluid(queriedFluid.getFluid());
    widgets.add(filter);
    yBase += 22;
    ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
    gotoPiece.setX(92);
    gotoPiece.setY(yBase);
    widgets.add(gotoPiece);
    area = new ProgWidgetArea();
    area.setX(107);
    area.setY(yBase);
    area.x1 = x + 30;
    area.y1 = startY;
    area.z1 = z;
    widgets.add(area);
    ProgWidgetSuicide suicide = new ProgWidgetSuicide();
    suicide.setX(92);
    suicide.setY(yBase + 11);
    widgets.add(suicide);
    TileEntityProgrammer.updatePuzzleConnections(widgets);
    world.spawnEntityInWorld(drone);
    return drone;
}
Also used : ProgWidgetLiquidImport(pneumaticCraft.common.progwidgets.ProgWidgetLiquidImport) IProgWidget(pneumaticCraft.common.progwidgets.IProgWidget) EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) ProgWidgetLiquidFilter(pneumaticCraft.common.progwidgets.ProgWidgetLiquidFilter) ProgWidgetGoToLocation(pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation) ProgWidgetArea(pneumaticCraft.common.progwidgets.ProgWidgetArea) ProgWidgetSuicide(pneumaticCraft.common.progwidgets.ProgWidgetSuicide) ProgWidgetStart(pneumaticCraft.common.progwidgets.ProgWidgetStart)

Aggregations

ProgWidgetArea (pneumaticCraft.common.progwidgets.ProgWidgetArea)8 IProgWidget (pneumaticCraft.common.progwidgets.IProgWidget)5 ProgWidgetStart (pneumaticCraft.common.progwidgets.ProgWidgetStart)5 EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)4 ProgWidgetGoToLocation (pneumaticCraft.common.progwidgets.ProgWidgetGoToLocation)4 ProgWidgetSuicide (pneumaticCraft.common.progwidgets.ProgWidgetSuicide)4 ChunkPosition (net.minecraft.world.ChunkPosition)3 ItemStack (net.minecraft.item.ItemStack)2 Point (java.awt.Point)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 PacketProgrammerUpdate (pneumaticCraft.common.network.PacketProgrammerUpdate)1 ProgWidgetCoordinate (pneumaticCraft.common.progwidgets.ProgWidgetCoordinate)1 ProgWidgetCoordinateOperator (pneumaticCraft.common.progwidgets.ProgWidgetCoordinateOperator)1 ProgWidgetDropItem (pneumaticCraft.common.progwidgets.ProgWidgetDropItem)1 ProgWidgetInventoryExport (pneumaticCraft.common.progwidgets.ProgWidgetInventoryExport)1 ProgWidgetInventoryImport (pneumaticCraft.common.progwidgets.ProgWidgetInventoryImport)1 ProgWidgetItemFilter (pneumaticCraft.common.progwidgets.ProgWidgetItemFilter)1 ProgWidgetLiquidExport (pneumaticCraft.common.progwidgets.ProgWidgetLiquidExport)1