Jump to content

[1.7.10] How to save and render objects on scaledresolution?


Recommended Posts

Posted

Hey, i created a mod that adds some "Boxes" with information(FPS, CPS, Real world Hour) that you can move wherever you want on the screen, and i'm currently saving the location of the objects in not scaled resolution and rendering them on not scaled resolution, so, when you change from fullscreen to windowed it moves everywhere on the screen, so i was wondering if theres a way to fix this issue, thanks :)!

 

Renderer of one of those boxes on screen with info.


package com.henixmc.www.coders.infinity.mods.clockmod;

import com.henixmc.www.coders.infinity.mods.keystrokes.KeystrokesMod;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.settings.GameSettings;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;

public class CLOCKRenderer extends GuiScreen
{
    private final Minecraft mc;
    int index = 0;
    long x = 0L;

    public static Color rainbowEffect(float f, float fade)
    {
        int speed = 10000 / KeystrokesMod.chromaspeed;
        int color = Color.HSBtoRGB((float)(System.currentTimeMillis() % speed) / speed, 0.7F, 0.8F);
        Color c = new Color(color);
        return new Color(c.getRed() / 255.0F * fade, c.getGreen() / 255.0F * fade, c.getBlue() / 255.0F * fade, c.getAlpha() / 255.0F);
    }

    public CLOCKRenderer()
    {
        this.mc = Minecraft.getMinecraft();
    }

    @SubscribeEvent
    public void onRenderGameOverlay(RenderGameOverlayEvent event)
    {
        if ((event.type != RenderGameOverlayEvent.ElementType.TEXT) || (event.isCancelable())) {
            return;
        }
        if (!KeystrokesMod.enabledClock) {
            return;
        }
        if (this.mc.gameSettings.showDebugInfo) {
            return;
        }
        int clockcolor = Integer.MAX_VALUE;
        if (KeystrokesMod.ColorsClock == 0)
        {
            clockcolor = 2130706432;
        }
        else if (KeystrokesMod.ColorsClock == 1)
        {
            clockcolor = 2130706602;
        }
        else if (KeystrokesMod.ColorsClock == 2)
        {
            clockcolor = 2130749952;
        }
        else if (KeystrokesMod.ColorsClock == 3)
        {
            clockcolor = 2130750122;
        }
        else if (KeystrokesMod.ColorsClock == 4)
        {
            clockcolor = 2141847552;
        }
        else if (KeystrokesMod.ColorsClock == 5)
        {
            clockcolor = 2141847722;
        }
        else if (KeystrokesMod.ColorsClock == 6)
        {
            clockcolor = 2147461632;
        }
        else if (KeystrokesMod.ColorsClock == 7)
        {
            clockcolor = 2141891242;
        }
        else if (KeystrokesMod.ColorsClock == 8)
        {
            clockcolor = 2136298837;
        }
        else if (KeystrokesMod.ColorsClock == 9)
        {
            clockcolor = 2136299007;
        }
        else if (KeystrokesMod.ColorsClock == 10)
        {
            clockcolor = 2136342357;
        }
        else if (KeystrokesMod.ColorsClock == 11)
        {
            clockcolor = 2136342527;
        }
        else if (KeystrokesMod.ColorsClock == 12)
        {
            clockcolor = 2147439957;
        }
        else if (KeystrokesMod.ColorsClock == 13)
        {
            clockcolor = 2147440127;
        }
        else if (KeystrokesMod.ColorsClock == 14)
        {
            clockcolor = 2147483477;
        }
        else if (KeystrokesMod.ColorsClock == 15)
        {
            clockcolor = Integer.MAX_VALUE;
        }
        else if (KeystrokesMod.ColorsClock == 16)
        {
            clockcolor = rainbowEffect(this.index + (float)this.x * 4000.0F, 1.0F).getRGB();
        }
        else if (KeystrokesMod.ColorsClock == 17)
        {
            Color textdemocolor = new Color(KeystrokesMod.r2, KeystrokesMod.g2, KeystrokesMod.b2, KeystrokesMod.alpha2);
            clockcolor = textdemocolor.getRGB();
        }
        String timeStamp1 = new SimpleDateFormat("hh:mm:ss").format(new Date());
        String timeStamp = timeStamp1;
        if (KeystrokesMod.BackgroundBox)
        {
            Color mycolour = new Color(KeystrokesMod.r, KeystrokesMod.g, KeystrokesMod.b, KeystrokesMod.alpha);

            Gui.drawRect(KeystrokesMod.coordsClockX, KeystrokesMod.coordsClockY, KeystrokesMod.coordsClockX + 58, KeystrokesMod.coordsClockY + 13, mycolour.getRGB());

            this.mc.fontRenderer.drawString(timeStamp, KeystrokesMod.coordsClockX + 9, KeystrokesMod.coordsClockY + 3, clockcolor);
        }
        if (!KeystrokesMod.BackgroundBox) {
            this.mc.fontRenderer.drawStringWithShadow(timeStamp, KeystrokesMod.coordsClockX + 9, KeystrokesMod.coordsClockY + 3, clockcolor);
        }


    }

}

 

