Search in sources :

Example 1 with WorldSceneRenderer

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

the class JEIOptional method getWorldSceneRenderer.

@Optional.Method(modid = "jei")
public static WorldSceneRenderer getWorldSceneRenderer(MultiblockControllerBase controllerBase) {
    IRecipeRegistry rr = GTJeiPlugin.jeiRuntime.getRecipeRegistry();
    IFocus<ItemStack> focus = rr.createFocus(IFocus.Mode.INPUT, controllerBase.getStackForm());
    return rr.getRecipeCategories(focus).stream().map(c -> (IRecipeCategory<IRecipeWrapper>) c).map(c -> rr.getRecipeWrappers(c, focus)).flatMap(List::stream).filter(MultiblockInfoRecipeWrapper.class::isInstance).findFirst().map(MultiblockInfoRecipeWrapper.class::cast).map(MultiblockInfoRecipeWrapper::getCurrentRenderer).orElse(null);
}
Also used : IFocus(mezz.jei.api.recipe.IFocus) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) WorldSceneRenderer(gregtech.client.renderer.scene.WorldSceneRenderer) MultiblockInfoRecipeWrapper(gregtech.integration.jei.multiblock.MultiblockInfoRecipeWrapper) Optional(net.minecraftforge.fml.common.Optional) IRecipeRegistry(mezz.jei.api.IRecipeRegistry) IRecipeCategory(mezz.jei.api.recipe.IRecipeCategory) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) IRecipeRegistry(mezz.jei.api.IRecipeRegistry) MultiblockInfoRecipeWrapper(gregtech.integration.jei.multiblock.MultiblockInfoRecipeWrapper) IRecipeCategory(mezz.jei.api.recipe.IRecipeCategory) ItemStack(net.minecraft.item.ItemStack)

Example 2 with WorldSceneRenderer

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

the class MultiblockInfoRecipeWrapper method toggleNextLayer.

private void toggleNextLayer() {
    WorldSceneRenderer renderer = getCurrentRenderer();
    int height = (int) ((TrackedDummyWorld) renderer.world).getSize().getY() - 1;
    if (++this.layerIndex > height) {
        // if current layer index is more than max height, reset it
        // to display all layers
        this.layerIndex = -1;
    }
    setNextLayer(layerIndex);
}
Also used : ImmediateWorldSceneRenderer(gregtech.client.renderer.scene.ImmediateWorldSceneRenderer) WorldSceneRenderer(gregtech.client.renderer.scene.WorldSceneRenderer)

Example 3 with WorldSceneRenderer

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

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

the class AdvancedMonitorPluginBehavior method update.

