Jump to content

1.8 Client Side Events


FallingAngel

Recommended Posts

Currently I am attempting to create a mod in 1.8 (has to be 1.8 so pls dont say "UPDATE!!!!!")  that will detect when your inventory is full and then run a command. Currently the mod works in single player, but not in multiplayer. As I understand it, the reason its not working in multiplayer is that the events I am trying to call are server based events and not client based events 

Here is my current code 
 

@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION, acceptedMinecraftVersions = Reference.ACCEPTED_VERSIONS)
public class AutoSell 
{
	
	public static String planet;

	@Instance
	public static AutoSell instance;
	
	@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
	public static CommonProxy proxy;
	
	@Mod.EventHandler
	public void onFMLInitialization(final FMLInitializationEvent event) 
	{
		FMLCommonHandler.instance().bus().register(new LivingEntityEventHandlers());
		ClientCommandHandler.instance.registerCommand((ICommand)new Commands());
		FMLCommonHandler.instance().bus().register((Object)this);
	}
	
	
	@Mod.EventHandler
	public void serverLoad(FMLServerStartingEvent event)
	{
	    // register server commands

	event.registerServerCommand(new Commands());

	 Runnable runnable = new Runnable() {
	      public void run() {
	    	  Minecraft.getMinecraft().thePlayer.sendChatMessage("/lag"); 
	    	  Minecraft.getMinecraft().thePlayer.sendChatMessage("/server " + planet + "planet");
	      }
	    };
	    
	    ScheduledExecutorService service = Executors
	                    .newSingleThreadScheduledExecutor();
	    service.scheduleAtFixedRate(runnable, 0, 1, TimeUnit.MINUTES);
	  }
	
	
	}	
public class LivingEntityEventHandlers 
{	
	int maxslots;
	@SubscribeEvent
	public void PlayerTickeEvent(TickEvent.PlayerTickEvent event) 
	{
		if (event.player instanceof EntityPlayerMP) 
		{

			EntityPlayerMP player = (EntityPlayerMP) event.player;
			InventoryPlayer inventory = player.inventory;		
			for (int i = 0; i < inventory.mainInventory.length; ++i)
	        {
				
				maxslots = i;
	            if (inventory.mainInventory[i] == null)
	            {
	            	
	            }
	            else
	            {
	            	if (maxslots == 35)
	            	{
    				Minecraft.getMinecraft().thePlayer.sendChatMessage("/sell all");
    				maxslots = 0;
    				break;
	            	}
	            }
	        }
	    }
	
				    
}
}

 

 

also the anti afk commands /lag and /server xplanet are not working I assume from the same issue. I'm new to forge coding, so forgive me for my stupidity

Edited by FallingAngel
Mistake
Link to comment
Share on other sites

5 hours ago, diesieben07 said:
  • No, it does not have to be 1.8. Update. No, I don't care about your server or whatever stupid ancient mod you are trying to use. If whatever it is has not updated by now (it's been over three years), it's time to abandon it.
  • You are registering your Commands class as both a client-side command and a server-side command. This can't be right.
  • You are accessing the game code (sendChatMessage) from a separate thread. This does not work. You can only interact with the game from the main thread.
  • When subscribing to any TickEvent, you must check TickEvent::phase.
  • In PlayerTickeEvent (please follow Java naming conventions...) you check if the player is a server-side player (EntityPlayerMP), but then you access a client-only class (Minecraft). This is known as reaching across logical sides and will crash on a dedicated server and cause subtle and hard to trace issues in single player.
  • Im not going to argue the point as many servers still use 1.8 over 1.12 but whatever
     
  • The commands class is working perfectly fine on multiplayer and single player servers
     
  • Thank you :) fixed
     
  • I'm am not very sure how to do this? From what I understand, the event triggers off 2x per tick, one at the start and once at the end. As a result this is rapid firing the message being sent, "/sell all" and getting me kicked for spam. How can i use the phase to make sure that at the instance the code only fires a single time?
     

Fixed and now the code is being sent properly :) 

updated code: 

Main

@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION, acceptedMinecraftVersions = Reference.ACCEPTED_VERSIONS)
public class AutoSell 
{
	
	public static String planet;
	
	@Instance
	public static AutoSell instance;
	
	@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
	public static CommonProxy proxy;
	
	@Mod.EventHandler
	public void onFMLInitialization(final FMLInitializationEvent event) 
	{
		MinecraftForge.EVENT_BUS.register(new LivingEntityEventHandlers());
		ClientCommandHandler.instance.registerCommand((ICommand)new Commands());
		FMLCommonHandler.instance().bus().register((Object)this);
		FMLCommonHandler.instance().bus().register(new AntiAfk());
	}
	
	
	public static void AfkForDays()
	{
		Minecraft.getMinecraft().thePlayer.sendChatMessage("/server " + planet + " planet");
		Minecraft.getMinecraft().thePlayer.sendChatMessage("/lag");	  
	}
	
	
	public static void sellShit() 
	{
		Minecraft.getMinecraft().thePlayer.sendChatMessage("/sell all");	
	}
}


Sell class:
 

public class LivingEntityEventHandlers 
{	
	
	int maxslots;
	@SubscribeEvent
	public void LivingUpdateEvent(LivingEvent event) 
	{
		if (event.entity instanceof EntityPlayerSP) 
		{
			EntityPlayerSP player = (EntityPlayerSP) event.entity;
			InventoryPlayer inventory = player.inventory;		
			for (int i = 0; i < inventory.mainInventory.length; ++i)
	        {
				
				maxslots = i;
	            if (inventory.mainInventory[i] == null)
	            {
	            	
	            }
	            else
	            {
	            	if (maxslots == 35)
	            	{
    				FallingAngel.AutoSell.AutoSell.sellShit();
    				maxslots = 0;
    				break;
	            	}
	            }
	        }
	    }
	}				    
}


