Search in sources :

Example 1 with MultiblockShapeInfo

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));
            }
        }
    }
}
Also used : BlockInfo(gregtech.api.util.BlockInfo) MultiblockShapeInfo(gregtech.api.pattern.MultiblockShapeInfo) BlockPos(net.minecraft.util.math.BlockPos) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with MultiblockShapeInfo

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);
}
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 3 with MultiblockShapeInfo

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());
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) MultiblockShapeInfo(gregtech.api.pattern.MultiblockShapeInfo) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) World(net.minecraft.world.World) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

MultiblockShapeInfo (gregtech.api.pattern.MultiblockShapeInfo)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)2 MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)2 BlockInfo (gregtech.api.util.BlockInfo)2 BlockPos (net.minecraft.util.math.BlockPos)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 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 BlockWorldState (gregtech.api.pattern.BlockWorldState)1 PatternMatchContext (gregtech.api.pattern.PatternMatchContext)1 TraceabilityPredicate (gregtech.api.pattern.TraceabilityPredicate)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