use of com.lowdragmc.lowdraglib.utils.CycleItemStackHandler in project Multiblocked by Low-Drag-MC.
the class PatternWidget method onPosSelected.
private void onPosSelected(BlockPos pos, Direction facing) {
if (index >= patterns.length || index < 0)
return;
TraceabilityPredicate predicate = patterns[index].predicateMap.get(pos);
if (predicate != null) {
predicates.clear();
predicates.addAll(predicate.common);
predicates.addAll(predicate.limited);
// why it happens?
predicates.removeIf(p -> p == null || p.candidates == null);
if (candidates != null) {
for (SlotWidget candidate : candidates) {
removeWidget(candidate);
}
}
List<List<ItemStack>> candidateStacks = new ArrayList<>();
List<List<String>> predicateTips = new ArrayList<>();
for (SimplePredicate simplePredicate : predicates) {
List<ItemStack> itemStacks = simplePredicate.getCandidates();
if (!itemStacks.isEmpty()) {
candidateStacks.add(itemStacks);
predicateTips.add(simplePredicate.getToolTips(predicate));
}
}
candidates = new SlotWidget[candidateStacks.size()];
CycleItemStackHandler itemHandler = new CycleItemStackHandler(candidateStacks);
for (int i = 0; i < candidateStacks.size(); i++) {
int finalI = i;
candidates[i] = new SlotWidget(itemHandler, i, 9 + (i / 6) * 18, 33 + (i % 6) * 18, false, false).setItemHook(this::itemHook).setBackgroundTexture(new ColorRectTexture(0x4fffffff)).setOnAddedTooltips((slot, list) -> predicateTips.get(finalI).forEach(tip -> list.add(new StringTextComponent(tip))));
addWidget(candidates[i]);
}
updateClientSlots();
}
}
use of com.lowdragmc.lowdraglib.utils.CycleItemStackHandler in project Multiblocked by Low-Drag-MC.
the class ItemsContentWidget method onContentUpdate.
@Override
protected void onContentUpdate() {
List<List<ItemStack>> stacks = Collections.singletonList(Arrays.stream(content.ingredient.getItems()).map(stack -> {
ItemStack copy = stack.copy();
copy.setCount(content.getAmount());
return copy;
}).collect(Collectors.toList()));
if (itemHandler != null) {
itemHandler.updateStacks(stacks);
} else {
itemHandler = new CycleItemStackHandler(stacks);
addWidget(new SlotWidget(itemHandler, 0, 1, 1, false, false).setDrawOverlay(false).setOnAddedTooltips((s, l) -> {
if (chance < 1) {
l.add(chance == 0 ? new TranslationTextComponent("multiblocked.gui.content.chance_0") : new TranslationTextComponent("multiblocked.gui.content.chance_1", String.format("%.1f", chance * 100)));
}
if (perTick) {
l.add(new TranslationTextComponent("multiblocked.gui.content.per_tick"));
}
}));
}
}
Aggregations