Search in sources :

Example 1 with ImmediateWorldSceneRenderer

use of gregtech.client.renderer.scene.ImmediateWorldSceneRenderer 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)

Aggregations

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 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)1 MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)1 BlockWorldState (gregtech.api.pattern.BlockWorldState)1 MultiblockShapeInfo (gregtech.api.pattern.MultiblockShapeInfo)1 PatternMatchContext (gregtech.api.pattern.PatternMatchContext)1 TraceabilityPredicate (gregtech.api.pattern.TraceabilityPredicate)1 BlockInfo (gregtech.api.util.BlockInfo)1 ItemStackKey (gregtech.api.util.ItemStackKey)1 ImmediateWorldSceneRenderer (gregtech.client.renderer.scene.ImmediateWorldSceneRenderer)1 WorldSceneRenderer (gregtech.client.renderer.scene.WorldSceneRenderer)1 RenderUtil (gregtech.client.utils.RenderUtil)1 TrackedDummyWorld (gregtech.client.utils.TrackedDummyWorld)1 java.util (java.util)1