Jump to content

Recommended Posts

Posted

So recently my friend got me into modding, and I've been trying to implement a basic command that returns the message "Hello" in chat when you do /coal. This is simply as a test so I can gain an understanding of how everything works.

 

This is my main class:

public class TutorialMain
{
    // The instance of your mod that Forge uses, in my case tutorial.
    @Instance("testmod")
    public static TutorialMain instance;
    
    @EventHandler
    public void serverLoad(FMLServerStartingEvent event)
    {
        // register server commands

    event.registerServerCommand(new SampleCommand());
    }

    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        // Stub Method
    }

    @EventHandler
    public void init(FMLInitializationEvent event)
    {

    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
        // Stub Method
    }
    

 

It is named TutorialMain because I was following the advice of a tutorial.

 

Here is the Sample Command class:

 

package com.testmod;

import java.util.ArrayList;
import java.util.List;
import eu.copybara.barra.util.*;

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;

public class SampleCommand implements ICommand {

@Override
public int compareTo(Object o) {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public List addTabCompletionOptions(ICommandSender arg0, String[] arg1, BlockPos arg2) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public boolean canCommandSenderUse(ICommandSender arg0) {
	// TODO Auto-generated method stub
	return true;
}

@Override
public void execute(ICommandSender arg0, String[] arg1) throws CommandException {
	// TODO Auto-generated method stub
	new Messages("Hello").send();

}

@Override
public List getAliases() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public String getCommandUsage(ICommandSender arg0) {
	// TODO Auto-generated method stub
	return "coal";
}

@Override
public String getName() {
	// TODO Auto-generated method stub
	return "coal";
}

@Override
public boolean isUsernameIndex(String[] arg0, int arg1) {
	// TODO Auto-generated method stub
	return false;
}}

 

Note: The Copybara.util is a package my friend sent me for sending chat messages, which I have tested and it worked before.

 

However when I run the mod and try to do /coal it informs me that there is no command like that.

 

 

I'm probably being really stupid and missing something but you must understand I have been following tutorials several years old.

 

Any help would be appreciated, thanks in advance!

 

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted
  On 8/11/2016 at 5:19 PM, diesieben07 said:

- For a start, do not implement ICommand. Extend CommandBase instead and override only the methods you need.

- Show the Messages class please.

- Why are you still on 1.8? Update.

 

1. I'm not entirely sure how the whole override thing works, could I have more detail? I'm assuming it is as simple as this:

package com.testmod;

import java.util.ArrayList;
import java.util.List;
import eu.copybara.barra.util.*;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;

public class SampleCommand extends CommandBase {

@Override
public int compareTo(Object o) {
	// TODO Auto-generated method stub
	return 0;
}


public List addTabCompletionOptions(ICommandSender arg0, String[] arg1, BlockPos arg2) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public boolean canCommandSenderUse(ICommandSender arg0) {
	// TODO Auto-generated method stub
	return true;
}

@Override
public void execute(ICommandSender arg0, String[] arg1) throws CommandException {
	// TODO Auto-generated method stub
	new Messages("Hello").send();

}


public List getAliases() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public String getCommandUsage(ICommandSender arg0) {
	// TODO Auto-generated method stub
	return "coal";
}

@Override
public String getName() {
	// TODO Auto-generated method stub
	return "coal";
}


public boolean isUsernameIndex(String[] arg0, int arg1) {
	// TODO Auto-generated method stub
	return false;
}}

 

2. Messages class:

 

package eu.copybara.barra.util;

import net.minecraft.event.ClickEvent;

import net.minecraft.event.HoverEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.fml.client.FMLClientHandler;

import java.util.ArrayList;

public class Messages {
private static IChatComponent CHAT_PREFIX;
public static String SEPARATION_MESSAGE = "\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC\u25AC";
private IChatComponent chatComponent;
private ArrayList<Messages> appendedMessages;

public Messages(String text) {
  this.chatComponent = new ChatComponentText(text);
}

public Messages(String text, EnumChatFormatting color) {
  this(text);
  this.addFormatting(color);
}

public Messages addFormatting(EnumChatFormatting formatting) {
  ChatStyle style = this.chatComponent.getChatStyle();
  switch (formatting) {
  case ITALIC:
   style.setItalic(true);
   break;
  case BOLD:
   style.setBold(true);
   break;
  case UNDERLINE:
   style.setUnderlined(true);
   break;
  case OBFUSCATED:
   style.setObfuscated(true);
   break;
  case STRIKETHROUGH:
   style.setStrikethrough(true);
   break;
  default:
   style.setColor(formatting);
   break;
  }
  this.chatComponent.setChatStyle(style);

  return this;
}

public Messages appendMessage(Messages message) {
  if (this.appendedMessages == null) {
   this.appendedMessages = new ArrayList<Messages>();
  }
  this.appendedMessages.add(message);
  if (message.appendedMessages != null) {
   this.appendedMessages.addAll(message.appendedMessages);
  }

  return this;
}

public Messages makeClickable(ClickEvent.Action action, String execute, Messages description) {
  ChatStyle style = this.chatComponent.getChatStyle();

  style.setChatClickEvent(new ClickEvent(action, execute));
  style.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, description.assembleMessage(false)));

