Search in sources :

Example 1 with TrueTypeFont

use of mcjty.lib.font.TrueTypeFont 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 TrueTypeFont

use of mcjty.lib.font.TrueTypeFont in project RFTools by McJty.

the class CmdFont method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    if (args.length < 3) {
        ITextComponent component = new TextComponentString(TextFormatting.RED + "Several parameters are missing!");
        if (sender instanceof EntityPlayer) {
            ((EntityPlayer) sender).sendStatusMessage(component, false);
        } else {
            sender.sendMessage(component);
        }
        return;
    } else if (args.length > 3) {
        ITextComponent component = new TextComponentString(TextFormatting.RED + "Too many parameters!");
        if (sender instanceof EntityPlayer) {
            ((EntityPlayer) sender).sendStatusMessage(component, false);
        } else {
            sender.sendMessage(component);
        }
        return;
    }
    ScreenConfiguration.font = fetchString(sender, args, 1, "rftools:fonts/ubuntu.ttf");
    ScreenConfiguration.fontSize = fetchFloat(sender, args, 2, 40);
    TrueTypeFont font = FontLoader.createFont(new ResourceLocation(ScreenConfiguration.font), ScreenConfiguration.fontSize, false);
    if (font == null) {
        ITextComponent component = new TextComponentString(TextFormatting.RED + "Could not load font!");
        if (sender instanceof EntityPlayer) {
            ((EntityPlayer) sender).sendStatusMessage(component, false);
        } else {
            sender.sendMessage(component);
        }
        return;
    }
    ClientProxy.font = font;
}
Also used : TrueTypeFont(mcjty.lib.font.TrueTypeFont) ResourceLocation(net.minecraft.util.ResourceLocation) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TrueTypeFont (mcjty.lib.font.TrueTypeFont)2 BaseBlock (mcjty.lib.container.BaseBlock)1 IClientScreenModule (mcjty.rftools.api.screens.IClientScreenModule)1 ModuleRenderInfo (mcjty.rftools.api.screens.ModuleRenderInfo)1 IModuleData (mcjty.rftools.api.screens.data.IModuleData)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumFacing (net.minecraft.util.EnumFacing)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1