Jump to content

[Solved] [1.6.4] Disabling the F3 menu/coordinates


Recommended Posts

Posted

Hello Forge,

 

This is one of my first real undertakings with modding. I've done a lot of work with Bukkit and am familiar with Java though. My question is simply a lack of understanding on how I'd accomplish this.

 

For my survival server, I'd like to add a mod to the modpack I'm distributing which disallows players from seeing their coordinates. The simplest way I thought of to do so is by disabling the debug menu which appears when F3 is pressed. If I disable all action linked to the button, the problem would be solved. However, I just have no idea where to find the code responsible for this in my 1.6.4 MCP workspace. I ran a search in Eclipse for "f3" and "F3" and nothing turned up. Is there anyone here more familiar with the Minecraft code who can point me in the right direction for figuring this out?

 

Thanks.

Posted

Thanks a bunch!

 

Now, do you have any suggestions on how I could modify this class? Would I need to use ASM and learn how to make a coremod if I wanted to change it?

Posted
  On 3/18/2014 at 3:28 AM, Tinker said:

Thanks a bunch!

 

Now, do you have any suggestions on how I could modify this class? Would I need to use ASM and learn how to make a coremod if I wanted to change it?

Yes, that would be the easiest way (if you didn't want to have people manualy replace the class in their 1.6.4.jar file). Sadly, there aren't much java ASM tutorials out there. I hope someone would make a tutorial on that in the future.

Potato's have skin. I have skin. Therefore, i am a potato.

 

Follow me on Twitter!

http://www.twitter.com/I_Mod_Minecraft

Posted

Thanks for the tutorials guys. I'm running into a lot of trouble trying to get this running though...anyone able to help troubleshoot?

 

package us.teamtinker.hide;

import java.io.File;
import java.util.Map;

import cpw.mods.fml.relauncher.IFMLLoadingPlugin;

public class CBFMLoadingPlugin implements cpw.mods.fml.relauncher.IFMLLoadingPlugin {


public static File location;

@Override
public String[] getLibraryRequestClass() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public String[] getASMTransformerClass() {
//This will return the name of the class "mod.culegooner.CreeperBurnCore.CBClassTransformer"
	return new String[]{CBClassTransformer.class.getName()};
}

@Override
public String getModContainerClass() {
	//This is the name of our dummy container "mod.culegooner.CreeperBurnCore.CBDummyContainer"
	return CBDummyContainer.class.getName();
}

@Override
public String getSetupClass() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public void injectData(Map<String, Object> data) {
	//This will return the jar file of this mod
	location = (File) data.get("coremodLocation");
	System.out.println("*** Transformer jar location location.getName: " +location.getName());
}

}

 

package us.teamtinker.hide;

import java.io.File;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import net.minecraft.launchwrapper.IClassTransformer;

public class CBClassTransformer implements IClassTransformer {

@Override
public byte[] transform(String arg0, String arg1, byte[] arg2) {

	// Check if the JVM is about to process the te.class or the
	// EntityCreeper.class
	if (arg0.equals("avj")
			|| arg0.equals("net.minecraft.client.gui.GuiIngame")) {
		System.out
				.println("********* INSIDE HIDE TRANSFORMER ABOUT TO PATCH: "
						+ arg0);
		arg2 = patchClassInJar(arg0, arg2, arg0,
				CBFMLoadingPlugin.location);
	}
	return arg2;
}

// a small helper method that takes the class name we want to replace and
// our jar file.
// It then uses the java zip library to open up the jar file and extract the
// classes.
// Afterwards it serializes the class in bytes and pushes it on to the JVM.
// with the original bytes that JVM was about to process ignored completly

public byte[] patchClassInJar(String name, byte[] bytes, String ObfName,
		File location) {
	try {
		// open the jar as zip
		ZipFile zip = new ZipFile(location);
		// find the file inside the zip that is called avj.class or
		// net.minecraft.client.gui.GuiIngame.class
		// replacing the . to / 
		ZipEntry entry = zip.getEntry(name.replace('.', '/') + ".class");

		if (entry == null) {
			System.out
					.println(name + " not found in " + location.getName());
		} else {

			// serialize the class file into the bytes array
			InputStream zin = zip.getInputStream(entry);
			bytes = new byte[(int) entry.getSize()];
			zin.read(bytes);
			zin.close();
			System.out.println("[" + "Hide Coordinates" + "]: " + "Class "
					+ name + " patched!");
		}
		zip.close();
	} catch (Exception e) {
		throw new RuntimeException("Error overriding " + name + " from "
				+ location.getName(), e);
	}

	// return the new bytes
	return bytes;
}
}

 

package us.teamtinker.hide;

import java.util.Arrays;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

public class CBDummyContainer extends DummyModContainer {

public CBDummyContainer() {

	super(new ModMetadata());
	ModMetadata meta = getMetadata();
	meta.modId = "HideCoords";
	meta.name = "HideCoordsCore";
	meta.version = "@VERSION@"; //String.format("%d.%d.%d.%d", majorVersion, minorVersion, revisionVersion, buildVersion);
	meta.credits = "Roll Credits ...";
	meta.authorList = Arrays.asList("Tim Clancy");
	meta.description = "";
	meta.url = "www.teamtinker.us";
	meta.updateUrl = "";
	meta.screenshots = new String[0];
	meta.logoFile = "";

}

@Override
public boolean registerBus(EventBus bus, LoadController controller) {
	bus.register(this);
	return true;
}


@Subscribe
public void modConstruction(FMLConstructionEvent evt){

}

@Subscribe
public void init(FMLInitializationEvent evt) {

}

@Subscribe
public void preInit(FMLPreInitializationEvent evt) {

}

@Subscribe
public void postInit(FMLPostInitializationEvent evt) {

}
}

 

Far as I know, these are the three things I need in order for the plugin to run...but testing it in Eclipse consistently throws the error:

2014-03-18 22:04:32 [sEVERE] [ForgeModLoader] Unable to launch
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
at net.minecraft.launchwrapper.Launch.main(Launch.java:27)
Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/gui/GuiIngame
at net.minecraft.client.main.Main.main(Main.java:37)
... 6 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.gui.GuiIngame
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:186)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Caused by: java.lang.ClassFormatError: Invalid code attribute name index 0 in class file net/minecraft/client/gui/GuiIngame
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:178)
... 9 more

 

