Search in sources :

Example 21 with MultiblockControllerBase

use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase in project GregTech by GregTechCEu.

the class MultiblockPreviewRenderer method renderControllerInList.

public static void renderControllerInList(MultiblockControllerBase controllerBase, MultiblockShapeInfo shapeInfo, int layer) {
    BlockPos mbpPos = controllerBase.getPos();
    EnumFacing frontFacing, previewFacing;
    previewFacing = controllerBase.getFrontFacing();
    BlockPos controllerPos = BlockPos.ORIGIN;
    MultiblockControllerBase mte = null;
    BlockInfo[][][] blocks = shapeInfo.getBlocks();
    Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
    int maxY = 0;
    for (int x = 0; x < blocks.length; x++) {
        BlockInfo[][] aisle = blocks[x];
        maxY = Math.max(maxY, aisle.length);
        for (int y = 0; y < aisle.length; y++) {
            BlockInfo[] column = aisle[y];
            for (int z = 0; z < column.length; z++) {
                blockMap.put(new BlockPos(x, y, z), column[z]);
                MetaTileEntity metaTE = column[z].getTileEntity() instanceof MetaTileEntityHolder ? ((MetaTileEntityHolder) column[z].getTileEntity()).getMetaTileEntity() : null;
                if (metaTE instanceof MultiblockControllerBase && metaTE.metaTileEntityId.equals(controllerBase.metaTileEntityId)) {
                    controllerPos = new BlockPos(x, y, z);
                    previewFacing = metaTE.getFrontFacing();
                    mte = (MultiblockControllerBase) metaTE;
                    break;
                }
            }
        }
    }
    TrackedDummyWorld world = new TrackedDummyWorld();
    world.addBlocks(blockMap);
    int finalMaxY = layer % (maxY + 1);
    world.setRenderFilter(pos -> pos.getY() + 1 == finalMaxY || finalMaxY == 0);
    EnumFacing facing = controllerBase.getFrontFacing();
    EnumFacing spin = EnumFacing.NORTH;
    // TODO SIDEWAYS ONE DAY
    // spin = controllerBase.getSpin();
    frontFacing = facing.getYOffset() == 0 ? facing : facing.getYOffset() < 0 ? spin : spin.getOpposite();
    Rotation rotatePreviewBy = Rotation.values()[(4 + frontFacing.getHorizontalIndex() - previewFacing.getHorizontalIndex()) % 4];
    Minecraft mc = Minecraft.getMinecraft();
    BlockRendererDispatcher brd = mc.getBlockRendererDispatcher();
    Tessellator tes = Tessellator.getInstance();
    BufferBuilder buff = tes.getBuffer();
    GlStateManager.pushMatrix();
    GlStateManager.translate(mbpPos.getX(), mbpPos.getY(), mbpPos.getZ());
    GlStateManager.translate(0.5, 0, 0.5);
    GlStateManager.rotate(rotatePreviewBy.ordinal() * 90, 0, -1, 0);
    GlStateManager.translate(-0.5, 0, -0.5);
    if (facing == EnumFacing.UP) {
        GlStateManager.translate(0.5, 0.5, 0.5);
        GlStateManager.rotate(90, -previewFacing.getZOffset(), 0, previewFacing.getXOffset());
        GlStateManager.translate(-0.5, -0.5, -0.5);
    } else if (facing == EnumFacing.DOWN) {
        GlStateManager.translate(0.5, 0.5, 0.5);
        GlStateManager.rotate(90, previewFacing.getZOffset(), 0, -previewFacing.getXOffset());
        GlStateManager.translate(-0.5, -0.5, -0.5);
    } else {
        int degree = 90 * (spin == EnumFacing.EAST ? -1 : spin == EnumFacing.SOUTH ? 2 : spin == EnumFacing.WEST ? 1 : 0);
        GlStateManager.translate(0.5, 0.5, 0.5);
        GlStateManager.rotate(degree, previewFacing.getXOffset(), 0, previewFacing.getZOffset());
        GlStateManager.translate(-0.5, -0.5, -0.5);
    }
    if (mte != null) {
        mte.checkStructurePattern();
    }
    TargetBlockAccess targetBA = new TargetBlockAccess(world, BlockPos.ORIGIN);
    for (BlockPos pos : blockMap.keySet()) {
        targetBA.setPos(pos);
        GlStateManager.pushMatrix();
        BlockPos.MutableBlockPos tPos = new BlockPos.MutableBlockPos(pos.subtract(controllerPos));
        GlStateManager.translate(tPos.getX(), tPos.getY(), tPos.getZ());
        GlStateManager.translate(0.125, 0.125, 0.125);
        GlStateManager.scale(0.75, 0.75, 0.75);
        buff.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
        IBlockState state = world.getBlockState(pos);
        for (BlockRenderLayer brl : BlockRenderLayer.values()) {
            if (state.getBlock().canRenderInLayer(state, brl)) {
                ForgeHooksClient.setRenderLayer(brl);
                brd.renderBlock(state, BlockPos.ORIGIN, targetBA, buff);
            }
        }
        tes.draw();
        GlStateManager.popMatrix();
    }
    GlStateManager.popMatrix();
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) TrackedDummyWorld(gregtech.client.utils.TrackedDummyWorld) EnumFacing(net.minecraft.util.EnumFacing) Rotation(net.minecraft.util.Rotation) Minecraft(net.minecraft.client.Minecraft) BlockInfo(gregtech.api.util.BlockInfo) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockRenderLayer(net.minecraft.util.BlockRenderLayer)

Example 22 with MultiblockControllerBase

use of gregtech.api.metatileentity.multiblock.MultiblockControllerBase 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)

Aggregations

MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)22 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)11 TileEntity (net.minecraft.tileentity.TileEntity)10 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)9 BlockPos (net.minecraft.util.math.BlockPos)7 World (net.minecraft.world.World)7 EnumFacing (net.minecraft.util.EnumFacing)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 java.util (java.util)4 IBlockState (net.minecraft.block.state.IBlockState)4 GlStateManager (net.minecraft.client.renderer.GlStateManager)4 ItemStack (net.minecraft.item.ItemStack)4 RayTraceResult (net.minecraft.util.math.RayTraceResult)4 Side (net.minecraftforge.fml.relauncher.Side)4 GregtechDataCodes (gregtech.api.capability.GregtechDataCodes)3 MonitorPluginBaseBehavior (gregtech.api.items.behavior.MonitorPluginBaseBehavior)3 ProxyHolderPluginBehavior (gregtech.api.items.behavior.ProxyHolderPluginBehavior)3 PatternMatchContext (gregtech.api.pattern.PatternMatchContext)3 BlockInfo (gregtech.api.util.BlockInfo)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3