Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


Recommended Posts

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

Link to post
Share on other sites

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.

Link to post
Share on other sites

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();
    }

Link to post
Share on other sites

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() {

}
}

 

Link to post
Share on other sites

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());    
    	}	
    }
  }

Link to post
Share on other sites

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);
    }
}

 

Link to post
Share on other sites

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.

Link to post
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.

Guest
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 Privacy Policy.