use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class DroneAIManager method setActiveWidget.
private void setActiveWidget(IProgWidget widget) {
EntityAIBase targetAI = null;
EntityAIBase ai = null;
if (widget != null) {
boolean first = widget instanceof ProgWidgetStart;
targetAI = widget.getWidgetTargetAI(drone, widget);
ai = widget.getWidgetAI(drone, widget);
//Prevent endless loops
Set<IProgWidget> visitedWidgets = new HashSet<IProgWidget>();
while (!visitedWidgets.contains(widget) && targetAI == null && ai == null) {
visitedWidgets.add(widget);
IProgWidget oldWidget = widget;
widget = widget.getOutputWidget(drone, progWidgets);
if (widget == null) {
if (first) {
return;
} else {
if (stopWhenEndReached) {
setActiveWidget(null);
} else {
gotoFirstWidget();
}
return;
}
} else if (oldWidget.getOutputWidget() != widget) {
if (addJumpBackWidget(oldWidget))
return;
}
targetAI = widget.getWidgetTargetAI(drone, widget);
ai = widget.getWidgetAI(drone, widget);
}
drone.setActiveProgram(widget);
} else {
setLabel("Stopped");
}
curActiveWidget = widget;
if (curWidgetAI != null)
removeTask(curWidgetAI);
if (curWidgetTargetAI != null)
drone.getTargetAI().removeTask(curWidgetTargetAI);
if (ai != null)
addTask(2, ai);
if (targetAI != null)
drone.getTargetAI().addTask(2, targetAI);
curWidgetAI = ai;
curWidgetTargetAI = targetAI;
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class ItemProgrammingPuzzle method getWidgetForPiece.
public static IProgWidget getWidgetForPiece(ItemStack stack) {
if (NBTUtil.hasTag(stack, "type")) {
//TODO legacy remove
String type = stack.getTagCompound().getString("type");
for (IProgWidget widget : WidgetRegistrator.registeredWidgets) {
if (widget.getWidgetString().equals(type))
return widget;
}
Exception e = new IllegalArgumentException("No widget registered with the name " + type + "! This is not possible?!");
e.printStackTrace();
return null;
} else {
List<IProgWidget> widgets = getWidgetsForColor(stack.getItemDamage());
if (widgets.size() > 0) {
World world = PneumaticCraft.proxy.getClientWorld();
return widgets.get((int) (world.getTotalWorldTime() % (widgets.size() * 20) / 20));
} else {
return null;
}
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class PacketSyncDroneEntityProgWidgets method handleClientSide.
@Override
public void handleClientSide(PacketSyncDroneEntityProgWidgets message, EntityPlayer player) {
Entity entity = player.worldObj.getEntityByID(message.entityId);
if (entity instanceof EntityDrone) {
EntityDrone drone = (EntityDrone) entity;
List<IProgWidget> widgets = drone.getProgWidgets();
widgets.clear();
widgets.addAll(message.progWidgets);
}
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class ProgrammedDroneUtils method deliverItemsAmazonStyle.
public static EntityCreature deliverItemsAmazonStyle(World world, int x, int y, int z, ItemStack... deliveredStacks) {
if (world.isRemote)
return null;
if (deliveredStacks.length == 0)
throw new IllegalArgumentException("You need to deliver at least 1 stack!");
if (deliveredStacks.length > 65)
throw new IllegalArgumentException("You can only deliver up to 65 stacks at once!");
for (ItemStack stack : deliveredStacks) {
if (stack == null)
throw new IllegalArgumentException("You can't supply a null stack to be delivered!");
if (stack.getItem() == null)
throw new IllegalArgumentException("You can't supply a stack with a null item to be delivered!");
}
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);
ProgWidgetInventoryExport export = new ProgWidgetInventoryExport();
export.setX(92);
export.setY(52);
widgets.add(export);
ProgWidgetDropItem drop = new ProgWidgetDropItem();
drop.setX(92);
drop.setY(74);
widgets.add(drop);
ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
gotoPiece.setX(92);
gotoPiece.setY(96);
widgets.add(gotoPiece);
ProgWidgetSuicide suicide = new ProgWidgetSuicide();
suicide.setX(92);
suicide.setY(107);
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;
area.z1 = z;
if (drone.isBlockValidPathfindBlock(x, y, z)) {
for (int i = 0; i < 5 && drone.isBlockValidPathfindBlock(area.x1, i + y + 1, area.z1); i++) {
area.y1 = y + i;
}
} else {
area.y1 = world.getHeightValue(x, z) + 10;
//Worst case scenario, there are definately no blocks here.
if (!drone.isBlockValidPathfindBlock(area.x1, area.y1, area.z1))
area.y1 = 260;
}
widgets.add(area);
area = new ProgWidgetArea();
area.setX(107);
area.setY(96);
area.x1 = x + 30;
area.y1 = startY;
area.z1 = z;
widgets.add(area);
TileEntityProgrammer.updatePuzzleConnections(widgets);
for (int i = 0; i < deliveredStacks.length; i++) {
drone.getInventory().setInventorySlotContents(i, deliveredStacks[i].copy());
}
world.spawnEntityInWorld(drone);
return drone;
}
use of pneumaticCraft.common.progwidgets.IProgWidget in project PneumaticCraft by MineMaarten.
the class TileEntityProgrammer method getWidgetsFromNBT.
public static void getWidgetsFromNBT(NBTTagCompound tag, List<IProgWidget> progWidgets) {
NBTTagList widgetTags = tag.getTagList("widgets", 10);
for (int i = 0; i < widgetTags.tagCount(); i++) {
NBTTagCompound widgetTag = widgetTags.getCompoundTagAt(i);
String widgetName = widgetTag.getString("name");
for (IProgWidget widget : WidgetRegistrator.registeredWidgets) {
if (widgetName.equals(widget.getWidgetString())) {
//create the right progWidget for the given id tag.
IProgWidget addedWidget = widget.copy();
addedWidget.readFromNBT(widgetTag);
progWidgets.add(addedWidget);
break;
}
}
}
updatePuzzleConnections(progWidgets);
}
Aggregations