  this.chatComponent.setChatStyle(style);

  return this;
}

public Messages makeLink(String url) {
  Messages description = new Messages("Click to visit ", EnumChatFormatting.GRAY);
  description
    .appendMessage(new Messages(url, EnumChatFormatting.AQUA).addFormatting(EnumChatFormatting.UNDERLINE));
  this.makeClickable(ClickEvent.Action.OPEN_URL, url, description);

  return this;
}

public Messages makeHover(Messages text) {
  ChatStyle style = this.chatComponent.getChatStyle();

  style.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, text.assembleMessage(false)));

  this.chatComponent.setChatStyle(style);

  return this;
}

public void send() {
  this.send(false);
}

public void send(boolean prefix) {
  try {
   FMLClientHandler.instance().getClientPlayerEntity().addChatMessage(this.assembleMessage(prefix));
  } catch (Exception e) {
   e.printStackTrace();
  }
}

protected IChatComponent assembleMessage(boolean prefix) {
  IChatComponent result;
  if (prefix) {
   result = CHAT_PREFIX.createCopy();
  } else if (this.appendedMessages == null) {
   return this.chatComponent;
  } else {
   result = new ChatComponentText("");
  }

  result.appendSibling(this.chatComponent);
  if (this.appendedMessages != null) {
   for (Messages m : this.appendedMessages) {
    result.appendSibling(m.chatComponent);
   }
  }

  return result;
}

public static void printSeparationMessage(EnumChatFormatting color) {
  new Messages(SEPARATION_MESSAGE, color).addFormatting(EnumChatFormatting.BOLD).send(false);
}
}

 

3. I'm more familiar with 1.8 and my goal is to create a special mod which is based around Hypixel, which supports 1.8. 1.9 and 1.10 is new territory for me.

 

Posted
  On 8/11/2016 at 5:41 PM, gummby8 said:

@Override

 

take a monster for example it extends EntityMob

 

I really hope you know what "extends" means

 

anyway. In EntityMob, or rather down the line at Entity, there is a method called onUpdate()

 

Lets say we want to still use onUpdate() but make it do something else

 

you do

 

@Override
public void onUpdate(){

//do stuff

}

 

in this way it overrides to parent method and substitutes whatever you want.

 

Now if you want the parent method to still run and your own stuff to run as well you add the super in

 

@Override
public void onUpdate(){
super.onUpdate();
//do stuff

}

 

I probably butchered that explanation, and may get scolded for not telling you to "Go learn java". But I am bored at work.

 

That actually made sense, thank you!

 

  Quote

The

send

method of the Messages class is absolutely broken. It will crash on servers and will not work reliably in single player.

 

Is there a better one you recommend?

