use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.
the class DroneAIManager method setWidgets.
public void setWidgets(List<IProgWidget> progWidgets) {
this.progWidgets = progWidgets;
for (IProgWidget widget : progWidgets) {
if (widget instanceof IVariableWidget) {
((IVariableWidget) widget).setAIManager(this);
}
}
gotoFirstWidget();
}
use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.
the class DroneAIExternalProgram method doBlockInteraction.
@Override
protected boolean doBlockInteraction(BlockPos pos, double distToBlock) {
IItemHandler inv = IOHelper.getInventoryForTE(drone.world().getTileEntity(pos));
if (inv == null)
return false;
if (curProgramTag != null) {
if (curSlot < inv.getSlots()) {
ItemStack stack = inv.getStackInSlot(curSlot);
if (curProgramTag.equals(stack.getTagCompound())) {
subAI.onUpdateTasks();
if (subAI.isIdling() || isRunningSameProgram(subAI.getCurrentAI())) {
curProgramTag = null;
curSlot++;
}
} else {
curProgramTag = null;
subAI.setWidgets(new ArrayList<>());
}
}
return true;
} else {
while (curSlot < inv.getSlots()) {
ItemStack stack = inv.getStackInSlot(curSlot);
if (stack.getItem() instanceof IProgrammable) {
IProgrammable programmable = (IProgrammable) stack.getItem();
if (programmable.canProgram(stack) && programmable.usesPieces(stack)) {
List<IProgWidget> widgets = TileEntityProgrammer.getProgWidgets(stack);
boolean areWidgetsValid = true;
for (IProgWidget widget : widgets) {
if (!drone.isProgramApplicable(widget)) {
areWidgetsValid = false;
break;
}
}
if (areWidgetsValid) {
if (widget.shareVariables)
mainAI.connectVariables(subAI);
subAI.getDrone().getAIManager().setLabel("Main");
subAI.setWidgets(widgets);
curProgramTag = stack.getTagCompound();
if (!subAI.isIdling()) {
return true;
}
}
}
}
curSlot++;
}
return false;
}
}
use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.
the class PacketSyncDroneEntityProgWidgets method handleClientSide.
@Override
public void handleClientSide(PacketSyncDroneEntityProgWidgets message, EntityPlayer player) {
Entity entity = player.world.getEntityByID(message.entityId);
if (entity instanceof EntityDrone) {
EntityDrone drone = (EntityDrone) entity;
List<IProgWidget> widgets = drone.getProgWidgets();
widgets.clear();
widgets.addAll(message.progWidgets);
}
}
use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.
the class GuiProgrammer method actionPerformed.
/**
* Fired when a control is clicked. This is the equivalent of
* ActionListener.actionPerformed(ActionEvent e).
*/
@Override
protected void actionPerformed(GuiButton button) {
switch(button.id) {
case // redstone button
0:
// redstoneBehaviourStat.closeWindow();
break;
case 3:
if (--widgetPage < 0)
widgetPage = maxPage;
updateVisibleProgWidgets();
return;
case 4:
if (++widgetPage > maxPage)
widgetPage = 0;
updateVisibleProgWidgets();
return;
case 5:
for (IProgWidget widget : te.progWidgets) {
if (widget instanceof ProgWidgetStart) {
programmerUnit.gotoPiece(widget);
break;
}
}
return;
case 6:
if (te.progWidgets.size() > 0) {
programmerUnit.gotoPiece(te.progWidgets.get(te.progWidgets.size() - 1));
}
return;
case 7:
NBTTagCompound mainTag = new NBTTagCompound();
te.writeProgWidgetsToNBT(mainTag);
FMLClientHandler.instance().showGuiScreen(pastebinGui = new GuiPastebin(this, mainTag));
break;
case 11:
te.progWidgets.clear();
NetworkHandler.sendToServer(new PacketProgrammerUpdate(te));
break;
case 12:
for (IProgWidget widget : te.progWidgets) {
if (widget instanceof ProgWidgetStart) {
generateRelativeOperators((ProgWidgetCoordinateOperator) widget.getOutputWidget(), null, false);
break;
}
}
break;
}
NetworkHandler.sendToServer(new PacketGuiButton(button.id));
}
use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.
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);
}
}
}
}
Aggregations