Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7.2]KeyBinding.isPressed() Build:10.12.0.1024:

Featured Replies

Posted

I tried to write a KeyHandler, but when i used the Method "Keybinding.isPressed()" everything works fine in Eclipse, but after recompiling and testing with my normal Launcher i got this StackTrace:

 

 

java.lang.NoSuchMethodError: net.minecraft.client.settings.KeyBinding.isPressed()Z
at com.cruXcon.BreedingViewer.handler.KeyHandler.KeyInputEvent(KeyHandler.java:25)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_4_KeyHandler_KeyInputEvent_KeyInputEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122)
at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:454)
at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1868)
at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:953)
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:870)
at net.minecraft.client.main.Main.main(SourceFile:103)
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:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

This is the code, the StackTrace points to.

if(this.stats.isPressed())
    	{
    		EntityClientPlayerMP var2 = FMLClientHandler.instance().getClient().thePlayer;
    		FMLClientHandler.instance().displayGuiScreen(var2, new GuiCowMod());    
    	}	

Thanks for your help

did you do gradlew reobf and used the class files inside build folder?

that error its because your class files are not obfuscated

I typically encounter that error when I've accidentally tried to access a client-side only field or method from the server; key presses are all client-side only, so be sure that your method is never called, initialized, or otherwise accessed on the server side.

 

If you run the server version inside of Eclipse, it should also crash on you with this error, though when you run only the client you will never notice.

oh yeah also could ^^^, post your full code please.(funny fact i got that error back in 1.4 because of the reason ^^ said, how could i forget lol)

  • Author

Yes i reobfuscated and used the files of build/classes/main.

 

This is the full Code of KeyHandler.class

If you need more, just tell me.

 

package com.cruXcon.BreedingViewer.handler;

import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.settings.KeyBinding;

import com.cruXcon.BreedingViewer.GuiBreedingViewer;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;

public class KeyHandler
{
  private KeyBinding mybinding = new KeyBinding("BreedingViewer", 64, "key.categories.misc");
  
  public KeyHandler() {
    ClientRegistry.registerKeyBinding(this.mybinding);
  }

@SubscribeEvent
  public void KeyInputEvent(InputEvent.KeyInputEvent event) {
    if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class))
    {
    	if(mybinding.isPressed())
    	{
    		EntityClientPlayerMP var2 = FMLClientHandler.instance().getClient().thePlayer;
    		FMLClientHandler.instance().displayGuiScreen(var2, new GuiBreedingViewer());    
    	}	
    }
  }

}

 

 

and this is where i register the KeyHandler:

    public void load(FMLInitializationEvent event) 
    {	
    	proxy.registerRenderers();
    	FMLCommonHandler.instance().bus().register(new KeyHandler());
    	RenderBreedingItem Item = new RenderBreedingItem();
        Item.load();
    }

  • Author

Ok i changed it, but it doesn't work anyway. Any suggestions?

Now i changed the main part to:

 

    @EventHandler // used in 1.6.2
    public void load(FMLInitializationEvent event) 
    {	
    	proxy.registerRenderers();
    	proxy.registerKeybindings();
    	RenderBreedingItem Item = new RenderBreedingItem();
        Item.load();
    }

 

This is my ClientProxy:

 

package com.cruXcon.BreedingViewer.client;

import net.minecraft.client.model.ModelChicken;
import net.minecraft.client.model.ModelCow;
import net.minecraft.client.model.ModelHorse;
import net.minecraft.client.model.ModelOcelot;
import net.minecraft.client.model.ModelPig;
import net.minecraft.client.model.ModelSheep1;
import net.minecraft.client.model.ModelSheep2;
import net.minecraft.client.model.ModelWolf;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityMooshroom;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityWolf;
import com.cruXcon.BreedingViewer.CommonProxy;
import com.cruXcon.BreedingViewer.RenderCowModChicken;
import com.cruXcon.BreedingViewer.RenderCowModCow;
import com.cruXcon.BreedingViewer.RenderCowModHorse;
import com.cruXcon.BreedingViewer.RenderCowModMooshroom;
import com.cruXcon.BreedingViewer.RenderCowModOcelot;
import com.cruXcon.BreedingViewer.RenderCowModPig;
import com.cruXcon.BreedingViewer.RenderCowModSheep;
import com.cruXcon.BreedingViewer.RenderCowModWolf;
import com.cruXcon.BreedingViewer.handler.KeyHandler;

