Jump to content

Recommended Posts

Posted

So I was told that "only one string" needed to change for this 1.8.9 mod to become a 1.16.5 mod. Im not very sure what this line is as I am new to this coding thing, so I thought I might ask around. Thanks in advance.

Here is pt.1 of the code:
 

package studio.dreamys.gui;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.awt.Color;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.Session;
import org.apache.commons.io.IOUtils;
import org.lwjgl.input.Keyboard;
import studio.dreamys.TokenAuth;

public class SessionGui extends GuiScreen {
    private GuiScreen previousScreen;
    private String status = "Session:";
    private GuiTextField sessionField;
    private ScaledResolution sr;

    public SessionGui(GuiScreen previousScreen) {
        this.previousScreen = previousScreen;
    }

    public void func_73866_w_() {
        Keyboard.enableRepeatEvents(true);
        this.sr = new ScaledResolution(this.field_146297_k);
        this.sessionField = new GuiTextField(1, this.field_146297_k.field_71466_p, this.sr.func_78326_a() / 2 - 100, this.sr.func_78328_b() / 2, 200, 20);
        this.sessionField.func_146203_f(32767);
        this.sessionField.func_146195_b(true);
        this.field_146292_n.add(new GuiButton(998, this.sr.func_78326_a() / 2 - 100, this.sr.func_78328_b() / 2 + 30, 200, 20, "Login"));
        this.field_146292_n.add(new GuiButton(999, this.sr.func_78326_a() / 2 - 100, this.sr.func_78328_b() / 2 + 60, 200, 20, "Restore"));
        super.func_73866_w_();
    }

    public void func_146281_b() {
        Keyboard.enableRepeatEvents(false);
        super.func_146281_b();
    }

    public void func_73863_a(int mouseX, int mouseY, float partialTicks) {
        this.func_146276_q_();
        this.field_146297_k.field_71466_p.func_78276_b(this.status, this.sr.func_78326_a() / 2 - this.field_146297_k.field_71466_p.func_78256_a(this.status) / 2, this.sr.func_78328_b() / 2 - 30, Color.WHITE.getRGB());
        this.sessionField.func_146194_f();
        super.func_73863_a(mouseX, mouseY, partialTicks);
    }

    protected void func_146284_a(GuiButton button) throws IOException {
        if (button.field_146127_k == 998) {
            try {
                String session = this.sessionField.func_146179_b();
                String username;
                String uuid;
                String token;
                if (session.contains(":")) {
                    username = session.split(":")[0];
                    uuid = session.split(":")[1];
                    token = session.split(":")[2];
                } else {
                    HttpURLConnection c = (HttpURLConnection)(new URL("https://api.minecraftservices.com/minecraft/profile/")).openConnection();
                    c.setRequestProperty("Content-type", "application/json");
                    c.setRequestProperty("Authorization", "Bearer " + this.sessionField.func_146179_b());
                    c.setDoOutput(true);
                    JsonObject json = (new JsonParser()).parse(IOUtils.toString(c.getInputStream())).getAsJsonObject();
                    username = json.get("name").getAsString();
                    uuid = json.get("id").getAsString();
                    token = session;
                }

                this.field_146297_k.field_71449_j = new Session(username, uuid, token, "mojang");
                this.field_146297_k.func_147108_a(this.previousScreen);
            } catch (Exception var9) {
                this.status = "§cError: Couldn't set session (check mc logs)";
                var9.printStackTrace();
            }
        }

        if (button.field_146127_k == 999) {
            try {
                this.field_146297_k.field_71449_j = TokenAuth.originalSession;
                this.field_146297_k.func_147108_a(this.previousScreen);
            } catch (Exception var8) {
                this.status = "§cError: Couldn't restore session (check mc logs)";
                var8.printStackTrace();
            }
        }

        super.func_146284_a(button);
    }

    protected void func_73869_a(char typedChar, int keyCode) throws IOException {
        this.sessionField.func_146201_a(typedChar, keyCode);
        if (1 == keyCode) {
            this.field_146297_k.func_147108_a(this.previousScreen);
        } else {
            super.func_73869_a(typedChar, keyCode);
        }

    }
}

and heres pt.2 :
 

package studio.dreamys;

import java.awt.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.util.Session;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import studio.dreamys.gui.SessionGui;

@Mod(
    modid = "ta",
    name = "TokenAuth",
    version = "1.1.0"
)
public class TokenAuth {
    public static Minecraft mc = Minecraft.func_71410_x();
    public static Session originalSession;

    public TokenAuth() {
    }

    @EventHandler
    public void preInit(FMLPreInitializationEvent e) {
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void onInitGuiPost(GuiScreenEvent.InitGuiEvent.Post e) {
        if (e.gui instanceof GuiMultiplayer) {
            e.buttonList.add(new GuiButton(999, 5, 5, 100, 20, "TokenAuth"));
        }

    }

    @SubscribeEvent
    public void onDrawScreenPost(GuiScreenEvent.DrawScreenEvent.Post e) {
        if (e.gui instanceof GuiMultiplayer) {
            String status = String.format("User: §a%s §rUUID: §a%s", mc.field_71449_j.func_111285_a(), mc.field_71449_j.func_148255_b());
            Minecraft.func_71410_x().field_71466_p.func_78276_b(status, 115, 10, Color.WHITE.getRGB());
        }

    }

    @SubscribeEvent
    public void onActionPerformedPre(GuiScreenEvent.ActionPerformedEvent.Pre e) {
        if (e.gui instanceof GuiMultiplayer && e.button.field_146127_k == 999) {
            Minecraft.func_71410_x().func_147108_a(new SessionGui(e.gui));
        }

    }

    static {
        originalSession = mc.field_71449_j;
    }
}

 

  • 7 months later...

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

    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
    • Instructions on how to install newer Java can be found in the FAQ
    • That's just plain wrong... newer versions are much better optimised and start a lot faster than 1.8.9, both Forge and Minecraft itself. Comparing Fabric 1.21 with Forge 1.8 is like comparing apples and oranges... one's brand new and the other's over a decade old.
  • Topics

×
×
  • Create New...

Important Information

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