use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class MultiblockInfoRecipeWrapper method initializePattern.
private MBPattern initializePattern(MultiblockShapeInfo shapeInfo, Set<ItemStackKey> blockDrops) {
Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
BlockInfo[][][] blocks = shapeInfo.getBlocks();
for (int z = 0; z < blocks.length; z++) {
BlockInfo[][] aisle = blocks[z];
for (int y = 0; y < aisle.length; y++) {
BlockInfo[] column = aisle[y];
for (int x = 0; x < column.length; x++) {
BlockPos blockPos = new BlockPos(x, y, z);
BlockInfo blockInfo = column[x];
blockMap.put(blockPos, blockInfo);
}
}
}
WorldSceneRenderer worldSceneRenderer = new WorldSceneRenderer(blockMap);
worldSceneRenderer.world.updateEntities();
HashMap<ItemStackKey, PartInfo> partsMap = new HashMap<>();
gatherBlockDrops(worldSceneRenderer.world, blockMap, blockDrops, partsMap);
worldSceneRenderer.setRenderCallback(this);
worldSceneRenderer.setRenderFilter(this::shouldDisplayBlock);
ArrayList<PartInfo> partInfos = new ArrayList<>(partsMap.values());
partInfos.sort((one, two) -> {
if (one.isController)
return -1;
if (two.isController)
return +1;
if (one.isTile && !two.isTile)
return -1;
if (two.isTile && !one.isTile)
return +1;
if (one.blockId != two.blockId)
return two.blockId - one.blockId;
return two.amount - one.amount;
});
ArrayList<ItemStack> parts = new ArrayList<>();
for (PartInfo partInfo : partInfos) {
parts.add(partInfo.getItemStack());
}
return new MBPattern(worldSceneRenderer, parts);
}
use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class CoverConveyor method countInventoryItemsByMatchSlot.
protected Map<Object, GroupItemInfo> countInventoryItemsByMatchSlot(IItemHandler inventory) {
HashMap<Object, GroupItemInfo> result = new HashMap<>();
for (int srcIndex = 0; srcIndex < inventory.getSlots(); srcIndex++) {
ItemStack itemStack = inventory.getStackInSlot(srcIndex);
if (itemStack.isEmpty()) {
continue;
}
Object transferSlotIndex = itemFilterContainer.matchItemStack(itemStack);
if (transferSlotIndex == null) {
continue;
}
ItemStackKey itemStackKey = new ItemStackKey(itemStack);
if (!result.containsKey(transferSlotIndex)) {
GroupItemInfo itemInfo = new GroupItemInfo(transferSlotIndex, new HashSet<>(), 0);
itemInfo.itemStackTypes.add(itemStackKey);
itemInfo.totalCount += itemStack.getCount();
result.put(transferSlotIndex, itemInfo);
} else {
GroupItemInfo itemInfo = result.get(transferSlotIndex);
itemInfo.itemStackTypes.add(itemStackKey);
itemInfo.totalCount += itemStack.getCount();
}
}
return result;
}
use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class CoverRoboticArm method doTransferExact.
protected int doTransferExact(IItemHandler itemHandler, IItemHandler myItemHandler, int maxTransferAmount) {
Map<ItemStackKey, TypeItemInfo> sourceItemAmount = doCountSourceInventoryItemsByType(itemHandler, myItemHandler);
Iterator<ItemStackKey> iterator = sourceItemAmount.keySet().iterator();
while (iterator.hasNext()) {
ItemStackKey key = iterator.next();
TypeItemInfo sourceInfo = sourceItemAmount.get(key);
int itemAmount = sourceInfo.totalCount;
Set<ItemStackKey> matchedItems = Collections.singleton(key);
int itemToMoveAmount = itemFilterContainer.getSlotTransferLimit(sourceInfo.filterSlot, matchedItems);
if (itemAmount >= itemToMoveAmount) {
sourceInfo.totalCount = itemToMoveAmount;
} else {
iterator.remove();
}
}
int itemsTransferred = 0;
int maxTotalTransferAmount = maxTransferAmount + itemsTransferBuffered;
boolean notEnoughTransferRate = false;
for (TypeItemInfo itemInfo : sourceItemAmount.values()) {
if (maxTotalTransferAmount >= itemInfo.totalCount) {
boolean result = doTransferItemsExact(itemHandler, myItemHandler, itemInfo);
itemsTransferred += result ? itemInfo.totalCount : 0;
maxTotalTransferAmount -= result ? itemInfo.totalCount : 0;
} else {
notEnoughTransferRate = true;
}
}
// if we didn't transfer anything because of too small transfer rate, buffer it
if (itemsTransferred == 0 && notEnoughTransferRate) {
itemsTransferBuffered += maxTransferAmount;
} else {
// otherwise, if transfer succeed, empty transfer buffer value
itemsTransferBuffered = 0;
}
return Math.min(itemsTransferred, maxTransferAmount);
}
use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class CachedRecipeData method performRecipe.
public boolean performRecipe(EntityPlayer player) {
this.lastTickChecked = -1L;
if (!checkRecipeValid()) {
return false;
}
if (!consumeRecipeItems(false)) {
this.lastTickChecked = -1L;
return false;
}
ForgeHooks.setCraftingPlayer(player);
InventoryCrafting deepCopy = InventoryUtils.deepCopyInventoryCrafting(inventory);
NonNullList<ItemStack> remainingItems = recipe.getRemainingItems(deepCopy);
ForgeHooks.setCraftingPlayer(null);
for (ItemStack itemStack : remainingItems) {
itemStack = itemStack.copy();
ItemStackKey stackKey = new ItemStackKey(itemStack);
int remainingAmount = itemStack.getCount() - itemSourceList.insertItem(stackKey, itemStack.getCount(), false, InsertMode.HIGHEST_PRIORITY);
if (remainingAmount > 0) {
itemStack.setCount(remainingAmount);
player.addItemStackToInventory(itemStack);
if (itemStack.getCount() > 0) {
player.dropItem(itemStack, false, false);
}
}
}
this.lastTickChecked = -1L;
return true;
}
use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class ItemSourceList method removeItemHandler.
public void removeItemHandler(ItemSource handlerInfo) {
if (this.handlerInfoList.remove(handlerInfo)) {
handlerInfo.setStoredItemsChangeCallback(null);
handlerInfo.setInvalidationCallback(null);
for (ItemStackKey itemStackKey : itemInfoMap.keySet()) {
NetworkItemInfo itemInfo = itemInfoMap.get(itemStackKey);
itemInfo.removeInventory(handlerInfo);
}
removeItemHandlerPost(handlerInfo);
}
}
Aggregations