[/CODE]

 

Code to move it aroung the screen and save the position:

[CODE]

package com.henixmc.www.coders.infinity.mods.clockmod.settings;

import com.henixmc.www.coders.infinity.mods.keystrokes.Colors;
import com.henixmc.www.coders.infinity.mods.keystrokes.KeystrokesMod;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.EventBus;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;

public class GuiSettings
  extends GuiScreen
{
  int index = 0;
  long x = 0L;
  private boolean isDragging;
  private int lastX;
  private int lastY;
  private GuiButton buttonToggle;
  private GuiButton buttonReset;
  private GuiButton buttonColor;
  private GuiButton buttonColorLeft;
  private GuiButton buttonColorRight;
  private GuiButton buttonAllign;
  private GuiButton BackgroundBoxbutton;
  
  public GuiSettings()
  {
    this.isDragging = false;
    this.lastX = 0;
    this.lastY = 0;
  }
  
  public static Color rainbowEffect(float f, float fade)
  {
    int speed = 10000 / KeystrokesMod.chromaspeed;
    int color = Color.HSBtoRGB((float)(System.currentTimeMillis() % speed) / speed, 0.7F, 0.8F);
    Color c = new Color(color);
    return new Color(c.getRed() / 255.0F * fade, c.getGreen() / 255.0F * fade, c.getBlue() / 255.0F * fade, c.getAlpha() / 255.0F);
  }
  
  public void initGui()
  {
    drawCenteredString(this.mc.fontRenderer, "Clock Mod by Infnity", this.width / 2, 4, -1);
    this.buttonList.add(this.buttonReset = new GuiButton(0, this.width / 2 - 75, this.height / 2 - 22, 150, 20, "Reset Position"));
    this.buttonList.add(this.buttonToggle = new GuiButton(1, this.width / 2 - 75, this.height / 2 - 44, 150, 20, "Enabled: " + KeystrokesMod.enabledClock));
    
    this.buttonList.add(this.buttonColor = new GuiButton(2, this.width / 2 - 75, this.height / 2 + 0, 150, 20, "Color: " + Colors.values()[KeystrokesMod.ColorsClock]));
    this.buttonList.add(this.buttonColorRight = new GuiButton(5, this.width / 2 + 76, this.height / 2 + 0, 20, 20, ">"));
    this.buttonList.add(this.buttonColorLeft = new GuiButton(6, this.width / 2 - 96, this.height / 2 + 0, 20, 20, "<"));
    
    this.buttonList.add(this.buttonAllign = new GuiButton(3, this.width / 2 - 75, this.height / 2 + 22, 150, 20, "Align under FPS"));
    this.buttonList.add(this.BackgroundBoxbutton = new GuiButton(4, this.width / 2 - 75, this.height / 2 + 44, 150, 20, "Background Box: " + KeystrokesMod.BackgroundBox));
  }
  
  public void display()
  {
    FMLCommonHandler.instance().bus().register(this);
  }
  
  @SubscribeEvent
  public void onClientTick(ClientTickEvent event)
  {
    FMLCommonHandler.instance().bus().unregister(this);
    Minecraft.getMinecraft().displayGuiScreen(this);
  }
  
  public void drawScreen(int x, int y, float partialTicks)
  {
    super.drawDefaultBackground();
    
    int clockcolor = Integer.MAX_VALUE;
    if (KeystrokesMod.ColorsClock == 0)
    {
      clockcolor = 2130706432;
    }
    else if (KeystrokesMod.ColorsClock == 1)
    {
      clockcolor = 2130706602;
    }
    else if (KeystrokesMod.ColorsClock == 2)
    {
      clockcolor = 2130749952;
    }
    else if (KeystrokesMod.ColorsClock == 3)
    {
      clockcolor = 2130750122;
    }
    else if (KeystrokesMod.ColorsClock == 4)
    {
      clockcolor = 2141847552;
    }
    else if (KeystrokesMod.ColorsClock == 5)
    {
      clockcolor = 2141847722;
    }
    else if (KeystrokesMod.ColorsClock == 6)
    {
      clockcolor = 2147461632;
    }
    else if (KeystrokesMod.ColorsClock == 7)
    {
      clockcolor = 2141891242;
    }
    else if (KeystrokesMod.ColorsClock == 8)
    {
      clockcolor = 2136298837;
    }
    else if (KeystrokesMod.ColorsClock == 9)
    {
      clockcolor = 2136299007;
    }
    else if (KeystrokesMod.ColorsClock == 10)
    {
      clockcolor = 2136342357;
    }
    else if (KeystrokesMod.ColorsClock == 11)
    {
      clockcolor = 2136342527;
    }
    else if (KeystrokesMod.ColorsClock == 12)
    {
      clockcolor = 2147439957;
    }
    else if (KeystrokesMod.ColorsClock == 13)
    {
      clockcolor = 2147440127;
    }
    else if (KeystrokesMod.ColorsClock == 14)
    {
      clockcolor = 2147483477;
    }
    else if (KeystrokesMod.ColorsClock == 15)
    {
      clockcolor = Integer.MAX_VALUE;
    }
    else if (KeystrokesMod.ColorsClock == 16)
    {
      clockcolor = rainbowEffect(this.index + (float)this.x * 4000.0F, 1.0F).getRGB();
    }
    else if (KeystrokesMod.ColorsClock == 17)
    {
      Color textdemocolor = new Color(KeystrokesMod.r2, KeystrokesMod.g2, KeystrokesMod.b2, KeystrokesMod.alpha2);
      clockcolor = textdemocolor.getRGB();
    }
    Color boxdemocolor = new Color(KeystrokesMod.r, KeystrokesMod.g, KeystrokesMod.b, KeystrokesMod.alpha);
    
    String timeStamp1 = new SimpleDateFormat("hh:mm:ss").format(new Date());
    String timeStamp = timeStamp1;
    if (KeystrokesMod.BackgroundBox)
    {
      Gui.drawRect(KeystrokesMod.coordsClockX, KeystrokesMod.coordsClockY, KeystrokesMod.coordsClockX + 58, KeystrokesMod.coordsClockY + 13, boxdemocolor.getRGB());
      this.mc.fontRenderer.drawString(timeStamp, KeystrokesMod.coordsClockX  + 9, KeystrokesMod.coordsClockY + 3, clockcolor);
    }
    if (!KeystrokesMod.BackgroundBox) {
      this.mc.fontRenderer.drawStringWithShadow(timeStamp, KeystrokesMod.coordsClockX + 9, KeystrokesMod.coordsClockY + 3, clockcolor);
    }
    drawCenteredString(this.mc.fontRenderer, "ClockMod by Infinity", this.width / 2, 4, -1);
    
    super.drawScreen(x, y, partialTicks);
  }
  
  protected void keyTyped(char c, int key)
  {
    if (key == 1) {
      this.mc.displayGuiScreen((GuiScreen)null);
    }
  }
  
  protected void mouseClicked(int x, int y, int time)
  {
    String timeStamp = new SimpleDateFormat("hh:mm:ss").format(new Date());
    
    int minX = KeystrokesMod.coordsClockX;
    int minY = KeystrokesMod.coordsClockY;
    int maxX = KeystrokesMod.coordsClockX + this.fontRendererObj.getStringWidth(timeStamp) + 30;
    int maxY = KeystrokesMod.coordsClockY + 12;
    if ((x >= minX) && (x <= maxX) && (y >= minY) && (y <= maxY))
    {
      this.isDragging = true;
      this.lastX = x;
      this.lastY = y;
    }
    super.mouseClicked(x, y, time);
  }
  
  protected void mouseMovedOrUp(int x, int y, int which)
  {
    if ((which == 0) && (this.isDragging)) {
      this.isDragging = false;
    }
    super.mouseMovedOrUp(x, y, which);
  }
  
  protected void mouseClickMove(int x, int y, int lastButtonClicked, long timeSinceClick)
  {
    if (this.isDragging)
    {
      KeystrokesMod.coordsClockX += x - this.lastX;
      KeystrokesMod.coordsClockY += y - this.lastY;
      this.lastX = x;
      this.lastY = y;
    }
    super.mouseClickMove(x, y, lastButtonClicked, timeSinceClick);
  }
  
  protected void actionPerformed(GuiButton button)
  {
    if (button == this.buttonReset)
    {
      KeystrokesMod.coordsClockX = 0;
      KeystrokesMod.coordsClockY = 0;
    }
    if (button == this.buttonToggle)
    {
      KeystrokesMod.enabledClock = !KeystrokesMod.enabledClock;
      this.buttonToggle.displayString = ("Enabled: " + KeystrokesMod.enabledClock);
    }
    if (button == this.BackgroundBoxbutton)
    {
      KeystrokesMod.BackgroundBox = !KeystrokesMod.BackgroundBox;
      this.BackgroundBoxbutton.displayString = ("Background Box: " + KeystrokesMod.BackgroundBox);
    }
    else if (button == this.buttonColor)
    {
      KeystrokesMod.ColorsClock += 1;
      if (KeystrokesMod.ColorsClock == Colors.values().length) {
        KeystrokesMod.ColorsClock = 0;
      }
      this.buttonColor.displayString = ("Color: " + Colors.values()[KeystrokesMod.ColorsClock]);
    }
    else if (button == this.buttonColorLeft)
    {
      KeystrokesMod.ColorsClock -= 1;
      if (KeystrokesMod.ColorsClock == -1) {
        KeystrokesMod.ColorsClock = 17;
      }
      this.buttonColor.displayString = ("Color: " + Colors.values()[KeystrokesMod.ColorsClock]);
    }
    else if (button == this.buttonColorRight)
    {
      KeystrokesMod.ColorsClock += 1;
      if (KeystrokesMod.ColorsClock == Colors.values().length) {
        KeystrokesMod.ColorsClock = 17;
      }
      this.buttonColor.displayString = ("Color: " + Colors.values()[KeystrokesMod.ColorsClock]);
    }
    else if (button == this.buttonAllign)
    {
      int cpsx = KeystrokesMod.counterPosXFPS;
      int cpsy = KeystrokesMod.counterPosYFPS;
      KeystrokesMod.coordsClockX = cpsx;
      KeystrokesMod.coordsClockY = cpsy + 15;
    }
  }
  
  public void onGuiClosed() {
      
      KeystrokesMod.saveSettingsClock();

  }
  
  public boolean doesGuiPauseGame()
  {
    return true;
  }
}
 

