Jump to content

Recommended Posts

Posted

Hi guys,

 

Just downloaded and got everything set up and wondering could someone please give me some pointers to how to create new custom server side commands that I can type into the chat. I am currently looking at the Commandkill.java class along with all the other CommandServer classes but still a bit confussed.

 

How would I get a hook into displaying how many drops are currently in the world?

 

Appreciate any help!

Posted

I recommend taking a look at this: http://www.minecraftforum.net/topic/1419836-131-forge-4x-events-howto/ to get some grounding on using events and event hooks.

 

As for creating commands your new command class should inherit from "CommandBase" and should be registered in the Server Command Manager after initialisation.

 

Something like this:

MinecraftServer server = ModLoader.getMinecraftServerInstance();
ICommandManager commandManager = server.getCommandManager();
ServerCommandManager serverCommandManager = ((ServerCommandManager)commandManager);
serverCommandManager.registerCommand(new YourCommand());

If I helped you, thank me. If I didn't, let me know.

Posted

Thank you very much both of you!

 

One last question and I am aware this is probably covered in a few areas somewhere, Once I have my extra command for the server I can just compile it and then drop "only" that package onto the server? So I dont need to upload a full new server.jar correct? (I dont want an answer explaining how to, I can look that up, just if that is the way its done, So similar to bukkit where you just drop your extra files onto the server?)

 

Thanks again guys!

Posted

Yes! you basically can. Do some digging on the wiki and find wuppy's tutorials and then the one about releasing a mod. All that is needed is a recompile,reobfuscate and then zip your package for release to be dropped into the mods folder. As I said the tutorial will tell you what you need.

If I helped you, thank me. If I didn't, let me know.

Posted

Thanks Jammas, Making progress, Have registered the events and I can see them doing exactly what I want on the server, but now my client crashes due to this line:

 

ServerCommandManager serverCommandManager = ((ServerCommandManager)commandManager);

 

How do I specify that I ONLY want these files loaded on the server? The client does not needs these files as it is only command server side.

 

Thanks again mate.

 

Posted

No worries.

 

Are you using the @NetworkMod annotation?

@NetworkMod(clientSideRequired = false, serverSideRequired = false)

It should come just after the @Mod.

 

Is that what you were asking? I'm not too sure.

 

But if you could also post what error you're getting upon the crash that would be sweet.

 

 

If I helped you, thank me. If I didn't, let me know.

Posted

Yep have that in there, I could actually launch the client and use the ingame server commands and all off a sudden it started crashing.

 

Full Error is:

 

 

2012-12-11 21:50:11 [sEVERE] [ForgeModLoader] Fatal errors were detected during the transition from INITIALIZATION to POSTINITIALIZATION. Loading cannot continue

2012-12-11 21:50:11 [sEVERE] [ForgeModLoader]

mcp [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized

FML [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized

Forge [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized

worldDropsCheck [World Drops Checker] (bin) Unloaded->Constructed->Pre-initialized->Errored

worldDropsRemove [World Drops Checkesr] (bin) Unloaded->Constructed->Pre-initialized->Errored

2012-12-11 21:50:11 [sEVERE] [ForgeModLoader] The following problems were captured during this phase

2012-12-11 21:50:11 [sEVERE] [ForgeModLoader] Caught exception from worldDropsCheck

java.lang.NullPointerException

at maxedgaming.worldDropsCheck.worldDropsCheck.init(worldDropsCheck.java:42)

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 cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:440)

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 com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

at com.google.common.eventbus.EventBus.post(EventBus.java:268)

at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:140)

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 com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

at com.google.common.eventbus.EventBus.post(EventBus.java:268)

at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:83)

at cpw.mods.fml.common.Loader.initializeMods(Loader.java:651)

at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:197)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:469)

at net.minecraft.client.Minecraft.run(Minecraft.java:756)

at java.lang.Thread.run(Unknown Source)

 

 

And the lines specific to that are:

 

 

@Init

public void init(FMLInitializationEvent event) {

MinecraftServer server = ModLoader.getMinecraftServerInstance();

ICommandManager commandManager = server.getCommandManager();

ServerCommandManager serverCommandManager = ((ServerCommandManager)commandManager);

serverCommandManager.registerCommand(new worldDropsCheck());

}

 

 

Where ICommandManager commandManager = server.getCommandManager();  is line 42.

 

Edit: Just to make it clearer, I only want to have these files on the server, I'm sure the client doesn't need any of these as I am just working with server instance and processing commands which shouldn't be files required on a client level correct?

Posted

Yes, if your NetworkMod annotation shows that the client does not need the mod files to join a server you are fine.

 

Now, preInit, init, and positInit all happen before the server is actually started. So, when you set up all you commands and register them with the managers no instance of the server exists. The null pointer exception means that commandManager is trying to access a null object that does not exist. This is because the server instance had not been started when you set up all your commands.

 

To fix this, you need to put all your command initialisation inside another method with the annotation @ServerStarting or @ServerStarted.

 

Let me know if you understand what I mean?

If I helped you, thank me. If I didn't, let me know.

Posted

Oh I realize I might have been a bit unclear, 'FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dimension).loadedEntityList.size();' will return all entities, including mobs, If you only want item drops, you can iterate and count the EntityItems:

int count = 0;
List list = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dimension).loadedEntityList;
for(Entity entity: (List<Entity>)list){
if(entity != null && entity instanceof EntityItem){
count++;
}
}

count would then have the item drop count. I just typed that off the top of my head, so it may have mistakes.

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

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

Announcements



×
×
  • Create New...

Important Information

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