use of pneumaticCraft.api.item.IProgrammable in project PneumaticCraft by MineMaarten.
the class DroneAIExternalProgram method doBlockInteraction.
@Override
protected boolean doBlockInteraction(ChunkPosition pos, double distToBlock) {
IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
if (inv == null)
return false;
if (curProgramTag != null) {
if (curSlot < inv.getSizeInventory()) {
ItemStack stack = inv.getStackInSlot(curSlot);
if (stack != null && curProgramTag.equals(stack.getTagCompound())) {
subAI.onUpdateTasks();
if (subAI.isIdling() || isRunningSameProgram(subAI.getCurrentAI())) {
curProgramTag = null;
curSlot++;
}
} else {
curProgramTag = null;
subAI.setWidgets(new ArrayList<IProgWidget>());
}
}
return true;
} else {
while (curSlot < inv.getSizeInventory()) {
ItemStack stack = inv.getStackInSlot(curSlot);
if (stack != null && 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 pneumaticCraft.api.item.IProgrammable in project PneumaticCraft by MineMaarten.
the class TileEntityProgrammer method getReturnedPuzzleStacks.
public List<ItemStack> getReturnedPuzzleStacks() {
List<ItemStack> stacks = new ArrayList<ItemStack>();
if (((IProgrammable) inventory[PROGRAM_SLOT].getItem()).usesPieces(inventory[PROGRAM_SLOT])) {
Map<Integer, Integer> tePieces = getPuzzleSummary(progWidgets);
Map<Integer, Integer> dronePieces = getPuzzleSummary(getProgWidgets(inventory[PROGRAM_SLOT]));
for (Integer availableWidget : dronePieces.keySet()) {
Integer requiredWidget = tePieces.get(availableWidget);
if (requiredWidget != null) {
Integer availableWidgets = dronePieces.get(availableWidget);
if (availableWidgets > requiredWidget) {
ItemStack stack = ItemProgrammingPuzzle.getStackForColor(availableWidget);
stack.stackSize = (availableWidgets - requiredWidget) * inventory[PROGRAM_SLOT].stackSize;
while (stack.stackSize > stack.getMaxStackSize()) {
stacks.add(stack.splitStack(stack.getMaxStackSize()));
}
stacks.add(stack);
}
} else {
ItemStack stack = ItemProgrammingPuzzle.getStackForColor(availableWidget);
stack.stackSize = dronePieces.get(availableWidget) * inventory[PROGRAM_SLOT].stackSize;
while (stack.stackSize > stack.getMaxStackSize()) {
stacks.add(stack.splitStack(stack.getMaxStackSize()));
}
stacks.add(stack);
}
}
}
return stacks;
}
use of pneumaticCraft.api.item.IProgrammable 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.api.item.IProgrammable in project PneumaticCraft by MineMaarten.
the class TileEntityProgrammer method getRequiredPuzzleStacks.
public List<ItemStack> getRequiredPuzzleStacks() {
List<ItemStack> stacks = new ArrayList<ItemStack>();
if (((IProgrammable) inventory[PROGRAM_SLOT].getItem()).usesPieces(inventory[PROGRAM_SLOT])) {
Map<Integer, Integer> tePieces = getPuzzleSummary(progWidgets);
Map<Integer, Integer> dronePieces = getPuzzleSummary(getProgWidgets(inventory[PROGRAM_SLOT]));
for (Integer includedWidget : tePieces.keySet()) {
Integer existingWidgets = dronePieces.get(includedWidget);
if (existingWidgets != null) {
Integer neededWidgets = tePieces.get(includedWidget);
if (neededWidgets > existingWidgets) {
ItemStack stack = ItemProgrammingPuzzle.getStackForColor(includedWidget);
stack.stackSize = (neededWidgets - existingWidgets) * inventory[PROGRAM_SLOT].stackSize;
stacks.add(stack);
}
} else {
ItemStack stack = ItemProgrammingPuzzle.getStackForColor(includedWidget);
stack.stackSize = tePieces.get(includedWidget) * inventory[PROGRAM_SLOT].stackSize;
stacks.add(stack);
}
}
}
return stacks;
}
Aggregations