Jump to content

Recommended Posts

Posted

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

}

  • 2 weeks later...
Posted

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/

  • 2 years later...
Posted (edited)

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.
  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Make a test with another Launcher like the Curseforge Launcher, MultiMC or AT Launcher
    • can anyone help me i am opening forge and add modpacks and then it says unable to update native luancher and i redownlaod java and the luancher it self?
    • The problem occurs also in 1.20.1 Forge, but with an "Error executing task on client" instead. I have "Sinytra Connector" installed. On 1.21.5 Fabric, there is no problem. When this happens, the chat message before the death screen appears gets sent, with an extra dash added.
    • Well, as usual, it was user error. Naming mismatch in sounds.json.  Please delete this post if you find it necessary. 
    • Hello Forge community.  I'm running into an issue with a mod I'm working on.  To preface, I can call /playsound modId:name music @a and I can hear the sound I registered being played in game. Great!  However, I cannot get it to trigger via my mod code.    Registration: public static final RegistryObject<SoundEvent> A_WORLD_OF_MADNESS = SOUND_EVENTS.register("a_world_of_madness", () -> new SoundEvent(new ResourceLocation("tetheredsouls", "a_world_of_madness")));   Playback: Minecraft mc = Minecraft.getInstance(); if (!(mc.player instanceof LocalPlayer) || mc.level == null) return; LocalPlayer player = (LocalPlayer) mc.player; BlockPos pos = player.blockPosition(); SoundEvent track = ModSounds.A_WORLD_OF_MADNESS.get(); System.out.println(track); System.out.println(pos); System.out.println(player); // play exactly like the tutorial: client-only, at the player's position try { mc.level.playLocalSound( player.getX(), player.getY(), player.getZ(), track, SoundSource.MUSIC, // Or MASTER if needed 1f, 1f, false ); System.out.println("[DEBUG] playSound success: " + track.getLocation()); } catch (Exception e) { System.err.println("[ERROR] Failed to play sound: " + track.getLocation()); e.printStackTrace(); } Sounds.json:   { "theme_of_laura": { "category": "music", "sounds": [ { "name": "tetheredsouls:a_world_of_madness", "stream": true } ] } } Things I have tried: - multiple .ogg files. Short .ogg files (5 seconds, <100KB).  - default minecraft sounds imported from import net.minecraft.sounds.SoundEvents; These work given my code. No idea why these are different.  - playSound() method, as well as several others in past iterations that did not work   I would be forever grateful if somebody could point me in the right direction. I've looked at several mod github repositories and found extremely similar code to what I'm doing. I've also found several threads in this forum that did not solve my issue. I just cannot figure out what I'm doing differently, and why I'm able to queue sounds manually with playsound but the code won't play it (despite confirming the code is being run with the debug statements.)
  • Topics

×
×
  • Create New...

Important Information

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