Jump to content

[1.7.10] Issues with Proxies


ravingmadlunatic

Recommended Posts

Before I start, I would like to say that I am new to programming in java so I apologize if I get any terminology wrong.

 

I've been following bedrockminers tutorial for proxies which can be found here: http://bedrockminer.jimdo.com/modding-tutorials/basic-modding/proxies/

 

I created the CommonProxy class and this is where I have gotten stuck. His code has the FLM initialization events in them but without importing those events.

 

package com.bedrockminer.tutorial;

public class CommonProxy {

    public void preInit(FMLPreInitializationEvent e) {

    }

    public void init(FMLInitializationEvent e) {

    }

    public void postInit(FMLPostInitializationEvent e) {

    }
}

 

I found that I cannot go on to the next step without importing the events.

 

In addition, eclipse does not seem to understand the @SidedProxy annotation.

 

@SidedProxy(clientSide="com.bedrockminer.tutorial.ClientProxy", serverSide="com.bedrockminer.tutorial.ServerProxy")
public static CommonProxy proxy;

 

When I add this code to the main class, @sidedproxy invokes a "cannot be resolved to a type" error.

 

I realize, in hindsight, i'm probably in way over my head at this point. My knowledge of Java is incredibly rudimentary. Still, I would like to work towards an understanding of what I am doing wrong.

 

Here is my code for the Main.java, ClientProxy.java, ServerProxy.java, and CommonProxy.java classes. The name of the package differ from his code and mine.

 

Main.java

package com.ravingmadlunatic.birds;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = Main.MODID, name = Main.MODNAME, version = Main.VERSION)
public class Main {

        public static final String MODID = "birds";
        public static final String MODNAME = "Realistic Bird Mod";
        public static final String VERSION = "1.0.0";
        
        @Instance
        public static Main instance = new Main();
        
        /**
         * Run before anything else. Read your config, create blocks, items, etc, and 
         * register them with the GameRegistry.
         */
       
        @SidedProxy(clientSide="com.ravingmadlunatic.birds.CombinedClientProxy", serverSide="com.ravingmadlunatic.birds.DedicatedServerProxy")
        public static CommonProxy proxy;
        
        @EventHandler
        public void preInit(FMLPreInitializationEvent e) {
        	this.proxy.preInit(e);
        }
        
        /**
         * Do your mod setup. Build whatever data structures you care about. Register recipes.
         */
        @EventHandler
        public void init(FMLInitializationEvent e) {
        	this.proxy.init(e);
                
        }
        
        /**
         * Handle interaction with other mods, complete your setup based on this.
         */
        @EventHandler
        public void postInit(FMLPostInitializationEvent e) {
        	this.proxy.postInit(e);
        
        }
}

 

CommonProxy.java

package com.ravingmadlunatic.birds;

public class CommonProxy {

    public void preInit(FMLPreInitializationEvent e) {

    }

    public void init(FMLInitializationEvent e) {

    }

    public void postInit(FMLPostInitializationEvent e) {

    }
  
}

 

ServerProxy.java

package com.ravingmadlunatic.birds;

public class ServerProxy extends CommonProxy {

/* (non-Javadoc)
 * @see com.ravingmadlunatic.birds.CommonProxy#preInit(cpw.mods.fml.common.event.FMLPreInitializationEvent)
 */
@Override
public void preInit(FMLPreInitializationEvent e) {
	// TODO Auto-generated method stub
	super.preInit(e);
}

/* (non-Javadoc)
 * @see com.ravingmadlunatic.birds.CommonProxy#init(cpw.mods.fml.common.event.FMLInitializationEvent)
 */
@Override
public void init(FMLInitializationEvent e) {
	// TODO Auto-generated method stub
	super.init(e);
}

/* (non-Javadoc)
 * @see com.ravingmadlunatic.birds.CommonProxy#postInit(cpw.mods.fml.common.event.FMLPostInitializationEvent)
 */
@Override
public void postInit(FMLPostInitializationEvent e) {
	// TODO Auto-generated method stub
	super.postInit(e);
}

 

ClientProxy.java

package com.ravingmadlunatic.birds;

public class ClientProxy extends CommonProxy {

/* (non-Javadoc)
 * @see com.ravingmadlunatic.birds.CommonProxy#preInit(cpw.mods.fml.common.event.FMLPreInitializationEvent)
 */
@Override
public void preInit(FMLPreInitializationEvent e) {
	// TODO Auto-generated method stub
	super.preInit(e);
}

/* (non-Javadoc)
 * @see com.ravingmadlunatic.birds.CommonProxy#init(cpw.mods.fml.common.event.FMLInitializationEvent)
 */
@Override
public void init(FMLInitializationEvent e) {
	// TODO Auto-generated method stub
	super.init(e);
}

/* (non-Javadoc)
 * @see com.ravingmadlunatic.birds.CommonProxy#postInit(cpw.mods.fml.common.event.FMLPostInitializationEvent)
 */
@Override
public void postInit(FMLPostInitializationEvent e) {
	// TODO Auto-generated method stub
	super.postInit(e);
}	

}

Link to comment
Share on other sites

  • 2 weeks later...

I think one of the most important things when beginning with Java and/or modding is to learn to use your IDE (e.g. Eclipse) effectively.  A good IDE will give flag the majority of errors, will give you good suggestions on how to fix things, and allow you to follow the call hierarchy back through the vanilla code.

 

For example, in Eclispe in the preferences for java code style you can set it up so it will automatically insert @Override statements.  I find this is really useful because it is very easy to write a method in your custom class which you think should override but you mess it up slightly essentially creating a different method that won't be called.

 

You can also set up Eclipse to automatically put in imports, at least for the cases where it can uniquely resolve them, and take out unused imports.

 

You can right-click on a method and choose "Call Hierarchy" and it will show you all the other code that calls the method.  I highly suggest you spend a couple hours following the call hierarchies for the vanilla code -- like take a vanilla block class and select a method in its code and find out what calls it.  This is hugely useful as a modder because the API isn't well documented so you often have to go into the vanilla code to confirm that it does what you expect.  You'll also get a lot of coding ideas by exploring the code call hierarchies.

 

You can right-click on any type, method or class and choose "Declaration" and it will take you to the code for that item.

 

Anyway, I'm just saying to check out the various preferences in your IDE and learn to use it proficiently.  Then you'll be able to correct most coding mistakes yourself without relying on the forum here!

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

  • 2 years later...

No better way to learn the IDE than working a project, IMO.

 

I see this conversation is from years ago, but I was just now having the same problem starting out modding for Minecraft 1.12.2, including the problem the OP mentioned wherein "eclipse does not seem to understand the @SidedProxy annotation" so I'm posting for everyone reading this who's still running into this problem.

 

The error I was getting was "SidedProxy cannot be resolved to a type".

Not sure if this is the right solution, but I added this to my Main and it removed the error message:

 

import net.minecraftforge.fml.common.SidedProxy;

 

HTH.

-ziz

 

Edited by zizbird
Added clarification of target audience.
Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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