What could be the problem here?

My .jar looks like this:

META-INF
- MANIFEST.MF (points to us.teamtinker.hide.CBFMLoadingPlugin as the main plugin loading class)
us/teamtinker/hide/(the three classes located above)
net/minecraft/client/gui/GuiIngame.class (containing my modifications)
GuiIngame.class (also modified)
avj.class (modified and obfuscated)

 

I've been troubleshooting this all day, and you guys have been so helpful thus far in getting this project rolling with me. Anyone able to help shed some light?

Posted

Why are you coremoding something that has an event?

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

I don't even pretend to be familiar with Forge, coming from an entirely Bukkit background. So there's an event for pressing F3 that I can disable?

Posted

Wouldn't cancelling the event in the GuiIngame class also cancel it from rendering its other components? I.e. things that aren't simply the debug menu?

Posted

Is there no event for detecting whether or not a specific key is being pressed, and then canceling that accordingly? That definitely seems to be the simplest way I could solve this problem, but I'm not able to find any keyboard events defined anywhere.

Posted

There is no event for detecting the key press {well, actually there is but ignore it for now}, But there are events for when shit is rendered on the screen.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

Thank you for your help so far, I'm definitely making progress. I've managed to properly setup the RenderGameOverlayEvent, and to cancel it. However, this stops the rendering of all GUIs on the screen--no pause menus, no hotbar, no inventory, nada. This is too indiscriminate for my purposes, although it does stop the use of F3. Is there any data I can pull from the event object which would allow me to cancel only the debug menu which appears when F3 is pressed? Or maybe a way in which I can cancel/uncancel the event when F3 is toggled?

