use of mekanism.common.content.qio.QIOFrequency in project Mekanism by mekanism.
the class GuiQIOFilterHandler method addGuiElements.
@Override
protected void addGuiElements() {
super.addGuiElements();
addButton(new GuiQIOFrequencyTab(this, tile));
addButton(new GuiInnerScreen(this, 9, 16, imageWidth - 18, 12, () -> {
List<ITextComponent> list = new ArrayList<>();
QIOFrequency freq = tile.getQIOFrequency();
if (freq == null) {
list.add(MekanismLang.NO_FREQUENCY.translate());
} else {
list.add(MekanismLang.FREQUENCY.translate(freq.getKey()));
}
return list;
}).tooltip(() -> {
List<ITextComponent> list = new ArrayList<>();
QIOFrequency freq = tile.getQIOFrequency();
if (freq != null) {
list.add(MekanismLang.QIO_ITEMS_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(freq.getTotalItemCount()), TextUtils.format(freq.getTotalItemCountCapacity())));
list.add(MekanismLang.QIO_TYPES_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(freq.getTotalItemTypes(true)), TextUtils.format(freq.getTotalItemTypeCapacity())));
}
return list;
}));
// Filter holder
addButton(new GuiElementHolder(this, 9, 30, 144, 68));
// new filter button border
addButton(new GuiElementHolder(this, 9, 98, 144, 22));
addButton(new TranslationButton(this, 10, 99, 142, 20, MekanismLang.BUTTON_NEW_FILTER, () -> addWindow(new GuiQIOFilerSelect(this, tile))));
scrollBar = addButton(new GuiScrollBar(this, 153, 30, 90, () -> tile.getFilters().size(), () -> FILTER_COUNT));
// Add each of the buttons and then just change visibility state to match filter info
for (int i = 0; i < FILTER_COUNT; i++) {
addButton(new MovableFilterButton(this, 10, 31 + i * 22, 142, 22, i, scrollBar::getCurrentSelection, tile::getFilters, index -> {
if (index > 0) {
Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.MOVE_FILTER_UP, tile, index));
}
}, index -> {
if (index < tile.getFilters().size() - 1) {
Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.MOVE_FILTER_DOWN, tile, index));
}
}, this::onClick, filter -> {
List<ItemStack> list = new ArrayList<>();
if (filter != null) {
if (filter instanceof IItemStackFilter) {
list.add(((IItemStackFilter<?>) filter).getItemStack());
} else if (filter instanceof ITagFilter) {
String name = ((ITagFilter<?>) filter).getTagName();
if (name != null && !name.isEmpty()) {
list.addAll(TagCache.getItemTagStacks(((ITagFilter<?>) filter).getTagName()));
}
} else if (filter instanceof IModIDFilter) {
list.addAll(TagCache.getModIDStacks(((IModIDFilter<?>) filter).getModID(), false));
}
}
return list;
}));
}
}
use of mekanism.common.content.qio.QIOFrequency 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.content.qio.QIOFrequency in project Mekanism by mekanism.
the class QIOItemViewerContainer method quickMoveStack.
@Nonnull
@Override
public ItemStack quickMoveStack(@Nonnull PlayerEntity player, int slotID) {
Slot currentSlot = slots.get(slotID);
if (currentSlot == null) {
return ItemStack.EMPTY;
}
if (currentSlot instanceof VirtualCraftingOutputSlot) {
// If we are clicking an output crafting slot, allow the slot itself to handle the transferring
return ((VirtualCraftingOutputSlot) currentSlot).shiftClickSlot(player, hotBarSlots, mainInventorySlots);
} else if (currentSlot instanceof InventoryContainerSlot) {
// use our normal handling to attempt and transfer the contents to the player's inventory
return super.quickMoveStack(player, slotID);
}
// special handling for shift-clicking into GUI
if (!player.level.isClientSide()) {
ItemStack slotStack = currentSlot.getItem();
byte selectedCraftingGrid = getSelectedCraftingGrid(player.getUUID());
if (selectedCraftingGrid != -1) {
// If the player has a crafting window open
QIOCraftingWindow craftingWindow = getCraftingWindow(selectedCraftingGrid);
if (!craftingWindow.isOutput(slotStack)) {
// and the stack we are trying to transfer was not the output from the crafting window
// as then shift clicking should be sending it into the QIO, then try transferring it
// into the crafting window before transferring into the frequency
ItemStack stackToInsert = slotStack;
List<InventoryContainerSlot> craftingGridSlots = getCraftingGridSlots(selectedCraftingGrid);
SelectedWindowData windowData = craftingWindow.getWindowData();
// Start by trying to stack it with other things and if that fails try to insert it into empty slots
stackToInsert = insertItem(craftingGridSlots, stackToInsert, windowData);
if (stackToInsert.getCount() != slotStack.getCount()) {
// and return it as a new stack for what is now in the slot
return transferSuccess(currentSlot, player, slotStack, stackToInsert);
}
// Otherwise, if nothing changed, try to transfer into the QIO Frequency
}
}
QIOFrequency frequency = getFrequency();
if (frequency != null) {
if (currentSlot.hasItem()) {
// Make sure that we copy it so that we aren't just pointing to the reference of it
slotStack = slotStack.copy();
ItemStack ret = frequency.addItem(slotStack);
if (slotStack.getCount() == ret.getCount()) {
return ItemStack.EMPTY;
}
setTransferTracker(slotStack, slotID);
return updateSlot(player, currentSlot, ret);
} else {
if (slotID == lastSlot && !lastStack.isEmpty()) {
doDoubleClickTransfer(player);
}
resetTransferTracker();
return ItemStack.EMPTY;
}
}
}
return ItemStack.EMPTY;
}
use of mekanism.common.content.qio.QIOFrequency in project Mekanism by mekanism.
the class QIOItemViewerContainer method doDoubleClickTransfer.
private void doDoubleClickTransfer(PlayerEntity player) {
QIOFrequency freq = getFrequency();
mainInventorySlots.forEach(slot -> {
if (freq != null && slot.hasItem() && slot.mayPickup(player) && InventoryUtils.areItemsStackable(lastStack, slot.getItem())) {
updateSlot(player, slot, freq.addItem(slot.getItem()));
}
});
hotBarSlots.forEach(slot -> {
if (freq != null && slot.hasItem() && slot.mayPickup(player) && InventoryUtils.areItemsStackable(lastStack, slot.getItem())) {
updateSlot(player, slot, freq.addItem(slot.getItem()));
}
});
}
use of mekanism.common.content.qio.QIOFrequency in project Mekanism by mekanism.
the class TileEntityQIOComponent method decrementFrequencyColor.
@ComputerMethod
private void decrementFrequencyColor() throws ComputerException {
validateSecurityIsPublic();
QIOFrequency frequency = computerGetFrequency();
frequency.setColor(frequency.getColor().getPrevious());
}
Aggregations