Jump to content

Recommended Posts

Posted (edited)

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 by Antonii
Posted
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;" ?

Posted (edited)

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 by Antonii
Posted

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?

 

 

Posted

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.

Posted (edited)

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 by Antonii
Posted

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.

Posted (edited)

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 by Antonii
Posted (edited)

" 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 by Antonii
Posted

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

Posted (edited)

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 by Antonii
Posted (edited)

Like Minecraft a=new Minecraft(null); ?  this is were Eclipse lead me

Isn't Minecraft. getMinecraft () also correct?

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am playing a modpack with the web displays mod and I tried it out and when I logged back into my world i decided to get rid of the display i placed to move it and it started playing the video from last session and crashed my game, when i tried to start the game again it said it could not start becasue it could not delete a debug file that has the link in it that is no longer being displayed but is trying to, here is the debug folder.   [0201/091808.660:WARNING:chrome_browser_cloud_management_controller.cc(88)] Could not create policy manager as CBCM is not enabled. [0201/091930.426:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factors'.", source:  (0) [0201/091932.869:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.290:INFO:CONSOLE(5047)] "LegacyDataMixin will be applied to all legacy elements. Set `_legacyUndefinedCheck: true` on element class to enable.", source:  [0201/091933.529:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.529:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.530:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.530:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.557:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factors'.", source:  (0) [0201/091934.376:WARNING:obfuscated_file_util.cc(1410)] Failed to get origin+type directory: { uri: filesystem:https://www.youtube.com/temporary/, storage key: { origin: https://www.youtube.com, top-level site: https://youtube.com, nonce: <null>, ancestor chain bit: Same-Site }, bucket id: 1 } error:-4 [0201/091935.216:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factors'.", source:  (0) [0201/091935.241:INFO:CONSOLE(7990)] "Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.", source: https://www.youtube.com/s/desktop/3df27587/jsbin/desktop_polymer.vflset/desktop_polymer.js (7990) [0201/091936.766:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091936.767:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091936.767:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091936.767:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091937.243:INFO:CONSOLE(5047)] "LegacyDataMixin will be applied to all legacy elements. Set `_legacyUndefinedCheck: true` on element class to enable.", source: https://www.youtube.com/s/desktop/3df27587/jsbin/desktop_polymer.vflset/desktop_polymer.js (5047) [0201/091938.283:INFO:CONSOLE(7990)] "Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.", source: https://www.youtube.com/s/desktop/3df27587/jsbin/desktop_polymer.vflset/desktop_polymer.js (7990) [0201/091939.496:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091953.165:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705676 [9,12] [0201/091953.165:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705676 [9,12] [0201/091953.166:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705676 [9,12] [0201/091953.166:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705676 [9,12] [0201/091959.119:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/091959.119:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/091959.119:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092014.122:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092014.122:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092014.122:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092019.126:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092019.126:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092019.126:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092024.512:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092024.512:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092024.512:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092029.812:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092029.812:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092029.812:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092036.154:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092036.165:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092036.165:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092041.464:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092041.464:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092041.464:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092051.842:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092051.843:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092051.843:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092055.373:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092055.373:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092055.373:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0)
    • If you are searching for mods, I would not search here, this is more of a support forum for using/creating mods with minecraft Forge. Try https://www.curseforge.com/minecraft if you are looking for mods/modpacks to use.
    • I was trying to find a mod that added something specific, and was unable to find it with what limited memory I had of seeing it. I don't know why there isn't an option to include words in overviews of mods. I could see it being in the sort tab near filters on the app in my opinion. It might help someone trying to find something specific, only based off something from the overview tab, but idk
    • Please read the FAQ and post logs as described there.   Also, do not just add a post onto someone else's thread with your issue, create a new one please.
  • Topics

×
×
  • Create New...

Important Information

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