use of pneumaticCraft.common.progwidgets.IProgWidget 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;
}
use of pneumaticCraft.common.progwidgets.IProgWidget 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;
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class ClientEventHandler method onItemTooltip.
@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent event) {
if (event.itemStack.getItem() instanceof IProgrammable) {
IProgrammable programmable = (IProgrammable) event.itemStack.getItem();
if (programmable.canProgram(event.itemStack) && programmable.showProgramTooltip()) {
boolean hasInvalidPrograms = false;
List<String> addedEntries = new ArrayList<String>();
Map<String, Integer> widgetMap = getPuzzleSummary(TileEntityProgrammer.getProgWidgets(event.itemStack));
for (Map.Entry<String, Integer> entry : widgetMap.entrySet()) {
IProgWidget widget = ItemProgrammingPuzzle.getWidgetForName(entry.getKey());
String prefix = "";
GuiScreen curScreen = Minecraft.getMinecraft().currentScreen;
if (curScreen instanceof IGuiDrone) {
if (!((IGuiDrone) curScreen).getDrone().isProgramApplicable(widget)) {
prefix = EnumChatFormatting.RED + "";
hasInvalidPrograms = true;
}
}
addedEntries.add(prefix + "-" + entry.getValue() + "x " + I18n.format("programmingPuzzle." + entry.getKey() + ".name"));
}
if (hasInvalidPrograms) {
event.toolTip.add(EnumChatFormatting.RED + I18n.format("gui.tooltip.programmable.invalidPieces"));
}
Collections.sort(addedEntries);
event.toolTip.addAll(addedEntries);
}
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method handlePuzzleMargins.
private void handlePuzzleMargins() {
//Check for connection to the left of the dragged widget.
Class<? extends IProgWidget> returnValue = draggingWidget.returnType();
if (returnValue != null) {
for (IProgWidget widget : te.progWidgets) {
if (widget != draggingWidget && Math.abs(widget.getX() + widget.getWidth() / 2 - draggingWidget.getX()) <= FAULT_MARGIN) {
Class<? extends IProgWidget>[] parameters = widget.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (widget.canSetParameter(i) && parameters[i] == returnValue && Math.abs(widget.getY() + i * 11 - draggingWidget.getY()) <= FAULT_MARGIN) {
setConnectingWidgetsToXY(draggingWidget, widget.getX() + widget.getWidth() / 2, widget.getY() + i * 11);
return;
}
}
}
}
}
}
//check for connection to the right of the dragged widget.
Class<? extends IProgWidget>[] parameters = draggingWidget.getParameters();
if (parameters != null) {
for (IProgWidget widget : te.progWidgets) {
IProgWidget outerPiece = draggingWidget;
if (outerPiece.returnType() != null) {
//When the piece is a parameter pice (area, item filter, text).
while (outerPiece.getConnectedParameters()[0] != null) {
outerPiece = outerPiece.getConnectedParameters()[0];
}
}
if (widget != draggingWidget && Math.abs(outerPiece.getX() + outerPiece.getWidth() / 2 - widget.getX()) <= FAULT_MARGIN) {
if (widget.returnType() != null) {
for (int i = 0; i < parameters.length; i++) {
if (draggingWidget.canSetParameter(i) && parameters[i] == widget.returnType() && Math.abs(draggingWidget.getY() + i * 11 - widget.getY()) <= FAULT_MARGIN) {
setConnectingWidgetsToXY(draggingWidget, widget.getX() - draggingWidget.getWidth() / 2 - (outerPiece.getX() - draggingWidget.getX()), widget.getY() - i * 11);
}
}
} else {
Class<? extends IProgWidget>[] checkingPieceParms = widget.getParameters();
if (checkingPieceParms != null) {
for (int i = 0; i < checkingPieceParms.length; i++) {
if (widget.canSetParameter(i + parameters.length) && checkingPieceParms[i] == parameters[0] && Math.abs(widget.getY() + i * 11 - draggingWidget.getY()) <= FAULT_MARGIN) {
setConnectingWidgetsToXY(draggingWidget, widget.getX() - draggingWidget.getWidth() / 2 - (outerPiece.getX() - draggingWidget.getX()), widget.getY() + i * 11);
}
}
}
}
}
}
}
//check for connection to the top of the dragged widget.
if (draggingWidget.hasStepInput()) {
for (IProgWidget widget : te.progWidgets) {
if (widget.hasStepOutput() && Math.abs(widget.getX() - draggingWidget.getX()) <= FAULT_MARGIN && Math.abs(widget.getY() + widget.getHeight() / 2 - draggingWidget.getY()) <= FAULT_MARGIN) {
setConnectingWidgetsToXY(draggingWidget, widget.getX(), widget.getY() + widget.getHeight() / 2);
}
}
}
//check for connection to the bottom of the dragged widget.
if (draggingWidget.hasStepOutput()) {
for (IProgWidget widget : te.progWidgets) {
if (widget.hasStepInput() && Math.abs(widget.getX() - draggingWidget.getX()) <= FAULT_MARGIN && Math.abs(widget.getY() - draggingWidget.getY() - draggingWidget.getHeight() / 2) <= FAULT_MARGIN) {
setConnectingWidgetsToXY(draggingWidget, widget.getX(), widget.getY() - draggingWidget.getHeight() / 2);
}
}
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class GuiProgrammer method mouseClicked.
@Override
protected void mouseClicked(int x, int y, int par3) {
ItemStack programmedItem = te.getStackInSlot(TileEntityProgrammer.PROGRAM_SLOT);
if (nameField.isFocused() && programmedItem != null) {
programmedItem.setStackDisplayName(nameField.getText());
NetworkHandler.sendToServer(new PacketUpdateTextfield(te, 0));
}
super.mouseClicked(x, y, par3);
if (par3 == 1 && showingWidgetProgress == 0) {
IProgWidget widget = programmerUnit.getHoveredWidget(x, y);
if (widget != null) {
GuiScreen screen = widget.getOptionWindow(this);
if (screen != null)
mc.displayGuiScreen(screen);
}
}
}
Aggregations