Search in sources :

Example 1 with ItemStackKey

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;
}
Also used : BlockState(net.minecraft.block.BlockState) HashMap(java.util.HashMap) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) TrackedDummyWorld(com.lowdragmc.lowdraglib.utils.TrackedDummyWorld) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) HashMap(java.util.HashMap) ItemStackKey(com.lowdragmc.lowdraglib.utils.ItemStackKey)

Example 2 with ItemStackKey

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);
}
Also used : HashMap(java.util.HashMap) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) ItemStackKey(com.lowdragmc.lowdraglib.utils.ItemStackKey) ControllerTileEntity(com.lowdragmc.multiblocked.api.tile.ControllerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) BlockInfo(com.lowdragmc.lowdraglib.utils.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) TraceabilityPredicate(com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate)

Aggregations

BlockInfo (com.lowdragmc.lowdraglib.utils.BlockInfo)2 ItemStackKey (com.lowdragmc.lowdraglib.utils.ItemStackKey)2 HashMap (java.util.HashMap)2 BlockState (net.minecraft.block.BlockState)2 BlockPos (net.minecraft.util.math.BlockPos)2 TrackedDummyWorld (com.lowdragmc.lowdraglib.utils.TrackedDummyWorld)1 TraceabilityPredicate (com.lowdragmc.multiblocked.api.pattern.TraceabilityPredicate)1 ControllerTileEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)1 Map (java.util.Map)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 World (net.minecraft.world.World)1