Posted
  On 8/11/2016 at 5:53 PM, diesieben07 said:

ICommandSender::addChatMessage

(every entity is an

ICommandSender

).

So this is my refined code:

 

package com.testmod;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;

public class SampleCommand extends CommandBase {

@Override
public int compareTo(Object o) {
	// TODO Auto-generated method stub
	return 0;
}


public List addTabCompletionOptions(ICommandSender icommandsender, String[] arg1, BlockPos arg2) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public boolean canCommandSenderUse(ICommandSender icommandsender) {
	// TODO Auto-generated method stub
	return true;
}

@Override
public void execute(ICommandSender icommandsender, String[] arg1) throws CommandException {
	// TODO Auto-generated method stub
	icommandsender.addChatMessage(new ChatComponentText("Hello"));

}


public List getAliases() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public String getCommandUsage(ICommandSender icommandsender) {
	// TODO Auto-generated method stub
	return "coal";
}

@Override
public String getName() {
	// TODO Auto-generated method stub
	return "coal";
}

@Override
public boolean isUsernameIndex(String[] arg0, int arg1) {
	// TODO Auto-generated method stub
	return false;
}}
}}

 

Yet still nothing happens when I do /coal.

 

I apologise if I'm missing something obvious and am sounding like an idiot.

 

PS: I'm also crashing when genning a new world and attempting to join it. Minecraft just freezes and I have to close it.

 

 

Posted
  On 8/11/2016 at 7:35 PM, diesieben07 said:

You are still overriding all those methods. Why?

 

How exactly are you running the mod?

You told me to override all the methods I need, so I thought I needed to remove the "@Override" for all the methods that returned null. And I'm running it through eclipse with the run function, logged into my Minecraft account.

 

Edit: Just removed the overrides, still nothing.

Posted
  On 8/11/2016 at 7:47 PM, diesieben07 said:

Post updated code.

Also the @Override annotation is not what overrides a method. Overriding a method means creating a method with the same name and parameter types as a method in a superclass. @Override is just marker that produces an error if you are not overriding.

 

  Quote
How exactly are you running the mod?

package com.testmod;

import java.util.ArrayList;
import java.util.List;
import eu.copybara.barra.util.*;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;

public class SampleCommand extends CommandBase {


public int compareTo(Object o) {
	// TODO Auto-generated method stub
	return 0;
}


public List addTabCompletionOptions(ICommandSender icommandsender, String[] arg1, BlockPos arg2) {
	// TODO Auto-generated method stub
	return null;
}


public boolean canCommandSenderUse(ICommandSender icommandsender) {
	// TODO Auto-generated method stub
	return true;
}


public void execute(ICommandSender icommandsender, String[] arg1) throws CommandException {
	// TODO Auto-generated method stub
	icommandsender.addChatMessage(new ChatComponentText("Hello"));

}


public List getAliases() {
	// TODO Auto-generated method stub
	return null;
}


public String getCommandUsage(ICommandSender icommandsender) {
	// TODO Auto-generated method stub
	return "coal";
}


public String getName() {
	// TODO Auto-generated method stub
	return "coal";
}


public boolean isUsernameIndex(String[] arg0, int arg1) {
	// TODO Auto-generated method stub
	return false;
}}

 

Main:

package com.testmod;

import com.testmod.SampleCommand;

import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;

@Mod(modid="testmod", name="Test Mod", version="1.0")

public class TutorialMain
{
    // The instance of your mod that Forge uses, in my case tutorial.
    @Instance("testmod")
    public static TutorialMain instance;
    
    @EventHandler
    public void serverLoad(FMLServerStartingEvent event)
    {
        // register server commands

    event.registerServerCommand(new SampleCommand());
    }

    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        // Stub Method
    }

    @EventHandler
    public void init(FMLInitializationEvent event)
    {

    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
        // Stub Method
    }
    

   

}[code]


As I said, I click the "Run" button on eclipse, it opens Minecraft, I go onto a server (have to because single player crashes it for some reason) and do /coal.

 

