use of mekanism.common.inventory.container.QIOItemViewerContainer in project Mekanism by mekanism.
the class PacketQIOFillCraftingWindow method handle.
@Override
public void handle(NetworkEvent.Context context) {
ServerPlayerEntity player = context.getSender();
if (player != null && player.containerMenu instanceof QIOItemViewerContainer) {
QIOItemViewerContainer container = (QIOItemViewerContainer) player.containerMenu;
byte selectedCraftingGrid = container.getSelectedCraftingGrid(player.getUUID());
if (selectedCraftingGrid == -1) {
Mekanism.logger.warn("Received transfer request from: {}, but they do not currently have a crafting window open.", player);
} else {
Optional<? extends IRecipe<?>> optionalRecipe = player.level.getRecipeManager().byKey(recipeID);
if (optionalRecipe.isPresent()) {
IRecipe<?> recipe = optionalRecipe.get();
if (recipe instanceof ICraftingRecipe) {
QIOServerCraftingTransferHandler.tryTransfer(container, selectedCraftingGrid, player, recipeID, (ICraftingRecipe) recipe, sources);
} else {
Mekanism.logger.warn("Received transfer request from: {}, but the type ({}) of the specified recipe was not a crafting recipe.", player, recipe.getClass());
}
} else {
Mekanism.logger.warn("Received transfer request from: {}, but could not find specified recipe.", player);
}
}
}
}
use of mekanism.common.inventory.container.QIOItemViewerContainer in project Mekanism by mekanism.
the class PacketGuiItemDataRequest method handle.
@Override
public void handle(NetworkEvent.Context context) {
ServerPlayerEntity player = context.getSender();
if (player != null) {
if (type == Type.QIO_ITEM_VIEWER) {
if (player.containerMenu instanceof QIOItemViewerContainer) {
QIOItemViewerContainer container = (QIOItemViewerContainer) player.containerMenu;
QIOFrequency freq = container.getFrequency();
if (!player.level.isClientSide() && freq != null) {
freq.openItemViewer(player);
}
}
}
}
}
use of mekanism.common.inventory.container.QIOItemViewerContainer in project Mekanism by mekanism.
the class QIOFrequency method tick.
@Override
public void tick() {
super.tick();
if (!uuidsToInvalidate.isEmpty()) {
// If we have uuids we need to invalidate the Item UUID pairing of them
for (UUID uuidToInvalidate : uuidsToInvalidate) {
itemTypeLookup.inverse().remove(uuidToInvalidate);
}
uuidsToInvalidate.clear();
}
if (!updatedItems.isEmpty() || needsUpdate) {
Object2LongMap<UUIDAwareHashedItem> map = new Object2LongOpenHashMap<>();
updatedItems.forEach(type -> {
QIOItemTypeData data = itemDataMap.get(type);
map.put(type, data == null ? 0 : data.count);
});
// flush players that somehow didn't send a container close packet
playersViewingItems.removeIf(player -> !(player.containerMenu instanceof QIOItemViewerContainer));
playersViewingItems.forEach(player -> Mekanism.packetHandler.sendTo(PacketQIOItemViewerGuiSync.update(map, totalCountCapacity, totalTypeCapacity), player));
updatedItems.clear();
needsUpdate = false;
}
// is forcibly shut down.
if (isDirty && rand.nextInt(100) == 0) {
saveAll();
isDirty = false;
}
if (CommonWorldTickHandler.flushTagAndRecipeCaches) {
// Note: We only need to clear tags here as the modids cannot change just because a reload happened
tagLookupMap.clear();
tagWildcardCache.clear();
itemDataMap.values().forEach(item -> tagLookupMap.putAll(TagCache.getItemTags(item.itemType.getStack()), item.itemType));
}
}
use of mekanism.common.inventory.container.QIOItemViewerContainer in project Mekanism by mekanism.
the class PacketQIOItemViewerSlotInteract method handle.
@Override
public void handle(NetworkEvent.Context context) {
ServerPlayerEntity player = context.getSender();
if (player != null && player.containerMenu instanceof QIOItemViewerContainer) {
QIOItemViewerContainer container = (QIOItemViewerContainer) player.containerMenu;
QIOFrequency freq = container.getFrequency();
ItemStack curStack = player.inventory.getCarried();
if (freq != null) {
if (type == Type.TAKE) {
ItemStack ret = freq.removeByType(freq.getTypeByUUID(typeUUID), count);
if (curStack.isEmpty()) {
player.inventory.setCarried(ret);
} else if (InventoryUtils.areItemsStackable(ret, curStack)) {
curStack.grow(ret.getCount());
}
player.connection.send(new SSetSlotPacket(-1, -1, player.inventory.getCarried()));
} else if (type == Type.SHIFT_TAKE) {
HashedItem itemType = freq.getTypeByUUID(typeUUID);
if (itemType != null) {
ItemStack ret = freq.removeByType(itemType, itemType.getStack().getMaxStackSize());
ItemStack remainder = container.insertIntoPlayerInventory(player.getUUID(), ret);
if (!remainder.isEmpty()) {
remainder = freq.addItem(remainder);
if (!remainder.isEmpty()) {
Mekanism.logger.error("QIO shift-click transfer resulted in lost items ({}). This shouldn't happen!", remainder);
}
}
}
} else if (type == Type.PUT) {
if (!curStack.isEmpty()) {
ItemStack rejects = freq.addItem(StackUtils.size(curStack, Math.min(count, curStack.getCount())));
ItemStack newStack = StackUtils.size(curStack, curStack.getCount() - (count - rejects.getCount()));
player.inventory.setCarried(newStack);
}
player.connection.send(new SSetSlotPacket(-1, -1, player.inventory.getCarried()));
}
}
}
}
Aggregations