Search in sources :

Example 1 with FBOWorldSceneRenderer

use of gregtech.client.renderer.scene.FBOWorldSceneRenderer in project GregTech by GregTechCEu.

the class MachineSceneWidget method updateScene.

private void updateScene() {
    if (!mte.isValid())
        return;
    World world = mte.getWorld();
    if (worldSceneRenderer != null) {
        worldSceneRenderer.releaseFBO();
    }
    worldSceneRenderer = new FBOWorldSceneRenderer(world, 1080, 1080);
    worldSceneRenderer.setAfterWorldRender(this::renderBlockOverLay);
    cores = new HashSet<>();
    around = new HashSet<>();
    cores.add(pos);
    if (mte instanceof MultiblockControllerBase) {
        PatternMatchContext context = ((MultiblockControllerBase) mte).structurePattern.checkPatternFastAt(world, pos, mte.getFrontFacing().getOpposite());
        if (context != null) {
            List<BlockPos> validPos = ((MultiblockControllerBase) mte).structurePattern.cache.keySet().stream().map(BlockPos::fromLong).collect(Collectors.toList());
            Set<IMultiblockPart> parts = context.getOrCreate("MultiblockParts", HashSet::new);
            for (IMultiblockPart part : parts) {
                if (part instanceof MetaTileEntity) {
                    cores.add(((MetaTileEntity) part).getPos());
                }
            }
            for (EnumFacing facing : EnumFacing.VALUES) {
                cores.forEach(pos -> around.add(pos.offset(facing)));
            }
            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 (BlockPos vPos : validPos) {
                around.add(vPos);
                minX = Math.min(minX, vPos.getX());
                minY = Math.min(minY, vPos.getY());
                minZ = Math.min(minZ, vPos.getZ());
                maxX = Math.max(maxX, vPos.getX());
                maxY = Math.max(maxY, vPos.getY());
                maxZ = Math.max(maxZ, vPos.getZ());
            }
            around.removeAll(cores);
            center = new Vector3f((minX + maxX) / 2f, (minY + maxY) / 2f, (minZ + maxZ) / 2f);
        } else {
            for (EnumFacing facing : EnumFacing.VALUES) {
                around.add(pos.offset(facing));
            }
            center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f);
        }
    } else {
        for (EnumFacing facing : EnumFacing.VALUES) {
            around.add(pos.offset(facing));
        }
        center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f);
    }
    worldSceneRenderer.addRenderedBlocks(cores, null);
    worldSceneRenderer.addRenderedBlocks(around, this::aroundBlocksRenderHook);
    worldSceneRenderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
}
Also used : FBOWorldSceneRenderer(gregtech.client.renderer.scene.FBOWorldSceneRenderer) EnumFacing(net.minecraft.util.EnumFacing) IMultiblockPart(gregtech.api.metatileentity.multiblock.IMultiblockPart) World(net.minecraft.world.World) PatternMatchContext(gregtech.api.pattern.PatternMatchContext) Vector3f(javax.vecmath.Vector3f) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 2 with FBOWorldSceneRenderer

use of gregtech.client.renderer.scene.FBOWorldSceneRenderer in project GregTech by GregTechCEu.

the class AdvancedMonitorPluginBehavior method createWorldScene.

@SideOnly(Side.CLIENT)
private void createWorldScene() {
    if (this.screen == null || this.screen.getWorld() == null)
        return;
    isValid = true;
    World world = this.screen.getWorld();
    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 (BlockPos pos : validPos) {
        minX = Math.min(minX, pos.getX());
        minY = Math.min(minY, pos.getY());
        minZ = Math.min(minZ, pos.getZ());
        maxX = Math.max(maxX, pos.getX());
        maxY = Math.max(maxY, pos.getY());
        maxZ = Math.max(maxZ, pos.getZ());
    }
    if (FBO == null) {
        FBO = new Framebuffer(RESOLUTION, RESOLUTION, true);
    }
    TrackedDummyWorld dummyWorld = new TrackedDummyWorld(world);
    dummyWorld.setRenderFilter(pos -> validPos.contains(pos));
    worldSceneRenderer = new FBOWorldSceneRenderer(dummyWorld, FBO);
    worldSceneRenderer.addRenderedBlocks(validPos, null);
    center = new Vector3f((minX + maxX) / 2f + 0.5f, (minY + maxY) / 2f + 0.5f, (minZ + maxZ) / 2f + 0.5f);
    worldSceneRenderer.setCameraLookAt(center, 10 / scale, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
    worldSceneRenderer.setBeforeWorldRender(this::renderBefore);
    worldSceneRenderer.setAfterWorldRender(this::renderAfter);
    worldSceneRenderer.setOnLookingAt(rayTrace -> renderBlockOverLay(rayTrace.getBlockPos()));
}
Also used : Framebuffer(net.minecraft.client.shader.Framebuffer) TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) FBOWorldSceneRenderer(gregtech.client.renderer.scene.FBOWorldSceneRenderer) Vector3f(javax.vecmath.Vector3f) BlockPos(net.minecraft.util.math.BlockPos) TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) World(net.minecraft.world.World) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

FBOWorldSceneRenderer (gregtech.client.renderer.scene.FBOWorldSceneRenderer)2 Vector3f (javax.vecmath.Vector3f)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 IMultiblockPart (gregtech.api.metatileentity.multiblock.IMultiblockPart)1 MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)1 PatternMatchContext (gregtech.api.pattern.PatternMatchContext)1 TrackedDummyWorld (gregtech.client.utils.TrackedDummyWorld)1 HashSet (java.util.HashSet)1 Framebuffer (net.minecraft.client.shader.Framebuffer)1 EnumFacing (net.minecraft.util.EnumFacing)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1