Search in sources :

Example 1 with TrackedDummyWorld

use of gregtech.client.utils.TrackedDummyWorld 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);
}
Also used : MultiblockShapeInfo(gregtech.api.pattern.MultiblockShapeInfo) I18n(net.minecraft.client.resources.I18n) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) RenderHelper(net.minecraft.client.renderer.RenderHelper) IDrawable(mezz.jei.api.gui.IDrawable) NonNullList(net.minecraft.util.NonNullList) GL11(org.lwjgl.opengl.GL11) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) GuiButton(net.minecraft.client.gui.GuiButton) GlStateManager(net.minecraft.client.renderer.GlStateManager) ImmediateWorldSceneRenderer(gregtech.client.renderer.scene.ImmediateWorldSceneRenderer) TraceabilityPredicate(gregtech.api.pattern.TraceabilityPredicate) Mouse(org.lwjgl.input.Mouse) Collectors(java.util.stream.Collectors) GuiTextures(gregtech.api.gui.GuiTextures) Entry(java.util.Map.Entry) TooltipFlags(net.minecraft.client.util.ITooltipFlag.TooltipFlags) ColourMultiplier(codechicken.lib.render.pipeline.ColourMultiplier) RecipeLayout(mezz.jei.gui.recipes.RecipeLayout) java.util(java.util) Translation(codechicken.lib.vec.Translation) IIngredients(mezz.jei.api.ingredients.IIngredients) PatternMatchContext(gregtech.api.pattern.PatternMatchContext) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) Minecraft(net.minecraft.client.Minecraft) RenderUtil(gregtech.client.utils.RenderUtil) WorldSceneRenderer(gregtech.client.renderer.scene.WorldSceneRenderer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) ItemStackKey(gregtech.api.util.ItemStackKey) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) CCRenderState(codechicken.lib.render.CCRenderState) World(net.minecraft.world.World) TextFormatting(net.minecraft.util.text.TextFormatting) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) BlockRenderer(codechicken.lib.render.BlockRenderer) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) BlockWorldState(gregtech.api.pattern.BlockWorldState) BlockInfo(gregtech.api.util.BlockInfo) IGuiHelper(mezz.jei.api.IGuiHelper) EnumRarity(net.minecraft.item.EnumRarity) IBlockState(net.minecraft.block.state.IBlockState) Vector3f(javax.vecmath.Vector3f) FontRenderer(net.minecraft.client.gui.FontRenderer) Tessellator(net.minecraft.client.renderer.Tessellator) MathHelper(net.minecraft.util.math.MathHelper) VanillaTypes(mezz.jei.api.ingredients.VanillaTypes) TileEntity(net.minecraft.tileentity.TileEntity) Cuboid6(codechicken.lib.vec.Cuboid6) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) ImmediateWorldSceneRenderer(gregtech.client.renderer.scene.ImmediateWorldSceneRenderer) BlockInfo(gregtech.api.util.BlockInfo) Vector3f(javax.vecmath.Vector3f) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) TraceabilityPredicate(gregtech.api.pattern.TraceabilityPredicate)

Example 2 with TrackedDummyWorld

use of gregtech.client.utils.TrackedDummyWorld in project GregTech by GregTechCEu.

the class MultiblockPreviewRenderer method renderControllerInList.

