use of gregtech.api.pattern.MultiblockShapeInfo in project GregTech by GregTechCEu.
the class MachineBuilderWidget method setSceneWidget.
@SideOnly(Side.CLIENT)
public void setSceneWidget(MachineSceneWidget sceneWidget) {
this.sceneWidget = sceneWidget;
this.highLightBlocks = new HashSet<>();
sceneWidget.getWorldSceneRenderer().addRenderedBlocks(highLightBlocks, this::highLightRender);
sceneWidget.setOnSelected(this::setFocus);
sceneWidget.getAround().clear();
Set<BlockPos> cores = sceneWidget.getCores();
int rX = 5;
int rY = 5;
int rZ = 5;
for (MultiblockShapeInfo shapeInfo : controllerBase.getMatchingShapes()) {
BlockInfo[][][] blockInfos = shapeInfo.getBlocks();
rX = Math.max(blockInfos.length, rX);
rY = Math.max(blockInfos[0].length, rY);
rZ = Math.max(blockInfos[0][0].length, rZ);
}
for (int x = -rX; x <= rX; x++) {
for (int y = -rY; y <= rY; y++) {
for (int z = -rZ; z <= rZ; z++) {
cores.add(controllerBase.getPos().add(x, y, z));
}
}
}
}
use of gregtech.api.pattern.MultiblockShapeInfo in project GregTech by GregTechCEu.
the class MultiblockInfoRecipeWrapper method initializePattern.
private MBPattern initializePattern(MultiblockShapeInfo shapeInfo, Set<ItemStackKey> blockDrops) {
Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
MultiblockControllerBase controllerBase = null;
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++) {
if (column[z].getTileEntity() instanceof MetaTileEntityHolder && ((MetaTileEntityHolder) column[z].getTileEntity()).getMetaTileEntity() instanceof MultiblockControllerBase) {
controllerBase = (MultiblockControllerBase) ((MetaTileEntityHolder) column[z].getTileEntity()).getMetaTileEntity();
}
blockMap.put(new BlockPos(x, y, z), column[z]);
}
}
}
TrackedDummyWorld world = new TrackedDummyWorld();
ImmediateWorldSceneRenderer worldSceneRenderer = new ImmediateWorldSceneRenderer(world);
worldSceneRenderer.setClearColor(0xC6C6C6);
world.addBlocks(blockMap);
Vector3f size = world.getSize();
Vector3f minPos = world.getMinPos();
center = new Vector3f(minPos.x + size.x / 2, minPos.y + size.y / 2, minPos.z + size.z / 2);
worldSceneRenderer.addRenderedBlocks(world.renderedBlocks, null);
worldSceneRenderer.setOnLookingAt(ray -> {
});
worldSceneRenderer.setAfterWorldRender(renderer -> {
BlockPos look = worldSceneRenderer.getLastTraceResult() == null ? null : worldSceneRenderer.getLastTraceResult().getBlockPos();
if (look != null && look.equals(selected)) {
renderBlockOverLay(selected, 200, 75, 75);
return;
}
renderBlockOverLay(look, 150, 150, 150);
renderBlockOverLay(selected, 255, 0, 0);
});
world.updateEntities();
world.setRenderFilter(pos -> worldSceneRenderer.renderedBlocksMap.keySet().stream().anyMatch(c -> c.contains(pos)));
List<ItemStack> parts = gatherBlockDrops(worldSceneRenderer.world, blockMap, blockDrops).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).collect(Collectors.toList());
Map<BlockPos, TraceabilityPredicate> predicateMap = new HashMap<>();
if (controllerBase != null) {
controllerBase.structurePattern.cache.forEach((pos, blockInfo) -> predicateMap.put(BlockPos.fromLong(pos), (TraceabilityPredicate) blockInfo.getInfo()));
}
return new MBPattern(worldSceneRenderer, parts, predicateMap);
}
use of gregtech.api.pattern.MultiblockShapeInfo in project GregTech by GregTechCEu.
the class MultiBlockPreviewARApp method tickAR.
@SideOnly(Side.CLIENT)
@Override
public void tickAR(EntityPlayer player) {
World world = player.world;
// 0 - 26
int tick = Math.abs(player.ticksExisted % 27);
if (tick == 0) {
boolean reRender = false;
Iterator<MultiblockControllerBase> iterator = controllerList.keySet().iterator();
if (iterator.hasNext()) {
MultiblockControllerBase controller = iterator.next();
if (!controller.isValid() || controller.isStructureFormed() || !inRange(player.getPosition(), controller.getPos())) {
iterator.remove();
reRender = true;
}
}
for (MultiblockControllerBase controllerBase : found) {
if (!controllerList.containsKey(controllerBase)) {
List<MultiblockShapeInfo> shapeInfos = controllerBase.getMatchingShapes();
if (!shapeInfos.isEmpty()) {
controllerList.put(controllerBase, shapeInfos.get(0));
reRender = true;
}
}
}
found.clear();
lastPos = player.getPosition();
if (reRender) {
// allocate op list
opList = GLAllocation.generateDisplayLists(1);
GlStateManager.glNewList(opList, GL11.GL_COMPILE);
controllerList.forEach((controller, shapes) -> MultiblockPreviewRenderer.renderControllerInList(controller, shapes, 0));
GlStateManager.glEndList();
}
}
if (lastPos == null) {
lastPos = player.getPosition();
}
for (int i = tick * 1000; i < (tick + 1) * 1000; i++) {
int x = i % 30 - 15;
int y = (i / 30) % 30 - 15;
int z = (i / 900) - 15;
TileEntity tileEntity = world.getTileEntity(lastPos.add(x, y, z));
if (tileEntity instanceof MetaTileEntityHolder) {
if (((MetaTileEntityHolder) tileEntity).getMetaTileEntity() instanceof MultiblockControllerBase) {
found.add((MultiblockControllerBase) ((MetaTileEntityHolder) tileEntity).getMetaTileEntity());
}
}
}
}
Aggregations