Posted

Okay, I see that now. Thanks. Still having problems here though.

 

package us.teamtinker.hide;

import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class HideEventHandler {
@ForgeSubscribe
public void onRenderingCoordinates(RenderGameOverlayEvent event) {
	if (event.type.equals(RenderGameOverlayEvent.ElementType.TEXT)) {
		event.setCanceled(true);
	}
}
}

 

I have this event which hopefully cancels the rendering of the debug menu. None of the other sub-events I looked at seemed to apply to it. However, as soon as I attempt to load the world with this code in place, I get the following crash:

 

java.lang.IllegalArgumentException: Attempted to cancel a uncancelable event
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraftforge.event.Event.setCanceled(Event.java:104)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at us.teamtinker.hide.HideEventHandler.onRenderingCoordinates(HideEventHandler.java:11)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraftforge.event.ASMEventHandler_5_HideEventHandler_onRenderingCoordinates_RenderGameOverlayEvent.invoke(.dynamic)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraftforge.event.EventBus.post(EventBus.java:108)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraftforge.client.GuiIngameForge.post(GuiIngameForge.java:874)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraftforge.client.GuiIngameForge.renderHUDText(GuiIngameForge.java:696)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:155)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1014)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:946)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraft.client.Minecraft.run(Minecraft.java:838)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraft.client.main.Main.main(Main.java:93)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at java.lang.reflect.Method.invoke(Unknown Source)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
2014-03-19 11:32:58 [iNFO] [sTDOUT] 	at net.minecraft.launchwrapper.Launch.main(Launch.java:27)

 

So it looks like the TEXT sub-event is uncancelable. Is there anything I can do here?

Posted

Ah, thank you all so much. Canceling the RenderGameOverlayEvent.Pre worked so much better. :)

The plugin appears to be working as planned right now...and chat/signs/hotbar are all still functioning as expected. Just off the top of your collective heads, do any of you know of any definite drawbacks canceling all TEXT RenderGameOverlayEvents might cause, which I should be aware of? Thanks for all the help.

Posted
  On 3/19/2014 at 4:30 PM, diesieben07 said:

Not any that I know of, except that people might rage at you because their F3 doesn't work :D

 

Ah well, such is the price they pay for excellent survival servers. :)

Thanks for all your help guys, couldn't have done it without you all.

Posted

Off topic here just a bit... But, personally I would quit such a survival server immediately if it screwed with my DEBUG. I want to see things like my frame rate and chunk load times and may other useful things in the event of trouble. However, you might find some hardcore MC players who don't care or don't know about debug who may play.

Posted

I'm reopening my plea for help here...my mod is screwing with BattleGear 2 in how they both attempt to modify the GUI. This error is thrown whenever BattleGear 2 tries rendering its own GUI. As far as I can tell, there shouldn't be any conflict since I'm only canceling the TEXT pre event. But here's the error.