Note: When it crashes on singleplayer it returns this on the console:

The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED. Errors may have been discarded.

The state engine was in incorrect state ERRORED and forced into state AVAILABLE. Errors may have been discarded.

Posted
  On 8/11/2016 at 8:04 PM, diesieben07 said:

Again:

  Quote

You are still overriding all those methods. Why?

 

  Quote
As I said, I click the "Run" button on eclipse, it opens Minecraft, I go onto a server
What kind of server? Does it have your mod installed? If so: How?

 

  Quote
have to because single player crashes it for some reason
Post the full crash.

 

1. I really don't understand what I'm overriding, how I'm doing it and what effect it is having, this is one of my first times modding.

 

2. It's Hypixel, so of course it doesn't have my mod installed.

 

3. Crash:

Caught exception from testmod

java.lang.NullPointerException

at net.minecraft.command.CommandHandler.registerCommand(CommandHandler.java:138) ~[forgeBin-1.8-11.14.1.1334.jar:?]

at net.minecraftforge.fml.common.event.FMLServerStartingEvent.registerServerCommand(FMLServerStartingEvent.java:44) ~[forgeBin-1.8-11.14.1.1334.jar:?]

at com.testmod.TutorialMain.serverLoad(TutorialMain.java:27) ~[bin/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:518) ~[forgeBin-1.8-11.14.1.1334.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[forgeBin-1.8-11.14.1.1334.jar:?]

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[forgeBin-1.8-11.14.1.1334.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]

at net.minecraftforge.fml.common.Loader.serverStarting(Loader.java:738) [Loader.class:?]

at net.minecraftforge.fml.common.FMLCommonHandler.handleServerStarting(FMLCommonHandler.java:319) [FMLCommonHandler.class:?]

at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:128) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:438) [MinecraftServer.class:?]

at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]

[21:00:10] [server thread/ERROR]: A fatal exception occurred during the server starting event

java.lang.NullPointerException

at net.minecraft.command.CommandHandler.registerCommand(CommandHandler.java:138) ~[forgeBin-1.8-11.14.1.1334.jar:?]

at net.minecraftforge.fml.common.event.FMLServerStartingEvent.registerServerCommand(FMLServerStartingEvent.java:44) ~[forgeBin-1.8-11.14.1.1334.jar:?]

at com.testmod.TutorialMain.serverLoad(TutorialMain.java:27) ~[bin/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:518) ~[forgeBin-1.8-11.14.1.1334.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[LoadController.class:?]

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[LoadController.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_101]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_101]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_101]

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118) ~[LoadController.class:?]

at net.minecraftforge.fml.common.Loader.serverStarting(Loader.java:738) [Loader.class:?]

at net.minecraftforge.fml.common.FMLCommonHandler.handleServerStarting(FMLCommonHandler.java:319) [FMLCommonHandler.class:?]

at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:128) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:438) [MinecraftServer.class:?]

at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]

[21:00:10] [server thread/INFO]: Applying holder lookups

Posted
  On 8/11/2016 at 8:21 PM, diesieben07 said:

You need to learn Java then. Before modding.

Like I said, overriding a method means having a method with the same name and signature (i.e. parameter types) as a superclass. As an example the method

addTabCompletionOptions

from your command class overrides the

addTabCompletionOptions

method in CommandBase, because it has the same name and signature. Like I also already said,

@Override

has nothing to do with whether you override or not. @Override simply produces an error if you are not overriding.

 

 

  Quote

It's Hypixel, so of course it doesn't have my mod installed.

How do you expect a server-side command that you added to work on a server that is not yours?

 

  Quote

3. Crash:

[snip]

This crash happens because you are still overriding all those methods to perform nonsense instead of their actual intended function.

 

 

1. So I need to rename these things to something else? Anything of my choosing? And how am I supposed to change the parameters? Won't that screw stuff up?

 

 

