Jump to content

CoalOres

Members
  • Posts

    86
  • Joined

  • Last visited

Everything posted by CoalOres

  1. 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.
  2. That actually made sense, thank you! Is there a better one you recommend?
  3. 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.
  4. 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!
×
×
  • Create New...

Important Information

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