Search in sources :

Example 1 with TraceabilityPredicate

use of gregtech.api.pattern.TraceabilityPredicate in project GregTech by GregTechCEu.

the class MetaTileEntityLargeChemicalReactor method createStructurePattern.

@Override
protected BlockPattern createStructurePattern() {
    TraceabilityPredicate casing = states(getCasingState()).setMinGlobalLimited(10);
    TraceabilityPredicate abilities = autoAbilities();
    return FactoryBlockPattern.start().aisle("XXX", "XCX", "XXX").aisle("XCX", "CPC", "XCX").aisle("XXX", "XSX", "XXX").where('S', selfPredicate()).where('X', casing.or(abilities)).where('P', states(getPipeCasingState())).where('C', states(MetaBlocks.WIRE_COIL.getState(BlockWireCoil.CoilType.CUPRONICKEL)).setMinGlobalLimited(1).setMaxGlobalLimited(1).or(abilities).or(casing)).build();
}
Also used : TraceabilityPredicate(gregtech.api.pattern.TraceabilityPredicate)

Example 2 with TraceabilityPredicate

use of gregtech.api.pattern.TraceabilityPredicate in project GregTech by GregTechCEu.

the class MetaTileEntityProcessingArray method autoAbilities.

@Override
public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkMaintenance, boolean checkItemIn, boolean checkItemOut, boolean checkFluidIn, boolean checkFluidOut, boolean checkMuffler) {
    TraceabilityPredicate predicate = super.autoAbilities(checkMaintenance, checkMuffler).or(checkEnergyIn ? abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1).setMaxGlobalLimited(4).setPreviewCount(1) : new TraceabilityPredicate());
    predicate = predicate.or(abilities(MultiblockAbility.IMPORT_ITEMS).setPreviewCount(1));
    predicate = predicate.or(abilities(MultiblockAbility.EXPORT_ITEMS).setPreviewCount(1));
    predicate = predicate.or(abilities(MultiblockAbility.IMPORT_FLUIDS).setPreviewCount(1));
    predicate = predicate.or(abilities(MultiblockAbility.EXPORT_FLUIDS).setPreviewCount(1));
    return predicate;
}
Also used : TraceabilityPredicate(gregtech.api.pattern.TraceabilityPredicate)

Example 3 with TraceabilityPredicate

use of gregtech.api.pattern.TraceabilityPredicate 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 4 with TraceabilityPredicate

use of gregtech.api.pattern.TraceabilityPredicate in project GregTech by GregTechCEu.

the class MultiMapMultiblockController method autoAbilities.