2. I'm attempting to make a client side mod, eventually for convenience, for example a /afk command which will /reply to anybody who messages you after you have done /afk.

 

 

 

 

Posted
  On 8/12/2016 at 10:19 AM, Animefan8888 said:

You are trying  to create a mod that needs to have access to the server....

That would have been nice to know before hand. How does one create a client side mod then? Because all of the tutorials I have seen followed this exact procedure.

Posted
  On 8/12/2016 at 10:22 AM, Animefan8888 said:

What are you trying to do with /AFK?

The syntax would be:

/afk <reason>

 

And whenever somebody messaged you (could detect this by the pink "From" in chat) it would send "/r I am currently afk" + reason to the chat.

 

This was a simple test to see if I could have it print something to the chat upon a command.

Posted

Sending chat messages is handled server side on servers, because it is the only way for other players to the the message though you could probably have your command run the other command to possibly fix that.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 8/12/2016 at 10:41 AM, Animefan8888 said:

Sending chat messages is handled server side on servers, because it is the only way for other players to the the message though you could probably have your command run the other command to possibly fix that.

That's what I mean, I want it to send THROUGH MY PLAYER "/r" which is the /reply command.

Posted

So if I understand correctly what you want to do is...

1. Run /AFK command

2. If the player that ran the command is AFK and receives a whisper/msg then send a reply back saying This player is AFK

Am I right?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 8/12/2016 at 11:26 AM, Animefan8888 said:

So if I understand correctly what you want to do is...

1. Run /AFK command

2. If the player that ran the command is AFK and receives a whisper/msg then send a reply back saying This player is AFK

Am I right?

Precisely.

Posted
  On 8/12/2016 at 12:02 PM, Animefan8888 said:

I don't think you can detect if the player has received a chat message but if you could it would be down with an Event provided by forge.

This feature exists in other mods and works, I'm fairly sure that all you do is detect a "From" string in the chat, messages appear like this:

"From Player117: Want to play a game?" and the "From" part is pink, so you could detect it I think.

Posted
  On 8/12/2016 at 12:12 PM, diesieben07 said:

  Quote
So I need to rename these things to something else?
No, you should remove those methods. Why are they there? Don't just have stuff in your code that you do not understand.

 

  Quote
I'm attempting to make a client side mod, eventually for convenience, for example a /afk command which will /reply to anybody who messages you after you have done /afk.

First of all, you will need a client-side command, not a server command like you are registering currently. Client commands are registered using
ClientCommandHandler

.

To detect the receiving string you need to use

ClientChatReceivedEvent

.

 

Alright, so this is my new code:

 

Main:

package com.testmod;

import com.testmod.SampleCommand;

import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;

@Mod(modid="testmod", name="Test Mod", version="1.0")

public class TutorialMain
{
    // The instance of your mod that Forge uses, in my case tutorial.
    @Instance("testmod")
    public static TutorialMain instance;
    
    @EventHandler
    public void clientLoad(ClientCommandHandler clientcommandhandler)
    {
        // register server commands

    clientcommandhandler.instance.registerCommand(new SampleCommand());
    }

    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        // Stub Method
    }

    @EventHandler
    public void init(FMLInitializationEvent event)
    {

    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
        // Stub Method
    }
    

   

}

 

SampleCommand:

package com.testmod;

import java.util.ArrayList;
import java.util.List;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;

public class SampleCommand extends CommandBase {

@Override
public int compareTo(Object o) {
	// TODO Auto-generated method stub
	return 0;
}
@Override
public boolean canCommandSenderUse(ICommandSender icommandsender) {
	// TODO Auto-generated method stub
	return true;
}
@Override
public void execute(ICommandSender icommandsender, String[] arg1) throws CommandException {
	// TODO Auto-generated method stub
	icommandsender.addChatMessage(new ChatComponentText("Hello"));

}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
	// TODO Auto-generated method stub
	return "coal";
}

@Override
public String getName() {
	// TODO Auto-generated method stub
	return "coal";
}
@Override
public boolean isUsernameIndex(String[] arg0, int arg1) {
	// TODO Auto-generated method stub
	return false;
}}

 

 

