Jump to content

Custom command visible only to client not server


Antonii

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

" 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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

    • Slot Bank BNI adalah pilihan tergacor untuk memulai bermain slot judi Online dimuka bumi saat ini. Jika anda mempunyai Bank BNI, Anda berkesempatan mendapatkan Akun Pro atau ID pro untuk bermain slot. Tunggu apa lagi? Segera daftarkan diri anda sekarang dan dapatkan kemewahan menang maxwin di Museumbola.
    • Halo para penggemar slot online! Apakah Anda mencari pengalaman bermain slot yang seru dan menguntungkan? Apakah Anda ingin menikmati slot gacor dari server Thailand sambil melakukan deposit melalui Mandiri dengan kesempatan meraih kemenangan besar? Anda telah sampai di tempat yang tepat! Kami di WINNING303 siap memberikan Anda pengalaman bermain yang mengasyikkan dan menguntungkan. Mengapa Memilih WINNING303? WINNING303 telah dikenal sebagai salah satu platform terbaik untuk bermain slot dengan berbagai keunggulan yang kami tawarkan kepada para pemain kami. Berikut adalah beberapa alasan mengapa Anda harus memilih WINNING303: Slot Gacor dari Server Thailand Kami menyajikan koleksi slot gacor terbaik dari server Thailand yang pastinya akan memberikan Anda pengalaman bermain yang menarik dan menguntungkan. Nikmati berbagai jenis permainan slot dengan tingkat kemenangan yang tinggi dan jackpot yang menarik. Deposit Mudah Melalui Mandiri Kami memahami pentingnya kemudahan dalam bertransaksi bagi para pemain kami. Oleh karena itu, kami menyediakan layanan deposit melalui bank Mandiri, salah satu bank terbesar di Indonesia. Proses depositnya cepat, mudah, dan aman, sehingga Anda dapat langsung memulai petualangan bermain tanpa hambatan. Peluang Maxwin Besar Di WINNING303, kami selalu memberikan peluang untuk meraih kemenangan besar. Dengan berbagai promosi dan bonus menarik yang kami sediakan, Anda memiliki kesempatan untuk memenangkan hadiah-hadiah yang fantastis dan meraih maxwin dalam bermain slot.  
    • SLOT Ratubet77 adalah bocoran slot gacor rekomendasi dari Ratubet77 yang bisa anda temukan di SLOT Ratubet77. Situs SLOT Ratubet77 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ratubet77 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ratubet77 merupakan SLOT Ratubet77 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ratubet77. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ratubet77 hari ini yang telah disediakan SLOT Ratubet77. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ratubet77 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ratubet77 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ratubet77 di link SLOT Ratubet77. DAFTAR SEKARANG DAFTAR SEKARANG DAFTAR SEKARANG
    • I am currently running the 1.20.1 Occultcraft modpack in Curseforge and am having numerous troubles making a mob farm with the apotheosis mod. When trying to modify the stats of the spawners specific stats such as the range, spawn count, and max entities reset to default after every spawn. When the spawners spawn boss mobs with certain attributes, that I'm not sure of, the building it is in explode even with mob griefing turned off. This has happened multiple times with varying sizes for the explosions. I was wonder if there is any way to disable these explosions from happening or disable boss abilities with something in the game. I also wanted to know a fix for the resetting stats on spawners and why this is happening.
    • SLOT Bank BSI adalah pilihan terbaik untuk Anda yang ingin merasakan sensasi bermain slot dengan layanan dari Bank BSI. Dengan keamanan terjamin, beragam pilihan permainan, kemudahan deposit via Bank BSI, dan berbagai bonus menarik, kami siap memberikan Anda pengalaman bermain yang tak terlupakan. Bergabunglah dengan kami sekarang dan mulailah petualangan seru Anda!    
  • Topics

×
×
  • Create New...

Important Information

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