Search in sources :

Example 1 with PatternMatchContext

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

the class MachineSceneWidget method updateScene.

private void updateScene() {
    if (!mte.isValid())
        return;
    World world = mte.getWorld();
    if (worldSceneRenderer != null) {
        worldSceneRenderer.releaseFBO();
    }
    worldSceneRenderer = new FBOWorldSceneRenderer(world, 1080, 1080);
    worldSceneRenderer.setAfterWorldRender(this::renderBlockOverLay);
    cores = new HashSet<>();
    around = new HashSet<>();
    cores.add(pos);
    if (mte instanceof MultiblockControllerBase) {
        PatternMatchContext context = ((MultiblockControllerBase) mte).structurePattern.checkPatternFastAt(world, pos, mte.getFrontFacing().getOpposite());
        if (context != null) {
            List<BlockPos> validPos = ((MultiblockControllerBase) mte).structurePattern.cache.keySet().stream().map(BlockPos::fromLong).collect(Collectors.toList());
            Set<IMultiblockPart> parts = context.getOrCreate("MultiblockParts", HashSet::new);
            for (IMultiblockPart part : parts) {
                if (part instanceof MetaTileEntity) {
                    cores.add(((MetaTileEntity) part).getPos());
                }
            }
            for (EnumFacing facing : EnumFacing.VALUES) {
                cores.forEach(pos -> around.add(pos.offset(facing)));
            }
            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 vPos : validPos) {
                around.add(vPos);
                minX = Math.min(minX, vPos.getX());
                minY = Math.min(minY, vPos.getY());
                minZ = Math.min(minZ, vPos.getZ());
                maxX = Math.max(maxX, vPos.getX());
                maxY = Math.max(maxY, vPos.getY());
                maxZ = Math.max(maxZ, vPos.getZ());
            }
            around.removeAll(cores);
            center = new Vector3f((minX + maxX) / 2f, (minY + maxY) / 2f, (minZ + maxZ) / 2f);
        } else {
            for (EnumFacing facing : EnumFacing.VALUES) {
                around.add(pos.offset(facing));
            }
            center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f);
        }
    } else {
        for (EnumFacing facing : EnumFacing.VALUES) {
            around.add(pos.offset(facing));
        }
        center = new Vector3f(pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f);
    }
    worldSceneRenderer.addRenderedBlocks(cores, null);
    worldSceneRenderer.addRenderedBlocks(around, this::aroundBlocksRenderHook);
    worldSceneRenderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw));
}
Also used : FBOWorldSceneRenderer(gregtech.client.renderer.scene.FBOWorldSceneRenderer) EnumFacing(net.minecraft.util.EnumFacing) IMultiblockPart(gregtech.api.metatileentity.multiblock.IMultiblockPart) World(net.minecraft.world.World) 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) HashSet(java.util.HashSet)

Example 2 with PatternMatchContext

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

the class FakeGuiPluginBehavior method getRealMTE.

public MetaTileEntity getRealMTE() {
    MetaTileEntity target = this.holder.getMetaTileEntity();
    if (target instanceof MultiblockControllerBase && partIndex > 0) {
        if (partPos != null) {
            TileEntity entity = this.screen.getWorld().getTileEntity(partPos);
            if (entity instanceof MetaTileEntityHolder) {
                return ((MetaTileEntityHolder) entity).getMetaTileEntity();
            } else {
                partPos = null;
                return null;
            }
        }
        PatternMatchContext context = ((MultiblockControllerBase) target).structurePattern.checkPatternFastAt(target.getWorld(), target.getPos(), target.getFrontFacing().getOpposite());
        if (context == null) {
            return null;
        }
        Set<IMultiblockPart> rawPartsSet = context.getOrCreate("MultiblockParts", HashSet::new);
        List<IMultiblockPart> parts = new ArrayList<>(rawPartsSet);
        parts.sort(Comparator.comparing((it) -> ((MetaTileEntity) it).getPos().hashCode()));
        if (parts.size() > partIndex - 1 && parts.get(partIndex - 1) instanceof MetaTileEntity) {
            target = (MetaTileEntity) parts.get(partIndex - 1);
            partPos = target.getPos();
        } else {
            return null;
        }
    }
    return target;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) java.util(java.util) FakeModularGui(gregtech.api.gui.impl.FakeModularGui) EnumHand(net.minecraft.util.EnumHand) PatternMatchContext(gregtech.api.pattern.PatternMatchContext) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerMainInvWrapper(net.minecraftforge.items.wrapper.PlayerMainInvWrapper) RayTraceResult(net.minecraft.util.math.RayTraceResult) Widget(gregtech.api.gui.Widget) MonitorPluginBaseBehavior(gregtech.api.items.behavior.MonitorPluginBaseBehavior) IUIHolder(gregtech.api.gui.IUIHolder) gregtech.api.gui.widgets(gregtech.api.gui.widgets) ObfuscationReflectionHelper(net.minecraftforge.fml.common.ObfuscationReflectionHelper) Side(net.minecraftforge.fml.relauncher.Side) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) GregtechDataCodes(gregtech.api.capability.GregtechDataCodes) Method(java.lang.reflect.Method) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) WidgetPluginConfig(gregtech.common.gui.widget.monitor.WidgetPluginConfig) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMultiblockPart(gregtech.api.metatileentity.multiblock.IMultiblockPart) GTLog(gregtech.api.util.GTLog) ProxyHolderPluginBehavior(gregtech.api.items.behavior.ProxyHolderPluginBehavior) GlStateManager(net.minecraft.client.renderer.GlStateManager) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) GuiTextures(gregtech.api.gui.GuiTextures) FakeModularUIPluginContainer(gregtech.common.gui.impl.FakeModularUIPluginContainer) GregtechCapabilities(gregtech.api.capability.GregtechCapabilities) GregFakePlayer(gregtech.api.util.GregFakePlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IInventory(net.minecraft.inventory.IInventory) ModularUI(gregtech.api.gui.ModularUI) TileEntity(net.minecraft.tileentity.TileEntity) PacketBuffer(net.minecraft.network.PacketBuffer) MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IMultiblockPart(gregtech.api.metatileentity.multiblock.IMultiblockPart) PatternMatchContext(gregtech.api.pattern.PatternMatchContext)

Example 3 with PatternMatchContext

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

use of gregtech.api.pattern.PatternMatchContext 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

PatternMatchContext (gregtech.api.pattern.PatternMatchContext)4 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)3 MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3 GregtechDataCodes (gregtech.api.capability.GregtechDataCodes)2 IUIHolder (gregtech.api.gui.IUIHolder)2 MonitorPluginBaseBehavior (gregtech.api.items.behavior.MonitorPluginBaseBehavior)2 ProxyHolderPluginBehavior (gregtech.api.items.behavior.ProxyHolderPluginBehavior)2 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)2 IMultiblockPart (gregtech.api.metatileentity.multiblock.IMultiblockPart)2 FBOWorldSceneRenderer (gregtech.client.renderer.scene.FBOWorldSceneRenderer)2 WorldSceneRenderer (gregtech.client.renderer.scene.WorldSceneRenderer)2 WidgetPluginConfig (gregtech.common.gui.widget.monitor.WidgetPluginConfig)2 java.util (java.util)2 Vector3f (javax.vecmath.Vector3f)2 IBlockState (net.minecraft.block.state.IBlockState)2 GlStateManager (net.minecraft.client.renderer.GlStateManager)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 EnumFacing (net.minecraft.util.EnumFacing)2