I removed all the methods that returned null, and used a syntax I found online for ClientCommandHandler.

 

 

 

Edit: I added the register command to the init and it worked!

Posted

One more issue, bit more advanced now:

 

 

Main:

package com.testmod;

import com.testmod.SampleCommand;

import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;

@Mod(modid="testmod", name="Test Mod", version="1.0")

public class TutorialMain
{

    // The instance of your mod that Forge uses, in my case tutorial.
    @Instance("testmod")
    public static TutorialMain instance;
    

    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        // Stub Method
    	MinecraftForge.EVENT_BUS.register(new ChatListener());
    	
    }

    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    	ClientCommandHandler.instance.registerCommand(new SampleCommand());
    	
    	

    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
        // Stub Method
    }
    

   

}

 

ChatListener:

package com.testmod;

import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class ChatListener {
public static boolean isAFK = false;

@SubscribeEvent
public void onChat(ClientChatReceivedEvent event) {
	String message = event.message.getUnformattedText();
	if (message.contains("From") && isAFK) {
		Minecraft.getMinecraft().thePlayer.sendChatMessage("/r I am currently AFK. Reason: ");
	}




	}
}



 

SampleCommand:

package com.testmod;

import java.util.ArrayList;
import java.util.List;
import eu.copybara.barra.util.*;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;

public class SampleCommand extends CommandBase {


@Override
public int compareTo(Object o) {
	// TODO Auto-generated method stub
	return 0;
}
@Override
public boolean canCommandSenderUse(ICommandSender icommandsender) {
	// TODO Auto-generated method stub
	return true;
}
@Override
public void execute(ICommandSender icommandsender, String[] arg1) throws CommandException {
	// TODO Auto-generated method stub
	icommandsender.addChatMessage(new ChatComponentText("Hello"));
	if (ChatListener.isAFK = false) {
	ChatListener.isAFK = true;
	icommandsender.addChatMessage(new ChatComponentText("You are now AFK!"));
	}
	else if (ChatListener.isAFK = true) {
		ChatListener.isAFK = false;
		icommandsender.addChatMessage(new ChatComponentText("You are no longer AFK!"));
		}

}
@Override
public String getCommandUsage(ICommandSender icommandsender) {
	// TODO Auto-generated method stub
	return "afk <reason>";
}

@Override
public String getName() {
	// TODO Auto-generated method stub
	return "afk";
}
@Override
public boolean isUsernameIndex(String[] arg0, int arg1) {
	// TODO Auto-generated method stub
	return false;
}}

 

 

When I do /afk it returns "You are no longer AFK!" constantly, never does the /r and also never says the "You are now AFK!".

Posted
  On 8/12/2016 at 5:05 PM, CoalOres said:

  Quote

if (false) return;

There are two possible places for this, which are you referring to?

Here

                if (ChatListener.isAFK = false) {
	    ChatListener.isAFK = true;
	    icommandsender.addChatMessage(new ChatComponentText("You are now AFK!"));
	    return;
                }

If this doesn't work it is not being called.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Guest
This topic is now closed to further replies.

