Jump to content

[1.12]Full Screen / Fixed Gui Elements


Recommended Posts

So I often had this Problem with Gui textures resizing upon rescaling the window or changing the guiScale.
This is also problematic if other players with a different Resolution use your Guis which are meant to have fixed points.

In this tutorial I want to show you how to make a fixed ModalRect which will take up the whole Minecraft-Screen, no matter whether you are in fullscreen-mode

or only are using a small window.

 

Tutorial starts here

  1. Creating a texture file:
    In order to make a good Gui, you need to know what you are making. I always
    create a texture with some pattern scratched on to it to see if all of it is shown.
    You probably will be using a 4:3 Format, for me it is 512x384.
     
  2. Basic GUI class:
    I don't think I have to explain this, just create your Gui with everything you want in it.
     
  3. Scaling properly:
    So first you Need to call
    GlStateManager.pushMatrix();

    where you draw your Rect, to be able to scale your Image.
    Then, you create two floats, which I will simply call x and y here

    float x = (float)width/512;  //512 -> my texture size
    float y = (float)height/384; //384 -> my texture size

    These two floats are equal to the factor by which you have to scale your Image.
    If you are asking yourself why that is, well, it is because if you divide the Resolution of your current
    Screen(which may be for example 1024 * 768) by your texture size, you get the exact number of how many
    times it fits into your Screen. After that, you can call the scale method:

    GlStateManager.scale(x, y, 1.0);

    This should scale your texture to your width and height.
    Now you can simply call the common bindTexture() and drawRect() methods.

    this.mc.renderEngine.bindTexture(cmbase);
    this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 512, 384, 512, 384);

    and Pop the Matrix

    GlStateManager.popMatrix();

    Now you should have your whole texture on the Screen.

    This is an example of how I did it:

    package armamenthaki.duelmonsters.gui;
    
    import armamenthaki.duelmonsters.util.Log;
    import ca.weblite.objc.Client;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.gui.GuiButton;
    import net.minecraft.client.gui.GuiScreen;
    import net.minecraft.client.gui.ScaledResolution;
    import net.minecraft.client.renderer.GlStateManager;
    import net.minecraft.util.ResourceLocation;
    
    public class GuiCardManager extends GuiScreen
    {
    	private static final ResourceLocation cmbase = new ResourceLocation("duelmonsters", "textures/textures/gui/guicmbase.png");
    	private GuiButton button1;
    	
    	@Override
        public void drawScreen(int mouseX, int mouseY, float partialTicks)
    	{
    		GlStateManager.pushMatrix();
    		float x = (float)width/512;  //512 -> my texture size
    		float y = (float)height/384; //384 -> my texture size
    		GlStateManager.scale(x, y, 1.0);
    		this.mc.renderEngine.bindTexture(cmbase);
    		this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 512, 384, 512, 384);
    		GlStateManager.popMatrix();
    	}
        

     

  4. I hope this helps, I know it isn't well explained but I saw many Posts(including myself) on the Internet by
    People who where trying that, and I didn't find another tutorial.
    If you have any questions feel free to ask, though I am no expert at modding.

    Finally, this is a Screenshot of my example, which shows that the 512/384 texture fills the whole Screen.
    A screenshot in Minecraft

Link to comment
Share on other sites

  • 2 weeks later...
On ‎07‎.‎07‎.‎2017 at 3:23 AM, fuzzybat23 said:

Where exactly do you put your png in the file structure, though?  Like, I'm going to assume you're using eclipse?  Would it go in src/main/resources, where mcmod.info is located?

I am not sure if I understand you correctly, but the file is located in src/main/resources/duelmonsters/textures/textures/gui/cmbase.png.
I have two texture Folders, one for textures in General, and one for textures which belong to minecraft related textures.
The Resource Location is defined at the beginning of the class.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.