@Override
public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkMaintenance, boolean checkItemIn, boolean checkItemOut, boolean checkFluidIn, boolean checkFluidOut, boolean checkMuffler) {
    boolean checkedItemIn = false, checkedItemOut = false, checkedFluidIn = false, checkedFluidOut = false;
    TraceabilityPredicate predicate = super.autoAbilities(checkMaintenance, checkMuffler).or(checkEnergyIn ? abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1).setMaxGlobalLimited(3).setPreviewCount(1) : new TraceabilityPredicate());
    for (RecipeMap<?> recipeMap : getAvailableRecipeMaps()) {
        if (!checkedItemIn && checkItemIn) {
            if (recipeMap.getMinInputs() > 0) {
                checkedItemIn = true;
                predicate = predicate.or(abilities(MultiblockAbility.IMPORT_ITEMS).setMinGlobalLimited(1).setPreviewCount(1));
            } else if (recipeMap.getMaxInputs() > 0) {
                checkedItemIn = true;
                predicate = predicate.or(abilities(MultiblockAbility.IMPORT_ITEMS).setPreviewCount(1));
            }
        }
        if (!checkedItemOut && checkItemOut) {
            if (recipeMap.getMinOutputs() > 0) {
                checkedItemOut = true;
                predicate = predicate.or(abilities(MultiblockAbility.EXPORT_ITEMS).setMinGlobalLimited(1).setPreviewCount(1));
            } else if (recipeMap.getMaxOutputs() > 0) {
                checkedItemOut = true;
                predicate = predicate.or(abilities(MultiblockAbility.EXPORT_ITEMS).setPreviewCount(1));
            }
        }
        if (!checkedFluidIn && checkFluidIn) {
            if (recipeMap.getMinFluidInputs() > 0) {
                checkedFluidIn = true;
                predicate = predicate.or(abilities(MultiblockAbility.IMPORT_FLUIDS).setMinGlobalLimited(1).setPreviewCount(recipeMap.getMinFluidInputs()));
            } else if (recipeMap.getMaxFluidInputs() > 0) {
                checkedFluidIn = true;
                predicate = predicate.or(abilities(MultiblockAbility.IMPORT_FLUIDS).setPreviewCount(1));
            }
        }
        if (!checkedFluidOut && checkFluidOut) {
            if (recipeMap.getMinFluidOutputs() > 0) {
                checkedFluidOut = true;
                predicate = predicate.or(abilities(MultiblockAbility.EXPORT_FLUIDS).setMinGlobalLimited(1).setPreviewCount(recipeMap.getMinFluidOutputs()));
            } else if (recipeMap.getMaxFluidOutputs() > 0) {
                checkedFluidOut = true;
                predicate = predicate.or(abilities(MultiblockAbility.EXPORT_FLUIDS).setPreviewCount(1));
            }
        }
    }
    return predicate;
}
Also used : TraceabilityPredicate(gregtech.api.pattern.TraceabilityPredicate)

Example 5 with TraceabilityPredicate

use of gregtech.api.pattern.TraceabilityPredicate in project GregTech by GregTechCEu.

the class MultiblockInfoRecipeWrapper method drawInfo.