public static void renderControllerInList(MultiblockControllerBase controllerBase, MultiblockShapeInfo shapeInfo, int layer) {
    BlockPos mbpPos = controllerBase.getPos();
    EnumFacing frontFacing, previewFacing;
    previewFacing = controllerBase.getFrontFacing();
    BlockPos controllerPos = BlockPos.ORIGIN;
    MultiblockControllerBase mte = null;
    BlockInfo[][][] blocks = shapeInfo.getBlocks();
    Map<BlockPos, BlockInfo> 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]);
                MetaTileEntity metaTE = column[z].getTileEntity() instanceof MetaTileEntityHolder ? ((MetaTileEntityHolder) column[z].getTileEntity()).getMetaTileEntity() : null;
                if (metaTE instanceof MultiblockControllerBase && metaTE.metaTileEntityId.equals(controllerBase.metaTileEntityId)) {
                    controllerPos = new BlockPos(x, y, z);
                    previewFacing = metaTE.getFrontFacing();
                    mte = (MultiblockControllerBase) metaTE;
                    break;
                }
            }
        }
    }
    TrackedDummyWorld world = new TrackedDummyWorld();
    world.addBlocks(blockMap);
    int finalMaxY = layer % (maxY + 1);
    world.setRenderFilter(pos -> pos.getY() + 1 == finalMaxY || finalMaxY == 0);
    EnumFacing facing = controllerBase.getFrontFacing();
    EnumFacing spin = EnumFacing.NORTH;
    // TODO SIDEWAYS ONE DAY
    // spin = controllerBase.getSpin();
    frontFacing = facing.getYOffset() == 0 ? facing : facing.getYOffset() < 0 ? spin : spin.getOpposite();
    Rotation rotatePreviewBy = Rotation.values()[(4 + frontFacing.getHorizontalIndex() - previewFacing.getHorizontalIndex()) % 4];
    Minecraft mc = Minecraft.getMinecraft();
    BlockRendererDispatcher brd = mc.getBlockRendererDispatcher();
    Tessellator tes = Tessellator.getInstance();
    BufferBuilder buff = tes.getBuffer();
    GlStateManager.pushMatrix();
    GlStateManager.translate(mbpPos.getX(), mbpPos.getY(), mbpPos.getZ());
    GlStateManager.translate(0.5, 0, 0.5);
    GlStateManager.rotate(rotatePreviewBy.ordinal() * 90, 0, -1, 0);
    GlStateManager.translate(-0.5, 0, -0.5);
    if (facing == EnumFacing.UP) {
        GlStateManager.translate(0.5, 0.5, 0.5);
        GlStateManager.rotate(90, -previewFacing.getZOffset(), 0, previewFacing.getXOffset());
        GlStateManager.translate(-0.5, -0.5, -0.5);
    } else if (facing == EnumFacing.DOWN) {
        GlStateManager.translate(0.5, 0.5, 0.5);
        GlStateManager.rotate(90, previewFacing.getZOffset(), 0, -previewFacing.getXOffset());
        GlStateManager.translate(-0.5, -0.5, -0.5);
    } else {
        int degree = 90 * (spin == EnumFacing.EAST ? -1 : spin == EnumFacing.SOUTH ? 2 : spin == EnumFacing.WEST ? 1 : 0);
        GlStateManager.translate(0.5, 0.5, 0.5);
        GlStateManager.rotate(degree, previewFacing.getXOffset(), 0, previewFacing.getZOffset());
        GlStateManager.translate(-0.5, -0.5, -0.5);
    }
    if (mte != null) {
        mte.checkStructurePattern();
    }
    TargetBlockAccess targetBA = new TargetBlockAccess(world, BlockPos.ORIGIN);
    for (BlockPos pos : blockMap.keySet()) {
        targetBA.setPos(pos);
        GlStateManager.pushMatrix();
        BlockPos.MutableBlockPos tPos = new BlockPos.MutableBlockPos(pos.subtract(controllerPos));
        GlStateManager.translate(tPos.getX(), tPos.getY(), tPos.getZ());
        GlStateManager.translate(0.125, 0.125, 0.125);
        GlStateManager.scale(0.75, 0.75, 0.75);
        buff.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
        IBlockState state = world.getBlockState(pos);
        for (BlockRenderLayer brl : BlockRenderLayer.values()) {
            if (state.getBlock().canRenderInLayer(state, brl)) {
                ForgeHooksClient.setRenderLayer(brl);
                brd.renderBlock(state, BlockPos.ORIGIN, targetBA, buff);
            }
        }
        tes.draw();
        GlStateManager.popMatrix();
    }
    GlStateManager.popMatrix();
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) EnumFacing(net.minecraft.util.EnumFacing) Rotation(net.minecraft.util.Rotation) Minecraft(net.minecraft.client.Minecraft) BlockInfo(gregtech.api.util.BlockInfo) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockRenderLayer(net.minecraft.util.BlockRenderLayer)

Example 3 with TrackedDummyWorld

use of gregtech.client.utils.TrackedDummyWorld 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)

Example 4 with TrackedDummyWorld

use of gregtech.client.utils.TrackedDummyWorld in project GregTech by GregTechCEu.

the class MultiblockInfoRecipeWrapper method setRecipeLayout.

