use of com.lowdragmc.lowdraglib.utils.BlockInfo in project Multiblocked by Low-Drag-MC.
the class BlockPattern method getPreview.
public BlockInfo[][][] getPreview(int[] repetition) {
Map<SimplePredicate, Integer> cacheGlobal = new HashMap<>();
Map<BlockPos, BlockInfo> blocks = new HashMap<>();
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int minZ = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;
int maxZ = Integer.MIN_VALUE;
for (int l = 0, x = 0; l < this.fingerLength; l++) {
for (int r = 0; r < repetition[l]; r++) {
// Checking single slice
for (int y = 0; y < this.thumbLength; y++) {
for (int z = 0; z < this.palmLength; z++) {
TraceabilityPredicate predicate = this.blockMatches[l][y][z];
boolean find = false;
BlockInfo[] infos = null;
// check global and previewCount
for (SimplePredicate limit : predicate.limited) {
if (limit.minCount == -1 && limit.previewCount == -1)
continue;
if (cacheGlobal.getOrDefault(limit, 0) < limit.previewCount) {
if (!cacheGlobal.containsKey(limit)) {
cacheGlobal.put(limit, 1);
} else if (cacheGlobal.get(limit) < limit.previewCount) {
cacheGlobal.put(limit, cacheGlobal.get(limit) + 1);
} else {
continue;
}
} else if (limit.minCount > 0) {
if (!cacheGlobal.containsKey(limit)) {
cacheGlobal.put(limit, 1);
} else if (cacheGlobal.get(limit) < limit.minCount) {
cacheGlobal.put(limit, cacheGlobal.get(limit) + 1);
} else {
continue;
}
} else {
continue;
}
infos = limit.candidates == null ? null : limit.candidates.get();
find = true;
break;
}
if (!find) {
// check common with previewCount
for (SimplePredicate common : predicate.common) {
if (common.previewCount > 0) {
if (!cacheGlobal.containsKey(common)) {
cacheGlobal.put(common, 1);
} else if (cacheGlobal.get(common) < common.previewCount) {
cacheGlobal.put(common, cacheGlobal.get(common) + 1);
} else {
continue;
}
} else {
continue;
}
infos = common.candidates == null ? null : common.candidates.get();
find = true;
break;
}
}
if (!find) {
// check without previewCount
for (SimplePredicate common : predicate.common) {
if (common.previewCount == -1) {
infos = common.candidates == null ? null : common.candidates.get();
find = true;
break;
}
}
}
if (!find) {
// check max
for (SimplePredicate limit : predicate.limited) {
if (limit.previewCount != -1) {
continue;
} else if (limit.maxCount != -1) {
if (cacheGlobal.getOrDefault(limit, 0) < limit.maxCount) {
if (!cacheGlobal.containsKey(limit)) {
cacheGlobal.put(limit, 1);
} else {
cacheGlobal.put(limit, cacheGlobal.get(limit) + 1);
}
} else {
continue;
}
}
infos = limit.candidates == null ? null : limit.candidates.get();
break;
}
}
BlockInfo info = infos == null || infos.length == 0 ? BlockInfo.EMPTY : infos[0];
BlockPos pos = setActualRelativeOffset(z, y, x, Direction.NORTH);
blocks.put(pos, info);
minX = Math.min(pos.getX(), minX);
minY = Math.min(pos.getY(), minY);
minZ = Math.min(pos.getZ(), minZ);
maxX = Math.max(pos.getX(), maxX);
maxY = Math.max(pos.getY(), maxY);
maxZ = Math.max(pos.getZ(), maxZ);
}
}
x++;
}
}
BlockInfo[][][] result = (BlockInfo[][][]) Array.newInstance(BlockInfo.class, maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1);
int finalMinX = minX;
int finalMinY = minY;
int finalMinZ = minZ;
blocks.forEach((pos, info) -> {
TileEntity te = blocks.get(pos).getTileEntity();
resetFacing(pos, info.getBlockState(), null, (p, f) -> {
BlockInfo blockInfo = blocks.get(p.relative(f));
if (blockInfo == null || blockInfo.getBlockState().getBlock() == Blocks.AIR) {
if (te instanceof ComponentTileEntity) {
return ((ComponentTileEntity<?>) te).isValidFrontFacing(f);
}
return true;
}
return false;
}, info::setBlockState);
result[pos.getX() - finalMinX][pos.getY() - finalMinY][pos.getZ() - finalMinZ] = info;
});
return result;
}
use of com.lowdragmc.lowdraglib.utils.BlockInfo in project Multiblocked by Low-Drag-MC.
the class PredicateAnyCapability method buildPredicate.
@Override
public SimplePredicate buildPredicate() {
MultiblockCapability<?> capability = MbdCapabilities.get(this.capability);
if (capability == null) {
predicate = state -> false;
candidates = () -> new BlockInfo[] { new BlockInfo(Blocks.BARRIER) };
return this;
}
predicate = state -> state.getBlockState().getBlock() == capability.getAnyBlock() || checkCapability(io, capability, state);
candidates = () -> new BlockInfo[] { BlockInfo.fromBlockState(capability.getAnyBlock().defaultBlockState()) };
toolTips = new ArrayList<>();
toolTips.add(String.format("Any Capability: %s IO: %s", capability.name, io == null ? "NULL" : io.name()));
return this;
}
use of com.lowdragmc.lowdraglib.utils.BlockInfo in project Multiblocked by Low-Drag-MC.
the class FEMultiblockCapability method getCandidates.
@Override
public BlockInfo[] getCandidates() {
List<BlockInfo> list = new ArrayList<>();
TrackedDummyWorld dummyWorld = new TrackedDummyWorld();
for (Block block : ForgeRegistries.BLOCKS.getValues()) {
if (block.getRegistryName() != null) {
String path = block.getRegistryName().getPath();
if (path.contains("energy") || path.contains("rf")) {
try {
if (block.hasTileEntity(block.defaultBlockState())) {
TileEntity tileEntity = block.createTileEntity(block.defaultBlockState(), dummyWorld);
if (tileEntity != null && isBlockHasCapability(IO.BOTH, tileEntity)) {
list.add(new BlockInfo(block.defaultBlockState(), tileEntity));
}
}
} catch (Throwable ignored) {
}
}
}
}
list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "energy_input"))));
list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "energy_output"))));
return list.toArray(new BlockInfo[0]);
}
use of com.lowdragmc.lowdraglib.utils.BlockInfo in project Multiblocked by Low-Drag-MC.
the class FluidMultiblockCapability method getCandidates.
@Override
public BlockInfo[] getCandidates() {
List<BlockInfo> list = new ArrayList<>();
TrackedDummyWorld dummyWorld = new TrackedDummyWorld();
for (Block block : ForgeRegistries.BLOCKS.getValues()) {
if (block.getRegistryName() != null) {
String path = block.getRegistryName().getPath();
if (path.contains("tank") || path.contains("fluid") || path.contains("liquid")) {
try {
if (block.hasTileEntity(block.defaultBlockState())) {
TileEntity tileEntity = block.createTileEntity(block.defaultBlockState(), dummyWorld);
if (tileEntity != null && isBlockHasCapability(IO.BOTH, tileEntity)) {
list.add(new BlockInfo(block.defaultBlockState(), tileEntity));
}
}
} catch (Throwable ignored) {
}
}
}
}
list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "fluid_input"))));
list.add(BlockInfo.fromBlock(MbdComponents.COMPONENT_BLOCKS_REGISTRY.get(new ResourceLocation(Multiblocked.MODID, "fluid_output"))));
return list.toArray(new BlockInfo[0]);
}
use of com.lowdragmc.lowdraglib.utils.BlockInfo in project Multiblocked by Low-Drag-MC.
the class MultiblockPreviewRenderer method renderControllerInList.
public static void renderControllerInList(ControllerTileEntity controllerBase, MultiblockShapeInfo shapeInfo, int layer) {
Direction frontFacing;
previewFacing = Direction.NORTH;
controllerPos = BlockPos.ZERO;
mte = null;
BlockInfo[][][] blocks = shapeInfo.getBlocks();
blockMap = new HashMap<>();
int maxY = 0;
for (int x = 0; x < blocks.length; x++) {
BlockInfo[][] aisle = blocks[x];
maxY = Math.max(maxY, aisle.length);
for (int y = 0; y < aisle.length; y++) {
BlockInfo[] column = aisle[y];
for (int z = 0; z < column.length; z++) {
blockMap.put(new BlockPos(x, y, z), column[z]);
ControllerTileEntity metaTE = column[z].getTileEntity() instanceof ControllerTileEntity ? (ControllerTileEntity) column[z].getTileEntity() : null;
if (metaTE != null) {
if (metaTE.getDefinition().location.equals(controllerBase.getDefinition().location)) {
controllerPos = new BlockPos(x, y, z);
mte = metaTE;
}
}
}
}
}
world = new TrackedDummyWorld();
world.addBlocks(blockMap);
int finalMaxY = layer % (maxY + 1);
world.setRenderFilter(pos -> pos.getY() + 1 == finalMaxY || finalMaxY == 0);
facing = controllerBase.getFrontFacing();
spin = Direction.NORTH;
frontFacing = facing.getStepY() == 0 ? facing : facing.getStepY() < 0 ? spin : spin.getOpposite();
rotatePreviewBy = Rotation.values()[(4 + frontFacing.get2DDataValue() - previewFacing.get2DDataValue()) % 4];
if (mte != null) {
mbpPos = controllerBase.getBlockPos();
}
}
Aggregations