use of com.lowdragmc.lowdraglib.utils.ItemStackKey in project Multiblocked by Low-Drag-MC.
the class PatternWidget method gatherBlockDrops.
private Map<ItemStackKey, PartInfo> gatherBlockDrops(Map<BlockPos, BlockInfo> blocks) {
Map<ItemStackKey, PartInfo> partsMap = new HashMap<>();
for (Map.Entry<BlockPos, BlockInfo> entry : blocks.entrySet()) {
BlockPos pos = entry.getKey();
BlockState blockState = ((World) PatternWidget.world).getBlockState(pos);
ItemStack itemStack = blockState.getBlock().getPickBlock(blockState, BlockRayTraceResult.miss(new Vector3d(0.5, 1, 0.5).add(pos.getX(), pos.getY(), pos.getZ()), Direction.UP, pos), PatternWidget.world, pos, Minecraft.getInstance().player);
ItemStackKey itemStackKey = new ItemStackKey(itemStack);
PartInfo partInfo = partsMap.get(itemStackKey);
if (partInfo == null) {
partInfo = new PartInfo(itemStackKey, entry.getValue());
partsMap.put(itemStackKey, partInfo);
}
++partInfo.amount;
}
return partsMap;
}
use of com.lowdragmc.lowdraglib.utils.ItemStackKey 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);
}
Aggregations