Posted July 28, 20187 yr I want to create a new command for the client to use. I tested the code on a local world and it works(for now there are only some print lines). It seems that Minecraft uses a list and a loop to search through all commands and when found it calls its execute method. But when I join a server the game still searches for my command but instead of executing its method it looks like it's sent to the server and checked there. This of course results in an error("The server couldn't find the command"). Main class: Quote package com.user.testmod; import com.user.testmod.proxy.CommonProxy; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; 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.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @Mod(modid=Reference.MODID,name=Reference.MODNAME,version=Reference.VERSION,acceptableRemoteVersions = "*",acceptedMinecraftVersions=Reference.ACCEPTED_MINECRAFT_VERSIONS) public class Main{ @Instance public static Main instance; @SidedProxy(clientSide="com.user.testmod.proxy.ClientProxy",serverSide="com.user.testmod.proxy.CommonProxy") public static CommonProxy proxy; @EventHandler public static void preInit(FMLPreInitializationEvent event) { System.out.println("a"); } @EventHandler public static void Init(FMLInitializationEvent event) { System.out.println("b"); MinecraftForge.EVENT_BUS.register(new Event()); ClientCommandHandler.instance.registerCommand(new Command()); } @EventHandler public static void postInit(FMLPostInitializationEvent event) { System.out.println("c"); } } Command class package com.user.testmod; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.server.MinecraftServer; public class Command extends CommandBase{ @Override public String getName() { // TODO Auto-generated method stub System.out.println("comm aaa"); return "test"; } @Override public String getUsage(ICommandSender sender) { // TODO Auto-generated method stub System.out.println("comm bbb"); return null; } @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { // TODO Auto-generated method stub System.out.println("command executed"); } } There are other weird things happening that I believe are related: I implemented an onBreakBlock event -it works on a local world but does nothing in multiplayer. Event class package com.user.testmod; import net.minecraft.client.Minecraft; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.BreakEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class Event { @SubscribeEvent public void breakEvent(BlockEvent.BreakEvent event) { System.out.println("ccc"); Minecraft.getMinecraft().player.sendChatMessage("asdasd"); } @SubscribeEvent public void onBreakBlock(BreakEvent event) { event.setCanceled(true); } @SubscribeEvent public void onFlyFall(PlayerFlyableFallEvent event) { System.out.println("dddd"); //just testing different events to see which works in multiplayer-many don't } } How can I fix it? Edited July 28, 20187 yr by Antonii
July 28, 20187 yr Author 3 minutes ago, diesieben07 said: Your code should work, except that you are referring to client-only classes (ClientCommandHandler) from common code. You also might want to implement IClientCommand to make your command only execute when prefixed with a slash. As for your break block event, you did not post that code. I am new to mods. What should I use instead of ClientCommandHandler? And how do you know it's common code? Is it from this line "public static CommonProxy proxy;" ?
July 28, 20187 yr Author In the end: I can't possibly believe that my problem has no solution. I read that some events do not exist so I have to edit network packets but I can't believe that onBreak event is not called when I break a block, What is the solution? Are mods THAT hard to make? Always being forced to use packets? Edited July 28, 20187 yr by Antonii
July 28, 20187 yr Author Another thing: it looks like the code for fly event is called twice by main thread and Server thread. Why is that? Am I supposed to explicitly use a side? Why doesn't that happen with the break event?
July 28, 20187 yr And some events have a Phase, for when the event should run before or after vanilla code. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
July 28, 20187 yr Author diesieben07 I have provided the code for the events I reffered. By "fly" I meant onFlyFall. The breakEvent event is not called when in multiplayer. When I am on a local world It works but not in multiplayer. If you don't mind ,another thing :"RenderPlayerEvent.Specials.Post" is deprecated -what is the alternative? There's absolutely no reference to it on the internet-only for older versions. I couldn't see any given alternatives. Edited July 28, 20187 yr by Antonii
July 28, 20187 yr Author I hate this. It takes forever for Minecraft to build and to test the mod. Now it stoppped working. On the breakEvent I wanted this code to be executed Minecraft.getMinecraft().player.sendChatMessage("asdasd"); It worked for a few builds. Now...it STOPED! I have built Minecraft like a hundred times. No luck. What is going on? Event File package com.user.testmod; import net.minecraft.client.Minecraft; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.BreakEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; public class Event { @SubscribeEvent public void onPlayerLoggedInEvent(PlayerLoggedInEvent event) { System.out.println("logged"); } @SubscribeEvent public void breakEvent(BlockEvent.BreakEvent event) { System.out.println("breakEvent"); Minecraft.getMinecraft().player.sendChatMessage("asdasd"); } @SubscribeEvent public void onBreakBlock(BreakEvent event) { System.out.println("Break block"); event.setCanceled(true); } } Main package com.user.testmod; import com.user.testmod.proxy.ClientProxy; import com.user.testmod.proxy.CommonProxy; import ibxm.Player; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; 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.SidedProxy; 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.gameevent.PlayerEvent; @Mod(modid=Reference.MODID,name=Reference.MODNAME,version=Reference.VERSION,acceptableRemoteVersions = "*",acceptedMinecraftVersions=Reference.ACCEPTED_MINECRAFT_VERSIONS) public class Main{ @Instance public static Main instance; @SidedProxy(clientSide="com.user.testmod.proxy.ClientProxy",serverSide="com.user.testmod.proxy.CommonProxy") public static CommonProxy proxy; @EventHandler public static void preInit(FMLPreInitializationEvent event) { System.out.println("a"); } @EventHandler public static void Init(FMLInitializationEvent event) { System.out.println("b"); MinecraftForge.EVENT_BUS.register(new Event()); ClientCommandHandler.instance.registerCommand(new Command()); ClientCommandHandler.instance.registerCommand(new Command2()); } @EventHandler public static void postInit(FMLPostInitializationEvent event) { System.out.println("c"); } } I am starting to hate Java and Minecraft. It's like Python with dependencies on Windows.
July 28, 20187 yr Author diesieben07 No the mod is client-oriented. I join a server from Multiplayer menu in Minecraft. It should stay active during the play right?
July 28, 20187 yr Author I realized something. I can't tell the difference between the client events and server ones. I <know> the difference but you have enligthen me. So the event was for server side. How can I know that? Is there a list with all the events available? About the custom command. The execute method seems to be for the server side(it has a MinecraftServer argument so it's quite obvious) so ,of course in a multiplayer game it will not be executed because the server is not local. What should I do to prevent the command to be sent out? Is not a problem because I've seen that I can detect the command: weirdly the getName function is called exactly once only for the command so I can use this location to write code for the actual command. But it's upsetting me that the command is still sent out. Isn't there an event for capturing chat or commands that I can cancel? Edited July 28, 20187 yr by Antonii
July 28, 20187 yr Author " When registered to ClientCommandHandler the command should not be "sent out". Use the debugger to find out what is happening exactly. " -the execute function is never called on client side and the server generates an error so the command is sent out-over network. Two final questions(from what I have seen the doc is pretty thin so your experience is my salvation): Where should I put my code to be executed when I enter the custom command?and How on this earth can I loop through the player's inventory-there's NOTHING on this subject,only for server side-? Edited July 28, 20187 yr by Antonii
July 28, 20187 yr Author " Sorry, I am not following here. You say it is never called on the client. Are you sure it is registered to ClientCommandHandler? " Yes as the code shows. I thought that when I enter a command it is first sent to the server to be checked because otherwise I couldn't explain the fact that the server sends back a "You don't have permission"
July 28, 20187 yr Author Can I take player's inventory from this event? public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { // TODO Auto-generated method stub } should I make a public variable that I set in onWorldLoad and in which I store EntityPlayer? Or..how else could I get the player? Like this: Minecraft.getMinecraft().player ? Edited July 28, 20187 yr by Antonii
July 28, 20187 yr Author Really sometimes I don't understand what Minecraft#player means : Minecraft.player (doesn't exist) or what?
July 28, 20187 yr Author Like Minecraft a=new Minecraft(null); ? this is were Eclipse lead me Isn't Minecraft. getMinecraft () also correct? Edited July 28, 20187 yr by Antonii
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.