use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
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 pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
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 pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
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 pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
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);
}
use of pneumaticCraft.common.progwidgets.IProgWidget 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;
}
Aggregations