public void setRecipeLayout(RecipeLayout layout, IGuiHelper guiHelper) {
    this.recipeLayout = layout;
    this.slot = guiHelper.drawableBuilder(GuiTextures.SLOT.imageLocation, 0, 0, SLOT_SIZE, SLOT_SIZE).setTextureSize(SLOT_SIZE, SLOT_SIZE).build();
    this.infoIcon = guiHelper.drawableBuilder(GuiTextures.INFO_ICON.imageLocation, 0, 0, ICON_SIZE, ICON_SIZE).setTextureSize(ICON_SIZE, ICON_SIZE).build();
    IDrawable border = layout.getRecipeCategory().getBackground();
    preparePlaceForParts(border.getHeight());
    if (Mouse.getEventDWheel() == 0 || lastWrapper != this) {
        selected = null;
        this.predicates.clear();
        this.father = null;
        lastWrapper = this;
        this.nextLayerButton.x = border.getWidth() - (ICON_SIZE + RIGHT_PADDING);
        this.buttonPreviousPattern.x = border.getWidth() - ((2 * ICON_SIZE) + RIGHT_PADDING + 1);
        this.buttonNextPattern.x = border.getWidth() - (ICON_SIZE + RIGHT_PADDING);
        this.buttonPreviousPattern.enabled = false;
        this.buttonNextPattern.enabled = patterns.length > 1;
        Vector3f size = ((TrackedDummyWorld) getCurrentRenderer().world).getSize();
        float max = Math.max(Math.max(Math.max(size.x, size.y), size.z), 1);
        this.zoom = (float) (3.5 * Math.sqrt(max));
        this.rotationYaw = 20.0f;
        this.rotationPitch = 50f;
        this.currentRendererPage = 0;
        setNextLayer(-1);
    } else {
        zoom = (float) MathHelper.clamp(zoom + (Mouse.getEventDWheel() < 0 ? 0.5 : -0.5), 3, 999);
        setNextLayer(getLayerIndex());
        if (predicates != null && predicates.size() > 0) {
            setItemStackGroup();
        }
    }
    if (getCurrentRenderer() != null) {
        TrackedDummyWorld world = (TrackedDummyWorld) getCurrentRenderer().world;
        resetCenter(world);
    }
    updateParts();
}
Also used : TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) Vector3f(javax.vecmath.Vector3f) IDrawable(mezz.jei.api.gui.IDrawable)

Example 5 with TrackedDummyWorld

use of gregtech.client.utils.TrackedDummyWorld in project GregTech by GregTechCEu.

the class MultiblockInfoRecipeWrapper method setNextLayer.

private void setNextLayer(int newLayer) {
    this.layerIndex = newLayer;
    this.nextLayerButton.displayString = "L:" + (layerIndex == -1 ? "A" : Integer.toString(layerIndex + 1));
    WorldSceneRenderer renderer = getCurrentRenderer();
    if (renderer != null) {
        TrackedDummyWorld world = ((TrackedDummyWorld) renderer.world);
        resetCenter(world);
        renderer.renderedBlocksMap.clear();
        int minY = (int) world.getMinPos().getY();
        Collection<BlockPos> renderBlocks;
        if (newLayer == -1) {
            renderBlocks = world.renderedBlocks;
        } else {
            renderBlocks = world.renderedBlocks.stream().filter(pos -> pos.getY() - minY == newLayer).collect(Collectors.toSet());
        }
        renderer.addRenderedBlocks(renderBlocks, null);
    }
}
Also used : TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) BlockPos(net.minecraft.util.math.BlockPos) ImmediateWorldSceneRenderer(gregtech.client.renderer.scene.ImmediateWorldSceneRenderer) WorldSceneRenderer(gregtech.client.renderer.scene.WorldSceneRenderer)

Aggregations

TrackedDummyWorld (gregtech.client.utils.TrackedDummyWorld)5 Vector3f (javax.vecmath.Vector3f)3 BlockPos (net.minecraft.util.math.BlockPos)3 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)2 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)2 MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)2 BlockInfo (gregtech.api.util.BlockInfo)2 ImmediateWorldSceneRenderer (gregtech.client.renderer.scene.ImmediateWorldSceneRenderer)2 WorldSceneRenderer (gregtech.client.renderer.scene.WorldSceneRenderer)2 IDrawable (mezz.jei.api.gui.IDrawable)2 IBlockState (net.minecraft.block.state.IBlockState)2 Minecraft (net.minecraft.client.Minecraft)2 BlockRenderer (codechicken.lib.render.BlockRenderer)1 CCRenderState (codechicken.lib.render.CCRenderState)1 ColourMultiplier (codechicken.lib.render.pipeline.ColourMultiplier)1 Cuboid6 (codechicken.lib.vec.Cuboid6)1 Translation (codechicken.lib.vec.Translation)1 GuiTextures (gregtech.api.gui.GuiTextures)1 BlockWorldState (gregtech.api.pattern.BlockWorldState)1 MultiblockShapeInfo (gregtech.api.pattern.MultiblockShapeInfo)1