use of com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate 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.multiblocked.api.pattern.TraceabilityPredicate in project Multiblocked by Low-Drag-MC.
the class PatternWidget method initializePattern.
private MBPattern initializePattern(MultiblockShapeInfo shapeInfo, HashSet<ItemStackKey> blockDrops) {
Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
ControllerTileEntity controllerBase = null;
BlockPos multiPos = locateNextRegion(500);
BlockInfo[][][] blocks = shapeInfo.getBlocks();
for (int x = 0; x < blocks.length; x++) {
BlockInfo[][] aisle = blocks[x];
for (int y = 0; y < aisle.length; y++) {
BlockInfo[] column = aisle[y];
for (int z = 0; z < column.length; z++) {
TileEntity tileEntity = column[z].getTileEntity();
BlockState blockState = column[z].getBlockState();
if (tileEntity == null && blockState.getBlock().hasTileEntity(blockState)) {
tileEntity = blockState.getBlock().createTileEntity(blockState, world);
}
if (tileEntity instanceof ControllerTileEntity) {
controllerBase = (ControllerTileEntity) tileEntity;
}
blockMap.put(multiPos.offset(x, y, z), new BlockInfo(blockState, tileEntity));
}
}
}
world.addBlocks(blockMap);
Map<ItemStackKey, PartInfo> parts = gatherBlockDrops(blockMap);
blockDrops.addAll(parts.keySet());
Map<BlockPos, TraceabilityPredicate> predicateMap = new HashMap<>();
if (controllerBase != null) {
loadControllerFormed(predicateMap.keySet(), controllerBase);
predicateMap = controllerBase.state.getMatchContext().get("predicates");
}
return controllerBase == null ? null : new MBPattern(blockMap, parts.values().stream().sorted((one, two) -> {
if (one.isController)
return -1;
if (two.isController)
return +1;
if (one.isTile && !two.isTile)
return -1;
if (two.isTile && !one.isTile)
return +1;
if (one.blockId != two.blockId)
return two.blockId - one.blockId;
return two.amount - one.amount;
}).map(PartInfo::getItemStack).toArray(ItemStack[]::new), predicateMap, controllerBase);
}
use of com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate in project Multiblocked by Low-Drag-MC.
the class PatternError method getCandidates.
public List<List<ItemStack>> getCandidates() {
TraceabilityPredicate predicate = worldState.predicate;
List<List<ItemStack>> candidates = new ArrayList<>();
for (SimplePredicate common : predicate.common) {
candidates.add(common.getCandidates());
}
for (SimplePredicate limited : predicate.limited) {
candidates.add(limited.getCandidates());
}
return candidates;
}
Aggregations