Jump to content

[1.7.10] Removing a line of chat from the client


crazykid080

Recommended Posts

having trouble with the GuiNewChat, It is saying that I'm making a static reference to a non static method

Here is how my key input event handler is set up right now

public class KeyInputEventHandler {

private static Key getPressedKeyBinding(){
	if (Keybindings.clear.isPressed()){
		return Key.CLEAR;
	}else{
		return null;
	}

}


@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event){
	LogHelper.info(getPressedKeyBinding());
	if(Keybindings.clear.isPressed()){
		GuiNewChat.refreshChat();
	}
}
}

Link to comment
Share on other sites

Make a search in your IDE where that class is used. You will see fields where it's stored in. Get access that way, you don't make an instance yourself.

that did help and I found a better method for what I want but after I implemented the method it needed, it still said that I am implementing a static reference, the declaration for this method is:

public void deleteChatLine(int p_146242_1_)
    {
        Iterator iterator = this.field_146253_i.iterator();
        ChatLine chatline;

        while (iterator.hasNext())
        {
            chatline = (ChatLine)iterator.next();

            if (chatline.getChatLineID() == p_146242_1_)
            {
                iterator.remove();
            }
        }

 

and I have my code set up like this:

private static Key getPressedKeyBinding(){
	if (Keybindings.clear.isPressed()){
		return Key.CLEAR;
	}else{
		return null;
	}

}


@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event){
	LogHelper.info(getPressedKeyBinding());
	if(Keybindings.clear.isPressed()){
		GuiNewChat.deleteChatLine(1);
	}
}
}

Link to comment
Share on other sites

If you don't know how to not call a method statically when the method isn't static, I highly suggest you learn some basic Java first, and then come back to modding.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Well I figured out how to implement it non-statically, but now I'm having trouble checking if its the correct keybinding and why it's not being called

code:

	
private static Key getPressedKeyBinding(){
	if (Keybindings.clear.isPressed()){
		return Key.CLEAR;
	}else{
		return null;
	}

}

public int field_146253_i = 1;
public int p_146242_1_ = 1;
void deleteChatLine(){

}

@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event){
	LogHelper.debug(getPressedKeyBinding());
	if(getPressedKeyBinding() != null){
		deleteChatLine();
	}else{

	}
}
}

Link to comment
Share on other sites

ok, realized that the if statement wasn't firing, so after I changed it, it crashed me, am I doing something wrong in the code?

package com.crazykid080.ClearChat.client.handler;

import net.minecraft.client.gui.GuiNewChat;

import com.crazykid080.ClearChat.client.settings.Keybindings;
import com.crazykid080.ClearChat.reference.Key;
import com.crazykid080.ClearChat.utility.LogHelper;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;

public class KeyInputEventHandler {

private static Key getPressedKeyBinding(){
	if (Keybindings.clear.isPressed()){
		return Key.CLEAR;
	}else{
		return null;
	}

}

public int field_146253_i = 1;
public int p_146242_1_ = 1;
void deleteChatLine(){

}

void clearChatMessages(){

}

@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event){
	LogHelper.info(getPressedKeyBinding());
	if(getPressedKeyBinding().equals(Key.CLEAR)){
		LogHelper.fatal("IT WORKED");
		//deleteChatLine();
		//clearChatMessages();
	}else{

	}
}
}

Link to comment
Share on other sites

removed anything not an error report/stack trace

 

[16:31:13] [Client thread/FATAL]: Unreported exception thrown!

java.lang.NullPointerException

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36) ~[KeyInputEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic) ~[?:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540) ~[FMLCommonHandler.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1953) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]

at GradleStart.main(GradleStart.java:45) [start/:?]

[16:31:13] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----

// Who set us up the TNT?

 

Time: 2/12/15 4:31 PM

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1953)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028)

at net.minecraft.client.Minecraft.run(Minecraft.java:951)

at net.minecraft.client.main.Main.main(Main.java:164)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

 

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

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540)

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2555)

at net.minecraft.client.Minecraft.run(Minecraft.java:980)

at net.minecraft.client.main.Main.main(Main.java:164)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