Announcements




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Looks like an issue with biomeswevegone
    • In the server.properties, set max-tick-time to -1   if there are further issues, make a test without distanthorizons
    • Verified user can get a $300 off TℰℳU Coupon code using the code ((“{{ '[''com31844'']}}”)). This TℰℳU $100Off code is specifically for new and existing customers both and can be redeemed to receive a $100discount on your purchase. Our exclusive TℰℳU Coupon code offers a flat $100off your purchase, plus an additional 100% discount on top of that. You can slash prices by up to $100as a new TℰℳU customer using code ((“{{ '[''com31844'']}}”)). Existing users can enjoy $100off their next haul with this code. But that’s not all! With our TℰℳU Coupon codes for 2025, you can get up to 90% discount on select items and clearance sales. Whether you’re a new customer or an existing shopper, our TℰℳU codes provide extra discounts tailored just for you. Save up to 100% with these current TℰℳU Coupons ["^"{{ '[''com31844'']}} "^"] for April 2025. The latest TℰℳU coupon codes at here. New users at TℰℳU receive a $100discount on orders over $100Use the code ((“{{ '[''com31844'']}}”)) during checkout to get TℰℳU Coupon $100Off For New Users. You can save $100Off your first order with the coupon code available for a limited time only. TℰℳU 90% Off promo code ((“{{ '[''com31844'']}}”)) will save you $100on your order. To get a discount, click on the item to purchase and enter the coe. Yes, offers $100Off coupon code “{{ '[''com31844'']}}” for first time users. You can get a $100bonus plus $100Off any purchase at TℰℳU with the $100Coupon Bundle at TℰℳU if you sign up with the referral code ((“{{ '[''com31844'']}}”)) and make a first purchase of $100or more. Free TℰℳU codes $100off — ((“{{ '[''com31844'']}}”)) Get a $100discount on your TℰℳU order with the promo code "{{ '[''com31844'']}}". You can get a discount by clicking on the item to purchase and entering this TℰℳU Coupon code $100off ((“{{ '[''com31844'']}}”)). ŢℰNew User Coupon ((“{{ '[''com31844'']}})): Up To $100OFF For First-Time Users Our TℰℳU first-time user coupon codes are designed just for new customers, offering the biggest discounts and the best deals currently available on TℰℳU To maximize your savings, download the TℰℳU app and apply our TℰℳU new user coupon during checkout. TℰℳU Coupon Codes For Existing Users ((“{{ '[''com31844'']}}”)): $100Price Slash Have you been shopping on TℰℳU or a while? Our TℰℳU Coupon for existing customers is here to reward you for your continued support, offering incredible discounts on your favorite products. TℰℳU Coupon For $100Off ((“{{ '[''com31844'']}}”)): Get A Flat $100Discount On Order Value Get ready to save big with our incredible TℰℳU Coupon for $100off! Our amazing ŢℰM$100off coupon code will give you a flat $100discount on your order value, making your shopping experience even more rewarding. TℰℳU Coupon Code For $100Off ((“{{ '[''com31844'']}}”)): For Both New And Existing Customers Our incredible TℰℳU Coupon code for $100off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our $100off code for TℰℳU will give you an additional discount! TℰℳU Coupon Bundle ((“{{ '[''com31844'']}}”)): Flat $100Off + Up To $100Discount Get ready for an unbelievable deal with our TℰℳU Coupon bundle for 2025! Our TℰℳU Coupon bundles will give you a flat $100discount and an additional $100off on top of it. Free TℰℳU Coupons ((“{{ '[''com31844'']}}”)): Unlock Unlimited Savings! Get ready to unlock a world of savings with our free TℰℳU Coupons! We’ve got you covered with a wide range of TℰℳU Coupon code options that will help you maximize your shopping experience. 100% Off TℰℳU Coupons, Promo Codes + 25% Cash Back ((“{{ '[''com31844'']}}”)) Redeem TℰℳU Coupon Code ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FOR EXISTING CUSTOMERS ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FIRST ORDER ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF REDDIT ((“{{ '[''com31844'']}}”)) TℰℳU Coupon $100OFF FOR EXISTING CUSTOMERS REDDIT ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF CODE ((“{{ '[''com31844'']}}”)) TℰℳU 70 OFF COUPON 2025 ((“{{ '[''com31844'']}}”)) DOMINOS 70 RS OFF COUPON CODE ((“{{ '[''com31844'']}}”)) WHAT IS A COUPON RATE ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FOR EXISTING CUSTOMERS ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FIRST ORDER ((“{{ '[''com31844'']}}”)) TℰℳU $100OFF FREE SHIPPING ((“{{ '[''com31844'']}}”)) You can get an exclusive $100off discount on your TℰℳU purchase with the code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}].This code is specially designed for new customers and offers a significant price cut on your shopping. Make your first purchase on TℰℳU more rewarding by using this code to get $100off instantly.   TℰℳU Coupon Code For $100Off [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]: Get A Flat $100Discount On Order Value Get ready to save big with our incredible TℰℳU coupon for $100off! Our coupon code will give you a flat $100discount on your order value, making your shopping experience even more rewarding.   Exclusive TℰℳU Discount Code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]: Flat $300 OFF for New and Existing Customers Using our TℰℳU promo code you can get A$ 200 off your order and 100% off using our TℰℳU promo code [{{ '[''com31844'']}}] Or [{{ '[''com31844'']}}]. As a new TℰℳU customer, you can save up to $100using this promo code. For returning users, our TℰℳU promo code offers a $100price slash on your next shopping spree. This is our way of saying thank you for shopping with us! Get ready to save big with our incredible TℰℳU Coupon code for $300 off! Our amazing TℰℳU $300 off coupon code will give you a flat $300 discount on your order value, making your shopping experience even more rewarding.   TℰℳU Coupon Code For 40% Off ["{com31844}"] For Both New And Existing Customers   Our incredible TℰℳU Coupon code for 40% off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our 40% off code for TℰℳU will give you an additional discount!   TℰℳU Coupon Bundle ["{com31844}"]: Flat $300 Off + Up To 90% Discount   Get ready for an unbelievable deal with our TℰℳU Coupon bundle for 2025! Our TℰℳU Coupon bundles will give you a flat $300 discount and an additional 40% off on top of it.   Free TℰℳU Coupons ["{com31844}"]: Unlock Unlimited Savings!   Get ready to unlock a world of savings with our free TℰℳU Coupons! We’ve got you covered with a wide range of TℰℳU Coupon code options that will help you maximize your shopping experience.   50% Off TℰℳU Coupons, Promo Codes + 25% Cash Back ["{com31844}"]   Redeem TℰℳU Coupon Code ["{com31844}"]   TℰℳU Coupon $300 OFF ["{com31844}"]   TℰℳU Coupon $300 OFF ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS ["{com31844}"]   TℰℳU Coupon $300 OFF FIRST ORDER ["{com31844}"]   TℰℳU Coupon $300 OFF FIRST ORDER ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS FREE SHIPPING USA ["{com31844}"]   TℰℳU Coupon $300 OFF HOW DOES IT WORK ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS CANADA ["{com31844}"]   TℰℳU Coupon $300 OFF 2025 ["{com31844}"]   TℰℳU Coupon $300 OFF FOR NEW CUSTOMERS ["{com31844}"]   TℰℳU Coupon $300 OFF CANADA ["{com31844}"]   TℰℳU Coupon $300 OFF FOR EXISTING CUSTOMERS FIRST ORDER ["{com31844}"]   TℰℳU 300 OFF COUPON BUNDLE ["{com31844}"]   This TℰℳU coupon $300 off is designed to provide substantial savings on your purchases, making shopping for your favorite items easier than ever. With our $300 off TℰℳU coupon, you'll be amazed at how much you can save on your next order. Here are the key benefits you can expect when using our coupon code {com31844} "OR" {com31844}: {com31844} "OR" {com31844}: Flat $300 off on your purchase {com31844} "OR" {com31844}: $300 coupon pack for multiple uses {com31844} "OR" {com31844}: $300 flat discount for new customers {com31844} "OR" {com31844}: Extra $300 promo code for existing customers {com31844} "OR" {com31844}: $300 coupon exclusively for USA/Canada users H2: TℰℳU Coupon Code $300 Off For New Users In 2024 New users can reap the highest benefits by using our coupon code on the TℰℳU app. This TℰℳU coupon $300 off is specifically designed to welcome new customers with incredible savings  
    • Now the serve runs for a bit, then crashes after 20 minutes of running, what's the issue here? apologies if I need to start a new post and didn't https://pastebin.com/uBpp5bCz  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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