[/CODE]

Posted (edited)
  On 11/24/2017 at 9:43 PM, xInfinityZ said:

[/CODE]

Expand  

Oh, at least you tried.

Now add a  code tag at the top, then wrap it in a spoiler. Or better yet, make a github repo.

 

Also, update, 1.7.10 is no longer supported here.

 
Edited by Draco18s
  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • it was flywheel, it's solved now and i am reporting it but i am going to figure what create addon was the cause or if was create itself  
    • I deleted delightful and all farmers delight addon (just in case) and still i have the error :'(, i need to check mod by mod?
    • I'm developing a Forge mod for Minecraft 1.16.5 to run on CatServer (version 1.16.5-1d8d6313, Forge 36.2.39). My mod needs to get the player's UUID from a ServerPlayerEntity object within a Forge ServerChatEvent handler. When I use serverPlayerEntity.getUUID(), my mod compiles fine, but I get a java.lang.NoSuchMethodError: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; at runtime. I cannot use serverPlayerEntity.getUniqueID() as it causes a compile error (cannot find symbol). Is there a known issue with this on CatServer, or a recommended way for a Forge mod to reliably get a player's UUID from ServerPlayerEntity in this environment? My goal is to pass this UUID to the LuckPerms API (which is running as a Bukkit plugin and successfully connected via ServicesManager). erorr ChatMod: FMLServerStartedEvent received. Attempting to initialize LuckPerms connection... [22:45:20] [Server thread/INFO]: ⚙️ Початок ініціалізації LuckPerms API через Bukkit Services Manager... [22:45:20] [Server thread/INFO]: ✅ Bukkit ServicesManager успішно отримано. [22:45:20] [Server thread/INFO]: ✅ Реєстрацію сервісу LuckPerms знайдено. [22:45:20] [Server thread/INFO]: ✅ API LuckPerms успішно отримано від Bukkit plugin! [22:45:20] [Server thread/INFO]: Використовується реалізація: me.lucko.luckperms.common.api.LuckPermsApiProvider [22:45:20] [Server thread/INFO]: ✅ LuckPerms API схоже що успішно ініціалізовано через Bukkit Services Manager. [22:45:24] [User Authenticator #1/INFO]: UUID of player Hiklee is 92cd7721-2652-3867-896b-2ceba5b99306 [22:45:25] [Server thread/INFO]: Using new advancement loading for net.minecraft.advancements.PlayerAdvancements@24cb7a68 [22:45:26] [Server thread/INFO]: Hiklee[/127.0.0.1:41122] logged in with entity id 210 at (92.23203876864889, 95.6183020148442, 68.24087802017877) [22:45:28] [Async Chat Thread - #0/INFO]: ✅ Скасовано стандартне відправлення чату! [22:45:28] [Async Chat Thread - #0/ERROR]: Exception caught during firing event: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; Index: 1 Listeners: 0: NORMAL 1: ASM: class com.example.chatmod.ChatEventHandler onPlayerChat(Lnet/minecraftforge/event/ServerChatEvent;)V java.lang.NoSuchMethodError: net.minecraft.entity.player.ServerPlayerEntity.getUUID()Ljava/util/UUID; at com.example.chatmod.ChatPacketHandler.getPlayerPrefix(ChatPacketHandler.java:46) at com.example.chatmod.ChatEventHandler.onPlayerChat(ChatEventHandler.java:32) at net.minecraftforge.eventbus.ASMEventHandler_1_ChatEventHandler_onPlayerChat_ServerChatEvent.invoke(.dynamic) at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:303) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) at net.minecraftforge.common.ForgeHooks.onServerChatEvent(ForgeHooks.java:493) at net.minecraft.network.play.ServerPlayNetHandler.chat(ServerPlayNetHandler.java:1717) at net.minecraft.network.play.ServerPlayNetHandler.func_244548_c(ServerPlayNetHandler.java:1666) at net.minecraft.network.play.ServerPlayNetHandler.func_147354_a(ServerPlayNetHandler.java:1605) at net.minecraft.network.play.client.CChatMessagePacket.lambda$handle$0(CChatMessagePacket.java:34) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:750
    • Thank you so much for your help, I'll try it as soon as I can. I have a genuine question because I'm not familiar with the matter: Can a recipe error cause something as serious as the AMD error?
    • When i try to launch my modpack, the instance crashes and this is sent to the logs: Time: 2025-05-27 23:07:18 Description: Rendering overlay Below is the full log: https://mclo.gs/jP5G2EH
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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