java.lang.NullPointerException
at us.teamtinker.hide.HideEventHandler.onRenderingCoordinates(HideEventHandler.java:10)
at net.minecraftforge.event.ASMEventHandler_14_HideEventHandler_onRenderingCoordinates_Pre.invoke(.dynamic)
at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)
at net.minecraftforge.event.EventBus.post(EventBus.java:108)
at mods.battlegear2.client.gui.BattlegearInGameGUI.renderGameOverlay(BattlegearInGameGUI.java:123)
at mods.battlegear2.client.BattlegearClientEvents.postRenderOverlay(BattlegearClientEvents.java:55)
at net.minecraftforge.event.ASMEventHandler_51_BattlegearClientEvents_postRenderOverlay_Post.invoke(.dynamic)
at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)
at net.minecraftforge.event.EventBus.post(EventBus.java:108)
at net.minecraftforge.client.GuiIngameForge.post(GuiIngameForge.java:874)
at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:212)
at net.minecraftforge.client.GuiIngameForge.func_73830_a(GuiIngameForge.java:141)
at net.minecraft.client.renderer.EntityRenderer.func_78480_b(EntityRenderer.java:1014)
at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:946)
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:838)
at net.minecraft.client.main.Main.main(SourceFile:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
at net.minecraft.launchwrapper.Launch.main(Launch.java:27)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at us.teamtinker.hide.HideEventHandler.onRenderingCoordinates(HideEventHandler.java:10)
at net.minecraftforge.event.ASMEventHandler_14_HideEventHandler_onRenderingCoordinates_Pre.invoke(.dynamic)
at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)
at net.minecraftforge.event.EventBus.post(EventBus.java:108)
at mods.battlegear2.client.gui.BattlegearInGameGUI.renderGameOverlay(BattlegearInGameGUI.java:123)
at mods.battlegear2.client.BattlegearClientEvents.postRenderOverlay(BattlegearClientEvents.java:55)
at net.minecraftforge.event.ASMEventHandler_51_BattlegearClientEvents_postRenderOverlay_Post.invoke(.dynamic)
at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)
at net.minecraftforge.event.EventBus.post(EventBus.java:108)
at net.minecraftforge.client.GuiIngameForge.post(GuiIngameForge.java:874)
at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:212)
at net.minecraftforge.client.GuiIngameForge.func_73830_a(GuiIngameForge.java:141)

 

Can anyone offer a bit of input? Thanks.

Posted

Obviously, cancelling this event would prevent other mods in-screen texts, if they planned to add those in such way.

 

On the Battlegear topic, you should have asked directly to the mod topic, you just are lucky I came in here.

Anyway, this crash shouldn't happen if you are listening to RenderGameOverlayEvent.Pre and using a newer Battlegear version.

Also, ElementType is an enum. You can do

if(event.type == RenderGameOverlayEvent.ElementType.TEXT) 

That would work the same.

Posted
  On 3/27/2014 at 10:34 PM, GotoLink said:

Obviously, cancelling this event would prevent other mods in-screen texts, if they planned to add those in such way.

 

On the Battlegear topic, you should have asked directly to the mod topic, you just are lucky I came in here.

Anyway, this crash shouldn't happen if you are listening to RenderGameOverlayEvent.Pre and using a newer Battlegear version.

Also, ElementType is an enum. You can do

if(event.type == RenderGameOverlayEvent.ElementType.TEXT) 

That would work the same.

 

Sadly I am not using the newest version of BattleGear, I'm developing for a 1.6.4 MCPC+ server.

 

This is my event, in all its glorious simplicity:

@ForgeSubscribe
public void onRenderingCoordinates(RenderGameOverlayEvent.Pre event) {
	if (event.type.equals(RenderGameOverlayEvent.ElementType.TEXT)) {
		event.setCanceled(true);
	}
}

 

Is there anything I can do, working within the constraints of my version right now, to fix this?

Thanks.

Posted

Is there perhaps any way to disallow the user to rebind keys?

If I can override what happens when F3 is pressed, without allowing my key to appear on the "Controls" tab, I can continue implementing this.

Posted

@ForgeSubscribe
public void onRenderingCoordinates(RenderGameOverlayEvent.Pre event) {
	if (event.type.equals(RenderGameOverlayEvent.ElementType.TEXT)) {
		event.setCanceled(true);
	}
}

 

This code has to be the problem. It's definitely not a fine enough comb to capture only the F3 menu rendering.

Is there any way I can check to see which class triggered this event, and only act if it was GuiInGame?

 

Deperate for help here.

Thanks.

Posted

Ho, you can extend the KeyBinding class so that it can't be rebind, then set its default as F3, and register it.

That should block the "F3" process, hopefully.

 

By the way, this

if(event.type == RenderGameOverlayEvent.ElementType.TEXT)

is an actual fix for the Battlegear incompatibility. I wonder if i was clear enough about it.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
  • Topics

×
×
  • Create New...

Important Information

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