import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
public class ClientProxy extends CommonProxy {

@Override
    public void registerRenderers() {
	RenderingRegistry.registerEntityRenderingHandler(EntityCow.class, new RenderCowModCow(new ModelCow(),0.7F));
	RenderingRegistry.registerEntityRenderingHandler(EntityMooshroom.class, new RenderCowModMooshroom(new ModelCow(), 0.5F));
	RenderingRegistry.registerEntityRenderingHandler(EntitySheep.class, new RenderCowModSheep(new ModelSheep2(), new ModelSheep1(), 0.7F));
	RenderingRegistry.registerEntityRenderingHandler(EntityPig.class, new RenderCowModPig(new ModelPig(), new ModelPig(0.5F), 0.7F));
	RenderingRegistry.registerEntityRenderingHandler(EntityChicken.class, new RenderCowModChicken(	new ModelChicken(), 0.2F));
	RenderingRegistry.registerEntityRenderingHandler(EntityWolf.class, new RenderCowModWolf(new ModelWolf(), new ModelWolf(), 0.5F));
	RenderingRegistry.registerEntityRenderingHandler(EntityOcelot.class, new RenderCowModOcelot(new ModelOcelot(), 0.4F));
	RenderingRegistry.registerEntityRenderingHandler(EntityHorse.class, new RenderCowModHorse(	new ModelHorse(),	0.7F));
}
@Override
public void registerKeybindings() {
	FMLCommonHandler.instance().bus().register(new KeyHandler());
}
   
}

 

And this is my CommonProxy

 

package com.cruXcon.BreedingViewer;

public class CommonProxy {

    // Client stuff
    public void registerRenderers() {
            // Nothing here as the server doesn't render graphics or entities!
    }
public void registerKeybindings() {

}
}

 

If that didn't fix it, then you are also accessing your key bindings indiscriminately somewhere. Look at the stack trace to see if you can't find the exact location that is posting the error; that will be where you need to add an 'if (world.isRemote)' with NO "!", because you want the client side.

  • Author

Okay, thank you for this.

The line where the StackTrace starts is: "if(mybinding.isPressed())"

 

I inserted world.isRemote but my Problem now is, how do i get the World Object and which one is right.

This is the part where i am accessing to the Keybind:

@SubscribeEvent
  	public void KeyInputEvent(InputEvent.KeyInputEvent event) {
    if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class))
    {
    	if(mybinding.isPressed() && world.isRemote)
    	{
    		EntityClientPlayerMP var2 = FMLClientHandler.instance().getClient().thePlayer;
    		FMLClientHandler.instance().displayGuiScreen(var2, new GuiBreedingViewer());    
    	}	
    }
  }

  • Author

KeyHandler was removed in 1.7.2

KeyHandler:

 

package com.cruXcon.BreedingViewer.handler;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.world.World;

import com.cruXcon.BreedingViewer.*;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;


public class KeyHandler
{
private KeyBinding mybinding = new KeyBinding("BreedingViewer", 64, "key.categories.misc");

public KeyHandler() 
{
	ClientRegistry.registerKeyBinding(this.mybinding);
    }

@SubscribeEvent
  	public void KeyInputEvent(InputEvent.KeyInputEvent event) {
    if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class))
    {
    	if(mybinding.isPressed() && BreedingViewer.world.isRemote)
    	{
    		EntityClientPlayerMP var2 = FMLClientHandler.instance().getClient().thePlayer;
    		FMLClientHandler.instance().displayGuiScreen(var2, new GuiBreedingViewer());    
    	}	
    }
  }

}

 

The KeyBinding.class is placed in net.minecraft.client.settings

 

package net.minecraft.client.settings;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.IntHashMap;

