Jump to content

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


Tinker

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Exception in thread "main" java.lang.IllegalStateException: Current Java is 1.8.0_271 but we require at least 17         at net.minecraftforge.bootstrap.shim.Main.main(Main.java:32) Never have successfully gotten a minecraft server up and running so I thought i'd try again. Instant unfixable issue.  
    • What MC version? What's the IP? Are any mods needed to be able to join?
    • Thank you for your answer ! Unfortunatly i have the same problem when i use setPos() public static int movingfunction(CommandContext<CommandSourceStack> context){ CommandSourceStack source = context.getSource(); if (!(source.getEntity() instanceof ServerPlayer)) { return 0; } ServerPlayer player = (ServerPlayer ) source.getEntity(); double moveSpeed = 0.5; for (int i =0; i<10000;i++) { LOGGER.info("running for the {} time", i); double x = player.getX() + player.getViewVector(1.0f).x * moveSpeed; double y = player.getY(); double z = player.getZ() + player.getViewVector(1.0f).z * moveSpeed ; Vec3 movementVec = new Vec3(x, y, z); LOGGER.info("x ={} y ={} z ={}", x, y, z); player.setPos( movementVec); } return 1; } With the logs i can see that x and z are increasing but once again my player is not moving. is there a function to use to sync the server and the client ? I also tried to use LocalPlayer instead of ServerPlayer but my code would stop when i got the object. Also i will change a bit the main topic but is there a way to similate key press ? i found KeyBinding.setKeyBindState on others post but it look like there is no more KeyBinding in 1.20   I found this code : KeyMapping.click(Minecraft.getInstance().options.keyUp.getKey()); But it doesn't seems to work   And i found this one : Minecraft.getInstance().options.keyUp.setDown(true); wich works but doesn't exactly do what i want , it doesn't release the key so for exemple i can't make him run. Minecraft.getInstance().options.keyUp.setDown(true); Minecraft.getInstance().options.keyUp.setDown(false); Minecraft.getInstance().options.keyUp.setDown(true); doesn't make him run
    • Add crash-reports with sites like https://paste.ee/ Maybe an issue with blur, essentials or cumulus_menus
  • Topics

×
×
  • Create New...

Important Information

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