use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class MultiblockInfoRecipeWrapper method gatherBlockDrops.
private static void gatherBlockDrops(World world, Map<BlockPos, BlockInfo> blocks, Set<ItemStackKey> drops, Map<ItemStackKey, PartInfo> partsMap) {
NonNullList<ItemStack> dropsList = NonNullList.create();
for (Entry<BlockPos, BlockInfo> entry : blocks.entrySet()) {
BlockPos pos = entry.getKey();
IBlockState blockState = world.getBlockState(pos);
NonNullList<ItemStack> blockDrops = NonNullList.create();
blockState.getBlock().getDrops(blockDrops, world, pos, blockState, 0);
dropsList.addAll(blockDrops);
for (ItemStack itemStack : blockDrops) {
ItemStackKey itemStackKey = new ItemStackKey(itemStack);
PartInfo partInfo = partsMap.get(itemStackKey);
if (partInfo == null) {
partInfo = new PartInfo(itemStackKey, entry.getValue());
partsMap.put(itemStackKey, partInfo);
}
++partInfo.amount;
}
}
for (ItemStack itemStack : dropsList) {
drops.add(new ItemStackKey(itemStack));
}
}
use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class ItemListGridWidget method readUpdateInfo.
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
super.readUpdateInfo(id, buffer);
if (id == 2) {
int slotsToAdd = buffer.readVarInt();
modifySlotRows(slotsToAdd);
}
if (id == 3) {
try {
int itemsRemoved = buffer.readVarInt();
for (int i = 0; i < itemsRemoved; i++) {
ItemStackKey itemStack = new ItemStackKey(buffer.readItemStack());
this.displayItemList.removeIf(it -> it.getItemStackKey().equals(itemStack));
}
int itemsChanged = buffer.readVarInt();
for (int i = 0; i < itemsChanged; i++) {
ItemStackKey itemStack = new ItemStackKey(buffer.readItemStack());
int newTotalAmount = buffer.readVarInt();
SimpleItemInfo itemInfo = displayItemList.stream().filter(it -> it.getItemStackKey().equals(itemStack)).findAny().orElse(null);
if (itemInfo == null) {
itemInfo = new SimpleItemInfo(itemStack);
this.displayItemList.add(itemInfo);
}
itemInfo.setTotalItemAmount(newTotalAmount);
}
this.displayItemList.sort(comparator);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class ItemListGridWidget method checkItemListForChanges.
private void checkItemListForChanges() {
Iterator<ItemStackKey> iterator = cachedItemList.keySet().iterator();
while (iterator.hasNext()) {
ItemStackKey itemStack = iterator.next();
if (!itemList.hasItemStored(itemStack)) {
iterator.remove();
itemsRemoved.add(itemStack);
}
}
for (ItemStackKey itemStack : itemList.getStoredItems()) {
IItemInfo itemInfo = itemList.getItemInfo(itemStack);
if (itemInfo == null)
continue;
if (!cachedItemList.containsKey(itemStack)) {
SimpleItemInfo lookupInfo = new SimpleItemInfo(itemStack);
int totalAmount = itemInfo.getTotalItemAmount();
if (totalAmount == 0) {
itemsRemoved.add(itemStack);
} else {
lookupInfo.setTotalItemAmount(totalAmount);
cachedItemList.put(itemStack, lookupInfo);
itemsChanged.add(lookupInfo);
}
} else {
SimpleItemInfo cachedItemInfo = cachedItemList.get(itemStack);
if (cachedItemInfo.getTotalItemAmount() != itemInfo.getTotalItemAmount()) {
cachedItemInfo.setTotalItemAmount(itemInfo.getTotalItemAmount());
itemsChanged.add(cachedItemInfo);
}
}
}
}
use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class ItemListGridWidget method detectAndSendChanges.
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (itemList == null)
return;
int amountOfItemTypes = itemList.getStoredItems().size();
int slotRowsRequired = Math.max(slotAmountY, (int) Math.ceil(amountOfItemTypes / (slotAmountX * 1.0)));
if (slotRowsAmount != slotRowsRequired) {
int slotsToAdd = slotRowsRequired - slotRowsAmount;
this.slotRowsAmount = slotRowsRequired;
writeUpdateInfo(2, buf -> buf.writeVarInt(slotsToAdd));
modifySlotRows(slotsToAdd);
}
this.itemsChanged.clear();
this.itemsRemoved.clear();
checkItemListForChanges();
if (!itemsChanged.isEmpty() || !itemsRemoved.isEmpty()) {
writeUpdateInfo(3, buf -> {
buf.writeVarInt(itemsRemoved.size());
for (ItemStackKey itemStackKey : itemsRemoved) {
buf.writeItemStack(itemStackKey.getItemStackRaw());
}
buf.writeVarInt(itemsChanged.size());
for (SimpleItemInfo itemInfo : itemsChanged) {
buf.writeItemStack(itemInfo.getItemStackKey().getItemStackRaw());
buf.writeVarInt(itemInfo.getTotalItemAmount());
}
});
}
}
use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.
the class ItemListSlotWidget method insertHeldItemStack.
// returns true if something actually happened
private boolean insertHeldItemStack(int button, boolean isClient) {
InventoryPlayer inventory = gui.entityPlayer.inventory;
int amountToInsert = button == 1 ? 1 : Integer.MAX_VALUE;
if (!inventory.getItemStack().isEmpty()) {
if (!isClient) {
// on server, we lookup item list to see how much we can actually insert
ItemStack heldItemStack = inventory.getItemStack();
IItemList itemList = gridWidget.getItemList();
int amountInserted = itemList.insertItem(new ItemStackKey(heldItemStack), Math.min(heldItemStack.getCount(), amountToInsert), false, InsertMode.LOWEST_PRIORITY);
heldItemStack.shrink(amountInserted);
uiAccess.sendHeldItemUpdate();
gui.entityPlayer.openContainer.detectAndSendChanges();
return amountInserted > 0;
} else {
// on client we assume we can insert full stack into the network
inventory.getItemStack().shrink(amountToInsert);
return true;
}
}
return false;
}
Aggregations