AntiAFK (Not Working)

 

public class AntiAfk {
	int tick = 0;
	@SubscribeEvent
    public void onPlayerJoinedServer(FMLNetworkEvent.ClientConnectedToServerEvent event) {
		if(tick != 6000){
			tick++;
			return;
		}
		else 
		{
			tick = 0;
			FallingAngel.AutoSell.AutoSell.AfkForDays();
		}
		
	}


Commands

 

public class Commands extends CommandBase
{ 
    private final List aliases;
  

    private String planets;
  
    public Commands() 
    { 
        aliases = new ArrayList(); 
        aliases.add("planet"); 
        aliases.add("reco"); 
        
    } 
  
    @Override 
    public int compareTo(Object o)
    { 
        return 0; 
    } 

    @Override 
    public String getName() 
    { 
        return "planet"; 
    } 

    @Override         
    public String getCommandUsage(ICommandSender var1) 
    { 
        return "planet <text>"; 
    } 
    
    @Override
    public List getAliases() 
    { 
        return this.aliases;
    } 

    @Override
	public void execute(ICommandSender sender, String[] args) throws CommandException {
    	
    	if (args.length == 0)
    	{
    		Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eplease enter in a planet or do '/planet list' to see the §ecurrent planet! "));
	
    	}
    	
    	else if (args[0].equals("list"))
		{
    		if(planets != null && !planets.isEmpty()) 
    		{
    		System.out.println(args[0]);
			Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eCurrent Planet: §4§l" + planets.toUpperCase()));
    		}
    		else
    		{
    			Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eNo current planet!"));
    		}
		}
    	
    	else 
    	{	

    			FallingAngel.AutoSell.AutoSell.planet = args[0];
    			planets = args[0];
    			Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§eplanet has been set to: §4§l" + args[0].toUpperCase() + " §r§eplanet"));

    	}
		
	}
    public boolean canCommandSenderUse(ICommandSender var1) 
    { 
        return true;
    } 

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

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

 

Link to comment
Share on other sites

Update - got the code to only fire 2x now. I am using phase but for some reason it fires 2x instead of once any idea why?

 

public class Seller {
    private int count = 0;

    @SubscribeEvent
    public void playerTickEvent(TickEvent.PlayerTickEvent event) 
    {
    if (event.phase == TickEvent.Phase.END) {
        if(this.count < 20)
        {
            this.count++;
        }
        else
        {
            this.count = 0;
            if (FallingAngel.AutoSell.LivingEntityEventHandlers.run == 1)
            {
                FallingAngel.AutoSell.LivingEntityEventHandlers.run = 0;
                FallingAngel.AutoSell.AutoSell.sellShit();
                
            }
        }
    }
}
}

public class Seller {
	private int count = 0;

	@SubscribeEvent
	public void playerTickEvent(TickEvent.PlayerTickEvent event) 
	{
	if (event.phase == TickEvent.Phase.END) {
	    if(this.count < 20)
	    {
	        this.count++;
	    }
	    else
	    {
	        this.count = 0;
	        if (FallingAngel.AutoSell.LivingEntityEventHandlers.run == 1)
    		{
	        	FallingAngel.AutoSell.LivingEntityEventHandlers.run = 0;
    			FallingAngel.AutoSell.AutoSell.sellShit();
    			
    		}
	    }
	}
}
}

 

Link to comment
Share on other sites

For your anti-AFK, please not that 

FMLNetworkEvent.ClientConnectedToServerEvent

says in its class:

Fired at the client when a client connects to a server

 

Its only fired ONCE, so your counter is only ever incremented once

 

Will your mod be on the server that you are connecting to?

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

45 minutes ago, Cadiboo said:

For your anti-AFK, please not that 


FMLNetworkEvent.ClientConnectedToServerEvent

says in its class:

Fired at the client when a client connects to a server

 

Its only fired ONCE, so your counter is only ever incremented once

 

Will your mod be on the server that you are connecting to?

Anti Afk was changed to a player tick event as that needed to be on a timer and works now :)

No it will not be on the server. The only issue I have now is this:

public class Seller {
	private int count = 0;

	@SubscribeEvent
	public void playerTickEvent(TickEvent.PlayerTickEvent event) 
	{
	if (event.phase == TickEvent.Phase.END) {
	    if(this.count < 12000)
	    {
	        this.count++;
	    }
	    else
	    {
	    count = 0;
	    FallingAngel.AutoSell.AutoSell.sellShit();			
    	}
	    }
	}
}

is running the FallingAngel.AutoSell.AutoSell.sellShit(); 2x rather than 1 time. 

Link to comment
Share on other sites

There's also a SIDE parameter. CLIENT and SERVER.

You need to pick one.

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

Try inserting some logging to find out what side it is being called on, what called it etc.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

  • 1 year later...
On 3/13/2018 at 4:36 PM, diesieben07 said:
  • No, it does not have to be 1.8. Update. No, I don't care about your server or whatever stupid ancient mod you are trying to use. If whatever it is has not updated by now (it's been over three years), it's time to abandon it.

Half the Minecraft multiplayer player-base still play 1.8, shut the fuck up and stop being so ignorant

Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam dunia perjudian berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
  • Topics

×
×
  • Create New...

Important Information

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