@SideOnly(Side.CLIENT)
public class KeyBinding implements Comparable
{
    private static final List keybindArray = new ArrayList();
    private static final IntHashMap hash = new IntHashMap();
    private static final Set keybindSet = new HashSet();
    private final String keyDescription;
    private final int keyCodeDefault;
    private final String keyCategory;
    private int keyCode;
    /**
     * because _303 wanted me to call it that(Caironater)
     */
    private boolean pressed;
    private int pressTime;
    private static final String __OBFID = "CL_00000628";

    public static void onTick(int par0)
    {
        if (par0 != 0)
        {
            KeyBinding keybinding = (KeyBinding)hash.lookup(par0);

            if (keybinding != null)
            {
                ++keybinding.pressTime;
            }
        }
    }

    public static void setKeyBindState(int par0, boolean par1)
    {
        if (par0 != 0)
        {
            KeyBinding keybinding = (KeyBinding)hash.lookup(par0);

            if (keybinding != null)
            {
                keybinding.pressed = par1;
            }
        }
    }

    public static void unPressAllKeys()
    {
        Iterator iterator = keybindArray.iterator();

        while (iterator.hasNext())
        {
            KeyBinding keybinding = (KeyBinding)iterator.next();
            keybinding.unpressKey();
        }
    }

    public static void resetKeyBindingArrayAndHash()
    {
        hash.clearMap();
        Iterator iterator = keybindArray.iterator();

        while (iterator.hasNext())
        {
            KeyBinding keybinding = (KeyBinding)iterator.next();
            hash.addKey(keybinding.keyCode, keybinding);
        }
    }

    public static Set getKeybinds()
    {
        return keybindSet;
    }

    public KeyBinding(String p_i45001_1_, int p_i45001_2_, String p_i45001_3_)
    {
        this.keyDescription = p_i45001_1_;
        this.keyCode = p_i45001_2_;
        this.keyCodeDefault = p_i45001_2_;
        this.keyCategory = p_i45001_3_;
        keybindArray.add(this);
        hash.addKey(p_i45001_2_, this);
        keybindSet.add(p_i45001_3_);
    }

    public boolean getIsKeyPressed()
    {
        return this.pressed;
    }

    public String getKeyCategory()
    {
        return this.keyCategory;
    }

    public boolean isPressed()
    {
        if (this.pressTime == 0)
        {
            return false;
        }
        else
        {
            --this.pressTime;
            return true;
        }
    }

    private void unpressKey()
    {
        this.pressTime = 0;
        this.pressed = false;
    }

    public String getKeyDescription()
    {
        return this.keyDescription;
    }

    public int getKeyCodeDefault()
    {
        return this.keyCodeDefault;
    }

    public int getKeyCode()
    {
        return this.keyCode;
    }

    public void setKeyCode(int p_151462_1_)
    {
        this.keyCode = p_151462_1_;
    }

    public int compareTo(KeyBinding p_151465_1_)
    {
        int i = I18n.format(this.keyCategory, new Object[0]).compareTo(I18n.format(p_151465_1_.keyCategory, new Object[0]));

        if (i == 0)
        {
            i = I18n.format(this.keyDescription, new Object[0]).compareTo(I18n.format(p_151465_1_.keyDescription, new Object[0]));
        }

        return i;
    }

    public int compareTo(Object par1Obj)
    {
        return this.compareTo((KeyBinding)par1Obj);
    }
}

 

That's a shame about the KeyHandler class being absent... it was pretty handy.

 

Well, the KeyInputEvent should only be firing on the client side anyway, so you shouldn't need to bother with checking if the world is remote.

 

Is it still giving the exact same error, that isPressed() method doesn't exist? Are you sure you are supposed to be registering the KeyHandler to the FMLCommonHandler, then? Perhaps it is registered to the EVENT_BUS or FMLClientHandler.

 

Try changing it to something else. Sorry I haven't started modding for 1.7 yet, so I can't tell you for sure, but that would be my guess.

I'd think you didn't reobfuscate or something went wrong with mcp mappings.

 

gradlew --refresh-dependencies build

Then try the jar.

  • Author

Thank you Dude!

In the end this was the solution:

gradlew --refresh-dependencies build

 

This thread can be closed.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.