Search in sources :

Example 1 with IModuleData

use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.

the class ScreenRenderer method renderModules.

private void renderModules(FontRenderer fontrenderer, ScreenTileEntity tileEntity, IClientScreenModule.TransformMode mode, List<IClientScreenModule> modules, Map<Integer, IModuleData> screenData, int size) {
    float f3;
    float factor = size + 1.0f;
    int currenty = 7;
    int moduleIndex = 0;
    BlockPos pos = tileEntity.getPos();
    RayTraceResult mouseOver = Minecraft.getMinecraft().objectMouseOver;
    IClientScreenModule hitModule = null;
    ScreenTileEntity.ModuleRaytraceResult hit = null;
    IBlockState blockState = getWorld().getBlockState(pos);
    Block block = blockState.getBlock();
    if (block != ScreenSetup.screenBlock && block != ScreenSetup.creativeScreenBlock && block != ScreenSetup.screenHitBlock) {
        // Safety
        return;
    }
    if (mouseOver != null) {
        if (mouseOver.sideHit == blockState.getValue(BaseBlock.FACING)) {
            double xx = mouseOver.hitVec.x - pos.getX();
            double yy = mouseOver.hitVec.y - pos.getY();
            double zz = mouseOver.hitVec.z - pos.getZ();
            EnumFacing horizontalFacing = blockState.getValue(ScreenBlock.HORIZONTAL_FACING);
            hit = tileEntity.getHitModule(xx, yy, zz, mouseOver.sideHit, horizontalFacing);
            if (hit != null) {
                hitModule = modules.get(hit.getModuleIndex());
            }
            tileEntity.focusModuleClient(xx, yy, zz, mouseOver.sideHit, horizontalFacing);
        }
    }
    if (tileEntity.isBright()) {
        Minecraft.getMinecraft().entityRenderer.disableLightmap();
    }
    for (IClientScreenModule module : modules) {
        if (module != null) {
            int height = module.getHeight();
            // Check if this module has enough room
            if (currenty + height <= 124) {
                if (module.getTransformMode() != mode) {
                    if (mode != IClientScreenModule.TransformMode.NONE) {
                        GlStateManager.popMatrix();
                    }
                    GlStateManager.pushMatrix();
                    mode = module.getTransformMode();
                    switch(mode) {
                        case TEXT:
                            GlStateManager.translate(-0.5F, 0.5F, 0.07F);
                            f3 = 0.0075F;
                            GlStateManager.scale(f3 * factor, -f3 * factor, f3);
                            GL11.glNormal3f(0.0F, 0.0F, -1.0F);
                            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                            break;
                        case TEXTLARGE:
                            GlStateManager.translate(-0.5F, 0.5F, 0.07F);
                            f3 = 0.0075F * 2;
                            GlStateManager.scale(f3 * factor, -f3 * factor, f3);
                            GL11.glNormal3f(0.0F, 0.0F, -1.0F);
                            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                            break;
                        case ITEM:
                            break;
                        default:
                            break;
                    }
                }
                IModuleData data = screenData.get(moduleIndex);
                // @todo this is a bit clumsy way to check if the data is compatible with the given module:
                try {
                    int hitx = -1;
                    int hity = -1;
                    if (module == hitModule) {
                        hitx = hit.getX();
                        hity = hit.getY() - hit.getCurrenty();
                    }
                    TrueTypeFont font = null;
                    switch(tileEntity.getTrueTypeMode()) {
                        case -1:
                            break;
                        case 1:
                            font = ClientProxy.font;
                            break;
                        case 0:
                            font = ScreenConfiguration.useTruetype ? ClientProxy.font : null;
                            break;
                    }
                    ModuleRenderInfo renderInfo = new ModuleRenderInfo(factor, pos, hitx, hity, font);
                    module.render(clientScreenModuleHelper, fontrenderer, currenty, data, renderInfo);
                } catch (ClassCastException e) {
                }
                currenty += height;
            }
        }
        moduleIndex++;
    }
    if (tileEntity.isBright()) {
        Minecraft.getMinecraft().entityRenderer.enableLightmap();
    }
    if (mode != IClientScreenModule.TransformMode.NONE) {
        GlStateManager.popMatrix();
    }
}
Also used : TrueTypeFont(mcjty.lib.font.TrueTypeFont) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) BaseBlock(mcjty.lib.container.BaseBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) IClientScreenModule(mcjty.rftools.api.screens.IClientScreenModule) IModuleData(mcjty.rftools.api.screens.data.IModuleData) ModuleRenderInfo(mcjty.rftools.api.screens.ModuleRenderInfo)

Example 2 with IModuleData

use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.

the class PacketReturnScreenData method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    NetworkTools.writePos(buf, pos.getCoordinate());
    buf.writeInt(pos.getDimension());
    buf.writeInt(screenData.size());
    for (Map.Entry<Integer, IModuleData> me : screenData.entrySet()) {
        buf.writeInt(me.getKey());
        IModuleData c = me.getValue();
        buf.writeInt(RFTools.screenModuleRegistry.getShortId(c.getId()));
        c.writeToBuf(buf);
    }
}
Also used : IModuleData(mcjty.rftools.api.screens.data.IModuleData) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with IModuleData

use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.

