use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.
the class TileEntityProgrammer method updatePuzzleConnections.
public static void updatePuzzleConnections(List<IProgWidget> progWidgets) {
for (IProgWidget widget : progWidgets) {
widget.setParent(null);
Class<? extends IProgWidget>[] parameters = widget.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.length * 2; i++) {
widget.setParameter(i, null);
}
}
if (widget.hasStepOutput())
widget.setOutputWidget(null);
}
for (IProgWidget checkedWidget : progWidgets) {
// check for connection to the right of the checked widget.
Class<? extends IProgWidget>[] parameters = checkedWidget.getParameters();
if (parameters != null) {
for (IProgWidget widget : progWidgets) {
if (widget != checkedWidget && checkedWidget.getX() + checkedWidget.getWidth() / 2 == widget.getX()) {
for (int i = 0; i < parameters.length; i++) {
if (checkedWidget.canSetParameter(i) && parameters[i] == widget.returnType() && checkedWidget.getY() + i * 11 == widget.getY()) {
checkedWidget.setParameter(i, widget);
widget.setParent(checkedWidget);
}
}
}
}
}
// check for connection to the bottom of the checked widget.
if (checkedWidget.hasStepOutput()) {
for (IProgWidget widget : progWidgets) {
if (widget.hasStepInput() && widget.getX() == checkedWidget.getX() && widget.getY() == checkedWidget.getY() + checkedWidget.getHeight() / 2) {
checkedWidget.setOutputWidget(widget);
}
}
}
}
// go again for the blacklist (as those are mirrored)
for (IProgWidget checkedWidget : progWidgets) {
if (checkedWidget.returnType() == null) {
// if it's a program (import/export inventory, attack entity) rather than a parameter (area, item filter).
Class<? extends IProgWidget>[] parameters = checkedWidget.getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (checkedWidget.canSetParameter(i)) {
for (IProgWidget widget : progWidgets) {
if (parameters[i] == widget.returnType()) {
if (widget != checkedWidget && widget.getX() + widget.getWidth() / 2 == checkedWidget.getX() && widget.getY() == checkedWidget.getY() + i * 11) {
IProgWidget root = widget;
while (root.getParent() != null) {
root = root.getParent();
}
checkedWidget.setParameter(i + parameters.length, root);
}
}
}
}
}
}
}
}
}
use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.
the class TileEntityProgrammer method getAllVariables.
/**
* Returns a set with all variables that are used in the program.
*
* @return
*/
public Set<String> getAllVariables() {
Set<String> variables = new HashSet<String>();
for (IProgWidget widget : progWidgets) {
if (widget instanceof IVariableWidget)
((IVariableWidget) widget).addVariables(variables);
}
variables.remove("");
return variables;
}
use of me.desht.pneumaticcraft.common.progwidgets.IProgWidget in project pnc-repressurized by TeamPneumatic.
the class TileEntityProgrammer method setWidgetsToNBT.
public static void setWidgetsToNBT(List<IProgWidget> widgets, NBTTagCompound tag) {
NBTTagList widgetTags = new NBTTagList();
for (IProgWidget widget : widgets) {
NBTTagCompound widgetTag = new NBTTagCompound();
widget.writeToNBT(widgetTag);
widgetTags.appendTag(widgetTag);
}
tag.setTag("widgets", widgetTags);
}
Aggregations