Link to comment
Share on other sites

removed anything not an error report/stack trace

 

[16:31:13] [Client thread/FATAL]: Unreported exception thrown!

java.lang.NullPointerException

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36) ~[KeyInputEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic) ~[?:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540) ~[FMLCommonHandler.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1953) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]

at GradleStart.main(GradleStart.java:45) [start/:?]

[16:31:13] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----

// Who set us up the TNT?

 

Time: 2/12/15 4:31 PM

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1953)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028)

at net.minecraft.client.Minecraft.run(Minecraft.java:951)

at net.minecraft.client.main.Main.main(Main.java:164)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

 

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

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540)

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2555)

at net.minecraft.client.Minecraft.run(Minecraft.java:980)

at net.minecraft.client.main.Main.main(Main.java:164)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

You never did a nullpointer check seeing whether there was not any buttons being pressed.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

well I have fixed it, but now I need to find out how to get the code working I have it like this

package com.crazykid080.ClearChat.client.handler;

import net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.GuiNewChat;

import com.crazykid080.ClearChat.client.settings.Keybindings;
import com.crazykid080.ClearChat.reference.Key;
import com.crazykid080.ClearChat.utility.LogHelper;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;

public class KeyInputEventHandler {

private static Key getPressedKeyBinding(){
	if (Keybindings.clear.isPressed()){
		return Key.CLEAR;
	}else{
		return null;
	}

}

int field_146253_i = 1;
int p_146242_1_ = 1;


@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event){
	Key pressedKey = getPressedKeyBinding(); 
	LogHelper.info(pressedKey);
	if (pressedKey != null){
		if(pressedKey.equals(Key.CLEAR)){
			LogHelper.fatal("IT WORKED");
			GuiIngame gui = getChatGUI();
			GuiNewChat newChat = gui.getChatGUI();
			newChat.deleteChatLine(p_146242_1_);
		}else{

		}
	}
}


private GuiIngame getChatGUI() {
	return null;

}

}


Link to comment
Share on other sites

removed anything not an error report/stack trace

 

[16:31:13] [Client thread/FATAL]: Unreported exception thrown!

java.lang.NullPointerException

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36) ~[KeyInputEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic) ~[?:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540) ~[FMLCommonHandler.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1953) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]

at GradleStart.main(GradleStart.java:45) [start/:?]

[16:31:13] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----

// Who set us up the TNT?

 

Time: 2/12/15 4:31 PM

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1953)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028)

at net.minecraft.client.Minecraft.run(Minecraft.java:951)

at net.minecraft.client.main.Main.main(Main.java:164)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

 

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

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.crazykid080.ClearChat.client.handler.KeyInputEventHandler.handleKeyInputEvent(KeyInputEventHandler.java:36)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_KeyInputEventHandler_handleKeyInputEvent_KeyInputEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540)

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2555)

at net.minecraft.client.Minecraft.run(Minecraft.java:980)

at net.minecraft.client.main.Main.main(Main.java:164)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

You never did a nullpointer check seeing whether there was not any buttons being pressed.

my dad helped me with that

Link to comment
Share on other sites

I still need help with getting the command to fire, there is no errors being shown

package com.crazykid080.ClearChat.client.handler;

import net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.GuiNewChat;

import com.crazykid080.ClearChat.client.settings.Keybindings;
import com.crazykid080.ClearChat.reference.Key;
import com.crazykid080.ClearChat.utility.LogHelper;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;

public class KeyInputEventHandler {

private static Key getPressedKeyBinding(){
	if (Keybindings.clear.isPressed()){
		return Key.CLEAR;
	}else{
		return null;
	}

}


@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event){
	Key pressedKey = getPressedKeyBinding(); 
	LogHelper.debug(pressedKey);
	if (pressedKey != null){
		if(pressedKey.equals(Key.CLEAR)){
			deleteChatLine(1);
			LogHelper.info("fired");
		}else{

		}
	}
}


private void deleteChatLine(int p_146242_1_2) {

}



}



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.



×
×
  • Create New...

Important Information

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