use of com.lowdragmc.lowdraglib.gui.widget.SlotWidget 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.gui.widget.SlotWidget in project Multiblocked by Low-Drag-MC.
the class ComponentTileEntity method initTraitUI.
protected void initTraitUI(TabContainer tabContainer, PlayerEntity PlayerEntity) {
WidgetGroup group = new WidgetGroup(20, 0, 176, 256);
tabContainer.addTab(new TabButton(0, tabContainer.containerGroup.widgets.size() * 20, 20, 20).setTexture(new ResourceTexture("multiblocked:textures/gui/custom_gui_tab_button.png").getSubTexture(0, 0, 1, 0.5), new ResourceTexture("multiblocked:textures/gui/custom_gui_tab_button.png").getSubTexture(0, 0.5, 1, 0.5)), group);
group.addWidget(new ImageWidget(0, 0, 176, 256, new ResourceTexture(JSONUtils.getAsString(definition.traits, "background", "multiblocked:textures/gui/custom_gui.png"))));
if (traits.size() > 0) {
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 9; col++) {
group.addWidget(new SlotWidget(PlayerEntity.inventory, col + (row + 1) * 9, 7 + col * 18, 173 + row * 18).setLocationInfo(true, false));
}
}
for (int slot = 0; slot < 9; slot++) {
group.addWidget(new SlotWidget(PlayerEntity.inventory, slot, 7 + slot * 18, 231).setLocationInfo(true, true));
}
}
for (CapabilityTrait trait : traits.values()) {
trait.createUI(this, group, PlayerEntity);
}
}
use of com.lowdragmc.lowdraglib.gui.widget.SlotWidget 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"));
}
}));
}
}
use of com.lowdragmc.lowdraglib.gui.widget.SlotWidget in project Multiblocked by Low-Drag-MC.
the class PatternWidget method reset.
private void reset(int index) {
if (index >= patterns.length || index < 0)
return;
this.index = index;
MBPattern pattern = patterns[index];
if (pattern.controllerBase.isFormed()) {
LongSet set = pattern.controllerBase.state.getMatchContext().getOrDefault("renderMask", LongSets.EMPTY_SET);
Set<BlockPos> modelDisabled = set.stream().map(BlockPos::of).collect(Collectors.toSet());
if (!modelDisabled.isEmpty()) {
sceneWidget.setRenderedCore(pattern.blockMap.keySet().stream().filter(pos -> !modelDisabled.contains(pos)).collect(Collectors.toList()), null);
} else {
sceneWidget.setRenderedCore(pattern.blockMap.keySet(), null);
}
} else {
sceneWidget.setRenderedCore(pattern.blockMap.keySet(), null);
}
if (slotWidgets != null) {
for (SlotWidget slotWidget : slotWidgets) {
removeWidget(slotWidget);
}
}
slotWidgets = new SlotWidget[Math.min(pattern.parts.size(), 18)];
IItemHandler itemHandler = new ItemStackHandler(pattern.parts);
for (int i = 0; i < slotWidgets.length; i++) {
slotWidgets[i] = new SlotWidget(itemHandler, i, 7 + (i % 9) * 18, 176 + (i / 9) * 18, false, false).setItemHook(this::itemHook);
addWidget(slotWidgets[i]);
}
leftButton.setVisible(index > 0);
rightButton.setVisible(index < patterns.length - 1);
updateClientSlots();
switchWidget.setPressed(pattern.controllerBase.isFormed());
}
Aggregations