use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class ModuleCCBasedQuickSort method tick.
@Override
public void tick() {
IInventoryUtil invUtil = _service.getPointedInventory(true);
if (invUtil == null) {
return;
}
handleSinkResponses(invUtil);
if (--currentTick > 0) {
return;
}
if (stalled) {
currentTick = stalledDelay;
} else {
currentTick = normalDelay;
}
if (!_service.canUseEnergy(500)) {
stalled = true;
return;
}
if ((!(invUtil instanceof SpecialInventoryHandler) && invUtil.getSizeInventory() == 0) || !_service.canUseEnergy(500)) {
stalled = true;
return;
}
//incremented at the end of the previous loop.
if (lastStackLookedAt >= invUtil.getSizeInventory()) {
lastStackLookedAt = 0;
}
ItemStack slot = invUtil.getStackInSlot(lastStackLookedAt);
while (slot == null) {
lastStackLookedAt++;
if (lastStackLookedAt >= invUtil.getSizeInventory()) {
lastStackLookedAt = 0;
}
slot = invUtil.getStackInSlot(lastStackLookedAt);
if (lastStackLookedAt == lastSuceededStack) {
stalled = true;
send();
// then we have been around the list without sending, halt for now
return;
}
}
send();
if (!sinkResponses.containsKey(lastStackLookedAt)) {
createSinkMessage(lastStackLookedAt, ItemIdentifierStack.getFromStack(slot));
}
lastStackLookedAt++;
checkSize();
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class NEISetCraftingRecipe method writeData.
@Override
public void writeData(LPDataOutput output) {
super.writeData(output);
output.writeInt(content.length);
for (int i = 0; i < content.length; i++) {
final ItemStack itemstack = content[i];
if (itemstack != null) {
output.writeByte(i);
output.writeInt(Item.getIdFromItem(itemstack.getItem()));
output.writeInt(itemstack.stackSize);
output.writeInt(itemstack.getItemDamage());
output.writeNBTTagCompound(itemstack.getTagCompound());
}
}
// mark packet end
output.writeByte(-1);
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class ModuleInHandGuiProvider method getLogisticsModule.
public final LogisticsModule getLogisticsModule(EntityPlayer player) {
ItemStack item = player.inventory.mainInventory[invSlot];
if (item == null) {
return null;
}
LogisticsModule module = LogisticsPipes.ModuleItem.getModuleForItem(item, null, new DummyWorldProvider(player.getEntityWorld()), null);
module.registerPosition(ModulePositionType.IN_HAND, invSlot);
ItemModuleInformationManager.readInformation(item, module);
return module;
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class LogisticsCraftingOverlayHandler method overlayRecipe.
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
TileEntity tile;
LogisticsBaseGuiScreen gui;
if (firstGui instanceof GuiLogisticsCraftingTable) {
tile = ((GuiLogisticsCraftingTable) firstGui)._crafter;
gui = (GuiLogisticsCraftingTable) firstGui;
} else if (firstGui instanceof GuiRequestTable) {
tile = ((GuiRequestTable) firstGui)._table.container;
gui = (GuiRequestTable) firstGui;
} else {
return;
}
ItemStack[] stack = new ItemStack[9];
ItemStack[][] stacks = new ItemStack[9][];
boolean hasCanidates = false;
NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
for (PositionedStack ps : recipe.getIngredientStacks(recipeIndex)) {
int x = (ps.relx - 25) / 18;
int y = (ps.rely - 6) / 18;
int slot = x + y * 3;
if (x < 0 || x > 2 || y < 0 || y > 2 || slot < 0 || slot > 8) {
FMLClientHandler.instance().getClient().thePlayer.sendChatMessage("Internal Error. This button is broken.");
return;
}
if (slot < 9) {
stack[slot] = ps.items[0];
List<ItemStack> list = new ArrayList<>(Arrays.asList(ps.items));
Iterator<ItemStack> iter = list.iterator();
while (iter.hasNext()) {
ItemStack wildCardCheckStack = iter.next();
if (wildCardCheckStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
iter.remove();
wildCardCheckStack.getItem().getSubItems(wildCardCheckStack.getItem(), wildCardCheckStack.getItem().getCreativeTab(), list);
iter = list.iterator();
}
}
stacks[slot] = list.toArray(new ItemStack[0]);
if (stacks[slot].length > 1) {
hasCanidates = true;
} else if (stacks[slot].length == 1) {
stack[slot] = stacks[slot][0];
}
}
}
if (hasCanidates) {
gui.setSubGui(new GuiRecipeImport(tile, stacks));
} else {
MainProxy.sendPacketToServer(packet.setContent(stack).setPosX(tile.xCoord).setPosY(tile.yCoord).setPosZ(tile.zCoord));
}
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class PipeItemsProviderLogistics method sendStack.
private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
ItemIdentifier item = stack.getItem();
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
//@formatter:off
Iterator<Pair<IInventoryUtil, ForgeDirection>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>(getAdaptedInventoryUtil(adjacent), adjacent.direction)).iterator();
while (iterator.hasNext()) {
Pair<IInventoryUtil, ForgeDirection> next = iterator.next();
int available = next.getValue1().itemCount(item);
if (available == 0) {
continue;
}
int wanted = Math.min(available, stack.getStackSize());
wanted = Math.min(wanted, maxCount);
wanted = Math.min(wanted, item.getMaxStackSize());
IRouter dRtr = SimpleServiceLocator.routerManager.getRouterUnsafe(destination, false);
if (dRtr == null) {
_orderManager.sendFailed();
return 0;
}
SinkReply reply = LogisticsManager.canSink(dRtr, null, true, stack.getItem(), null, true, false);
boolean defersend = false;
if (reply != null) {
// some pipes are not aware of the space in the adjacent inventory, so they return null
if (reply.maxNumberOfItems < wanted) {
wanted = reply.maxNumberOfItems;
if (wanted <= 0) {
_orderManager.deferSend();
return 0;
}
defersend = true;
}
}
if (!canUseEnergy(wanted * neededEnergy())) {
return -1;
}
ItemStack removed = next.getValue1().getMultipleItems(item, wanted);
if (removed == null || removed.stackSize == 0) {
continue;
}
int sent = removed.stackSize;
useEnergy(sent * neededEnergy());
IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(removed);
routedItem.setDestination(destination);
routedItem.setTransportMode(TransportMode.Active);
routedItem.setAdditionalTargetInformation(info);
super.queueRoutedItem(routedItem, next.getValue2());
_orderManager.sendSuccessfull(sent, defersend, routedItem);
return sent;
}
_orderManager.sendFailed();
return 0;
}
Aggregations