@Override
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
    WorldSceneRenderer renderer = getCurrentRenderer();
    int sceneHeight = recipeHeight - PARTS_HEIGHT;
    renderer.render(recipeLayout.getPosX(), recipeLayout.getPosY(), recipeWidth, sceneHeight, mouseX + recipeLayout.getPosX(), mouseY + recipeLayout.getPosY());
    drawMultiblockName(recipeWidth);
    // reset colors (so any elements render after this point are not dark)
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    int iconX = recipeWidth - (ICON_SIZE + RIGHT_PADDING);
    int iconY = 49;
    this.infoIcon.draw(minecraft, iconX, iconY);
    this.drawInfoIcon = iconX <= mouseX && mouseX <= iconX + ICON_SIZE && iconY <= mouseY && mouseY <= iconY + ICON_SIZE;
    // draw parts slots
    for (int i = 0; i < MAX_PARTS; ++i) {
        this.slot.draw(minecraft, SLOT_SIZE * i - (SLOTS_PER_ROW * SLOT_SIZE) * (i / SLOTS_PER_ROW) + (SLOT_SIZE / 2) - 2, sceneHeight + SLOT_SIZE * (i / SLOTS_PER_ROW));
    }
    // draw candidates slots
    for (int i = 0; i < predicates.size(); i++) {
        this.slot.draw(minecraft, 5 + (i / 6) * SLOT_SIZE, (i % 6) * SLOT_SIZE + 10);
    }
    // draw buttons
    for (GuiButton button : buttons.keySet()) {
        button.drawButton(minecraft, mouseX, mouseY, 0.0f);
    }
    tooltipBlockStack = null;
    this.predicateTips = null;
    RayTraceResult rayTraceResult = renderer.getLastTraceResult();
    boolean insideView = mouseX >= 0 && mouseY >= 0 && mouseX < recipeWidth && mouseY < sceneHeight;
    boolean leftClickHeld = Mouse.isButtonDown(0);
    boolean rightClickHeld = Mouse.isButtonDown(1);
    if (insideView) {
        for (GuiButton button : buttons.keySet()) {
            if (button.isMouseOver()) {
                insideView = false;
                break;
            }
        }
    }
    if (insideView) {
        if (leftClickHeld) {
            rotationPitch += mouseX - lastMouseX + 360;
            rotationPitch = rotationPitch % 360;
            rotationYaw = (float) MathHelper.clamp(rotationYaw + (mouseY - lastMouseY), -89.9, 89.9);
        } else if (rightClickHeld) {
            int mouseDeltaY = mouseY - lastMouseY;
            if (Math.abs(mouseDeltaY) > 1) {
                this.zoom = (float) MathHelper.clamp(zoom + (mouseDeltaY > 0 ? 0.5 : -0.5), 3, 999);
            }
        }
        renderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
    }
    if (!(leftClickHeld || rightClickHeld) && rayTraceResult != null && !renderer.world.isAirBlock(rayTraceResult.getBlockPos())) {
        IBlockState blockState = renderer.world.getBlockState(rayTraceResult.getBlockPos());
        ItemStack itemStack = blockState.getBlock().getPickBlock(blockState, rayTraceResult, renderer.world, rayTraceResult.getBlockPos(), minecraft.player);
        TraceabilityPredicate predicates = patterns[currentRendererPage].predicateMap.get(rayTraceResult.getBlockPos());
        if (predicates != null) {
            BlockWorldState worldState = new BlockWorldState();
            worldState.update(renderer.world, rayTraceResult.getBlockPos(), new PatternMatchContext(), new HashMap<>(), new HashMap<>(), predicates);
            for (TraceabilityPredicate.SimplePredicate common : predicates.common) {
                if (common.test(worldState)) {
                    predicateTips = common.getToolTips(predicates);
                    break;
                }
            }
            if (predicateTips == null) {
                for (TraceabilityPredicate.SimplePredicate limit : predicates.limited) {
                    if (limit.test(worldState)) {
                        predicateTips = limit.getToolTips(predicates);
                        break;
                    }
                }
            }
        }
        if (!itemStack.isEmpty()) {
            tooltipBlockStack = itemStack;
        }
    }
    lastRender = System.currentTimeMillis();
    this.lastMouseX = mouseX;
    this.lastMouseY = mouseY;
    GlStateManager.disableRescaleNormal();
    GlStateManager.disableLighting();
    RenderHelper.disableStandardItemLighting();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) GuiButton(net.minecraft.client.gui.GuiButton) RayTraceResult(net.minecraft.util.math.RayTraceResult) ImmediateWorldSceneRenderer(gregtech.client.renderer.scene.ImmediateWorldSceneRenderer) WorldSceneRenderer(gregtech.client.renderer.scene.WorldSceneRenderer) ItemStack(net.minecraft.item.ItemStack) BlockWorldState(gregtech.api.pattern.BlockWorldState) PatternMatchContext(gregtech.api.pattern.PatternMatchContext) TraceabilityPredicate(gregtech.api.pattern.TraceabilityPredicate)

Aggregations

TraceabilityPredicate (gregtech.api.pattern.TraceabilityPredicate)6 GuiButton (net.minecraft.client.gui.GuiButton)3 BlockWorldState (gregtech.api.pattern.BlockWorldState)2 PatternMatchContext (gregtech.api.pattern.PatternMatchContext)2 ImmediateWorldSceneRenderer (gregtech.client.renderer.scene.ImmediateWorldSceneRenderer)2 WorldSceneRenderer (gregtech.client.renderer.scene.WorldSceneRenderer)2 IBlockState (net.minecraft.block.state.IBlockState)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 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)1 MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)1 MultiblockShapeInfo (gregtech.api.pattern.MultiblockShapeInfo)1 BlockInfo (gregtech.api.util.BlockInfo)1 ItemStackKey (gregtech.api.util.ItemStackKey)1 RenderUtil (gregtech.client.utils.RenderUtil)1