Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey guys!

 

So i've written a server tick counter and I'm sure its all correct, but it doesn't seem to be running on the server. Can anyone help me as to figure out why?

 

Here is how I register my code:

@EventHandler
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new ServerEvents());
}

 

And here is my code:

import java.util.List;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent;

public class ServerEvents
{
int intervalGold = 30;
int intervalCounter = 0;
//*20 for ticks, *60 for minutes
int finalDuration = 1 * 20 * 60;

@SubscribeEvent
public void onServerTick(ServerTickEvent event) {
	if(event.phase == Phase.END) {
		//20 ticks = 1 second - check the counter is finished.
		if(intervalCounter % finalDuration == 0) {
			intervalCounter = 1; //Reset counter
			List<EntityPlayerMP> playerList = MinecraftServer.getServer().getConfigurationManager().playerEntityList;

			for(EntityPlayerMP player : playerList) {
				player.addChatMessage(new ChatComponentText("Hello"));
			}
		} else {
			intervalCounter++;
		}
	}
}
}

As mentioned, do some basic debugging: put 'System.out.println("Server tick called")' as the first line in your event listener to see if it is actually running, print out the tick counter to see what values it has, etc.

 

Also, if you are going to reset the counter each time it reaches the final duration, use '>=' instead of the modulo '%' operator. There is no point in doing division if the counter simply loops from 1-max over and over again.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.