1.8 - Proxies

Proxies are classes in a mod's code that differentiate between a client side instance of the mod and a server side instance of the mod. These are necessary when you create renderers and sound engines and can but do not necessarily have to be called before you register an item to be rendered. In this article, I'm going to show you how to create these proxies and how to use them in your mod class.

Creating Proxies
public class ClientProxy extends CommonProxy { @Override public void registerRenders { } } Then in the CommonProxy class add another registerRenders method:
 * 1) You first need to create a new package in your com.name.mod package and call it proxy. If the name of the source mod is already shown in the field, simply add '.proxy' after it.
 * 2) Inside the newly created package, add two classes: one called ClientProxy, and another called CommonProxy.
 * 3) Inside ClientProxy, make sure it extends CommonProxy and add a registerRenders method and an @Override annotation:

public class CommonProxy { public void registerRenders { } } Notice how we have two of the same methods in two classes. If you are experienced with Java you will know that that isn't allowed. However, since ClientProxy is extending CommonProxy, we can put a @Override annotation above the ClientProxy's method and, well, override the error. This annotation basically tells the class that these two methods are seperate: one is used on the client side, and the other is used on the server side.

Now that we have the classes in place, we need to add a reference to them in the Reference class. Open the Reference class and create two more final strings as follows:

public static final String CLIENT_PROXY_CLASS = "com.name.mod.proxy.ClientProxy"; public static final String SERVER_PROXY_CLASS = "com.name.mod.proxy.CommonProxy"; These strings provide the program with a directory to the two proxies we just created.

Now in your mod class add these two lines below your class declaration:

@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS) public static CommonProxy proxy; Be sure to import the @SidedProxy annotation and now you have proxies in your mod! We will be using these proxies when we create items in the next article.