the class ScreenRenderer method updateScreenData.

private Map<Integer, IModuleData> updateScreenData(ScreenTileEntity screenTileEntity) {
    long millis = System.currentTimeMillis();
    if ((millis - screenTileEntity.lastTime > 500) && screenTileEntity.isNeedsServerData()) {
        screenTileEntity.lastTime = millis;
        GlobalCoordinate pos = new GlobalCoordinate(screenTileEntity.getPos(), screenTileEntity.getWorld().provider.getDimension());
        RFToolsMessages.INSTANCE.sendToServer(new PacketGetScreenData(RFTools.MODID, pos, millis));
    }
    GlobalCoordinate key = new GlobalCoordinate(screenTileEntity.getPos(), screenTileEntity.getWorld().provider.getDimension());
    Map<Integer, IModuleData> screenData = ScreenTileEntity.screenData.get(key);
    if (screenData == null) {
        screenData = Collections.emptyMap();
    }
    return screenData;
}
Also used : PacketGetScreenData(mcjty.rftools.blocks.screens.network.PacketGetScreenData) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) IModuleData(mcjty.rftools.api.screens.data.IModuleData)

Example 4 with IModuleData

use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.

the class ScreenRenderer method render.

@Override
public void render(ScreenTileEntity tileEntity, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    float xRotation = 0.0F, yRotation = 0.0F;
    EnumFacing facing = EnumFacing.SOUTH, horizontalFacing = EnumFacing.SOUTH;
    if (tileEntity != null) {
        IBlockState state = Minecraft.getMinecraft().world.getBlockState(tileEntity.getPos());
        if (state.getBlock() instanceof ScreenBlock) {
            facing = state.getValue(BaseBlock.FACING);
            horizontalFacing = state.getValue(ScreenBlock.HORIZONTAL_FACING);
        } else {
            return;
        }
    }
    GlStateManager.pushMatrix();
    switch(horizontalFacing) {
        case NORTH:
            yRotation = -180.0F;
            break;
        case WEST:
            yRotation = -90.0F;
            break;
        case EAST:
            yRotation = 90.0F;
    }
    switch(facing) {
        case DOWN:
            xRotation = 90.0F;
            break;
        case UP:
            xRotation = -90.0F;
    }
    // TileEntity can be null if this is used for an item renderer.
    GlStateManager.translate((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
    GlStateManager.rotate(yRotation, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(xRotation, 1.0F, 0.0F, 0.0F);
    GlStateManager.translate(0.0F, 0.0F, -0.4375F);
    if (tileEntity == null) {
        GlStateManager.disableLighting();
        renderScreenBoard(0, 0);
    } else if (!tileEntity.isTransparent()) {
        GlStateManager.disableLighting();
        renderScreenBoard(tileEntity.getSize(), tileEntity.getColor());
    }
    if (tileEntity != null && tileEntity.isRenderable()) {
        FontRenderer fontrenderer = this.getFontRenderer();
        IClientScreenModule.TransformMode mode = IClientScreenModule.TransformMode.NONE;
        GlStateManager.depthMask(false);
        GlStateManager.disableLighting();
        Map<Integer, IModuleData> screenData = updateScreenData(tileEntity);
        List<IClientScreenModule> modules = tileEntity.getClientScreenModules();
        if (tileEntity.isShowHelp()) {
            modules = ScreenTileEntity.getHelpingScreenModules();
        }
        renderModules(fontrenderer, tileEntity, mode, modules, screenData, tileEntity.getSize());
    }
    GlStateManager.enableLighting();
    GlStateManager.depthMask(true);
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) FontRenderer(net.minecraft.client.gui.FontRenderer) IClientScreenModule(mcjty.rftools.api.screens.IClientScreenModule) IModuleData(mcjty.rftools.api.screens.data.IModuleData)

Example 5 with IModuleData

use of mcjty.rftools.api.screens.data.IModuleData in project RFTools by McJty.

the class PacketReturnScreenData method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    pos = new GlobalCoordinate(NetworkTools.readPos(buf), buf.readInt());
    int size = buf.readInt();
    screenData = new HashMap<>(size);
    for (int i = 0; i < size; i++) {
        int key = buf.readInt();
        int shortId = buf.readInt();
        String id = RFTools.screenModuleRegistry.getNormalId(shortId);
        IModuleDataFactory<?> dataFactory = RFTools.screenModuleRegistry.getModuleDataFactory(id);
        IModuleData data = dataFactory.createData(buf);
        screenData.put(key, data);
    }
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) IModuleData(mcjty.rftools.api.screens.data.IModuleData)

Aggregations

IModuleData (mcjty.rftools.api.screens.data.IModuleData)5 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)2 IClientScreenModule (mcjty.rftools.api.screens.IClientScreenModule)2 IBlockState (net.minecraft.block.state.IBlockState)2 EnumFacing (net.minecraft.util.EnumFacing)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BaseBlock (mcjty.lib.container.BaseBlock)1 TrueTypeFont (mcjty.lib.font.TrueTypeFont)1 ModuleRenderInfo (mcjty.rftools.api.screens.ModuleRenderInfo)1 PacketGetScreenData (mcjty.rftools.blocks.screens.network.PacketGetScreenData)1 Block (net.minecraft.block.Block)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1