@Override
public void update() {
    super.update();
    if (this.screen.getOffsetTimer() % 20 == 0) {
        if (this.screen.getWorld().isRemote) {
            // check connections
            if (worldSceneRenderer == null && validPos != null && validPos.size() > 0) {
                createWorldScene();
            }
            if (this.connect && worldSceneRenderer != null && this.screen.getController() instanceof MetaTileEntityCentralMonitor) {
                if (connections == null)
                    connections = new HashMap<>();
                connections.clear();
                for (MetaTileEntityMonitorScreen[] monitorScreens : ((MetaTileEntityCentralMonitor) this.screen.getController()).screens) {
                    for (MetaTileEntityMonitorScreen screen : monitorScreens) {
                        if (screen != null && screen.plugin instanceof FakeGuiPluginBehavior && ((FakeGuiPluginBehavior) screen.plugin).getHolder() == this.holder) {
                            MetaTileEntity met = ((FakeGuiPluginBehavior) screen.plugin).getRealMTE();
                            if (met != null) {
                                BlockPos pos = met.getPos();
                                Pair<List<MetaTileEntityMonitorScreen>, Vector3f> tuple = connections.getOrDefault(pos, new MutablePair<>(new ArrayList<>(), null));
                                tuple.getLeft().add(screen);
                                connections.put(pos, tuple);
                            }
                        }
                    }
                }
            }
        } else {
            // check multi-block valid
            if (holder != null && holder.getMetaTileEntity() instanceof MultiblockControllerBase) {
                MultiblockControllerBase entity = (MultiblockControllerBase) holder.getMetaTileEntity();
                if (entity.isStructureFormed()) {
                    if (!isValid) {
                        PatternMatchContext result = entity.structurePattern.checkPatternFastAt(entity.getWorld(), entity.getPos(), entity.getFrontFacing().getOpposite());
                        if (result != null) {
                            validPos = entity.structurePattern.cache.keySet().stream().map(BlockPos::fromLong).collect(Collectors.toSet());
                            writePluginData(GregtechDataCodes.UPDATE_ADVANCED_VALID_POS, buf -> {
                                buf.writeVarInt(validPos.size());
                                for (BlockPos pos : validPos) {
                                    buf.writeBlockPos(pos);
                                }
                            });
                            isValid = true;
                        } else {
                            validPos = Collections.emptySet();
                        }
                    }
                } else if (isValid) {
                    writePluginData(GregtechDataCodes.UPDATE_ADVANCED_VALID_POS, buf -> buf.writeVarInt(0));
                    isValid = false;
                }
            }
        }
    }
    if (this.screen.getWorld().isRemote && spin > 0 && lastMouse == null) {
        rotationPitch = (int) ((rotationPitch + spin * 4) % 360);
    }
}
Also used : FBOWorldSceneRenderer(gregtech.client.renderer.scene.FBOWorldSceneRenderer) EnumHand(net.minecraft.util.EnumHand) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IUIHolder(gregtech.api.gui.IUIHolder) Vec3d(net.minecraft.util.math.Vec3d) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Side(net.minecraftforge.fml.relauncher.Side) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) GL11(org.lwjgl.opengl.GL11) GregtechDataCodes(gregtech.api.capability.GregtechDataCodes) WidgetPluginConfig(gregtech.common.gui.widget.monitor.WidgetPluginConfig) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WidgetScrollBar(gregtech.common.gui.widget.WidgetScrollBar) ProxyHolderPluginBehavior(gregtech.api.items.behavior.ProxyHolderPluginBehavior) GlStateManager(net.minecraft.client.renderer.GlStateManager) LabelWidget(gregtech.api.gui.widgets.LabelWidget) Mouse(org.lwjgl.input.Mouse) Collectors(java.util.stream.Collectors) Framebuffer(net.minecraft.client.shader.Framebuffer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ColourMultiplier(codechicken.lib.render.pipeline.ColourMultiplier) ToggleButtonWidget(gregtech.api.gui.widgets.ToggleButtonWidget) java.util(java.util) Translation(codechicken.lib.vec.Translation) Blocks(net.minecraft.init.Blocks) PatternMatchContext(gregtech.api.pattern.PatternMatchContext) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) RayTraceResult(net.minecraft.util.math.RayTraceResult) MonitorPluginBaseBehavior(gregtech.api.items.behavior.MonitorPluginBaseBehavior) RenderUtil(gregtech.client.utils.RenderUtil) MetaTileEntityCentralMonitor(gregtech.common.metatileentities.multi.electric.centralmonitor.MetaTileEntityCentralMonitor) WorldSceneRenderer(gregtech.client.renderer.scene.WorldSceneRenderer) MetaTileEntityMonitorScreen(gregtech.common.metatileentities.multi.electric.centralmonitor.MetaTileEntityMonitorScreen) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) CCRenderState(codechicken.lib.render.CCRenderState) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) BlockRenderer(codechicken.lib.render.BlockRenderer) IBlockState(net.minecraft.block.state.IBlockState) Vector3f(javax.vecmath.Vector3f) Tessellator(net.minecraft.client.renderer.Tessellator) MathHelper(net.minecraft.util.math.MathHelper) TileEntity(net.minecraft.tileentity.TileEntity) PacketBuffer(net.minecraft.network.PacketBuffer) Cuboid6(codechicken.lib.vec.Cuboid6) 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) MetaTileEntityCentralMonitor(gregtech.common.metatileentities.multi.electric.centralmonitor.MetaTileEntityCentralMonitor) MetaTileEntityMonitorScreen(gregtech.common.metatileentities.multi.electric.centralmonitor.MetaTileEntityMonitorScreen)

Example 5 with WorldSceneRenderer

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

WorldSceneRenderer (gregtech.client.renderer.scene.WorldSceneRenderer)6 ImmediateWorldSceneRenderer (gregtech.client.renderer.scene.ImmediateWorldSceneRenderer)4 MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)3 PatternMatchContext (gregtech.api.pattern.PatternMatchContext)3 TrackedDummyWorld (gregtech.client.utils.TrackedDummyWorld)3 IBlockState (net.minecraft.block.state.IBlockState)3 BlockRenderer (codechicken.lib.render.BlockRenderer)2 CCRenderState (codechicken.lib.render.CCRenderState)2 ColourMultiplier (codechicken.lib.render.pipeline.ColourMultiplier)2 Cuboid6 (codechicken.lib.vec.Cuboid6)2 Translation (codechicken.lib.vec.Translation)2 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)2 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)2 BlockWorldState (gregtech.api.pattern.BlockWorldState)2 TraceabilityPredicate (gregtech.api.pattern.TraceabilityPredicate)2 RenderUtil (gregtech.client.utils.RenderUtil)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Vector3f (javax.vecmath.Vector3f)2 IRecipeWrapper (mezz.jei.api.recipe.IRecipeWrapper)2