Commit e068f3708bdd3ad58fad93e6b6181c1e1dd928c6

Authored by Mumfrey
1 parent 027952f9

LiteLoader -add ServerTickable interface

java/common/com/mumfrey/liteloader/ServerTickable.java 0 → 100644
  1 +package com.mumfrey.liteloader;
  2 +
  3 +import net.minecraft.server.MinecraftServer;
  4 +
  5 +/**
  6 + * Interface for mods which want to be ticked on the server thread
  7 + *
  8 + * @author Adam Mummery-Smith
  9 + */
  10 +public interface ServerTickable extends LiteMod
  11 +{
  12 + /**
  13 + * Called at the start of every server update tick
  14 + *
  15 + * @param server
  16 + */
  17 + public abstract void onTick(MinecraftServer server);
  18 +}
... ...
java/common/com/mumfrey/liteloader/core/IEventState.java
1 1 package com.mumfrey.liteloader.core;
2 2  
  3 +import net.minecraft.server.MinecraftServer;
  4 +
3 5  
4 6 public interface IEventState
5 7 {
6   - public abstract void onTick();
  8 + public abstract void onTick(MinecraftServer server);
7 9 }
... ...
java/common/com/mumfrey/liteloader/core/LiteLoaderEventBroker.java
... ... @@ -34,6 +34,7 @@ import com.mumfrey.liteloader.PluginChannelListener;
34 34 import com.mumfrey.liteloader.ServerCommandProvider;
35 35 import com.mumfrey.liteloader.ServerPlayerListener;
36 36 import com.mumfrey.liteloader.ServerPluginChannelListener;
  37 +import com.mumfrey.liteloader.ServerTickable;
37 38 import com.mumfrey.liteloader.api.InterfaceProvider;
38 39 import com.mumfrey.liteloader.api.Listener;
39 40 import com.mumfrey.liteloader.common.GameEngine;
... ... @@ -146,6 +147,11 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe
146 147 private FastIterable<PlayerMoveListener> playerMoveListeners = new HandlerList<PlayerMoveListener>(PlayerMoveListener.class, ReturnLogicOp.AND_BREAK_ON_FALSE);
147 148  
148 149 /**
  150 + * List of mods which monitor server ticks
  151 + */
  152 + private FastIterable<ServerTickable> serverTickListeners = new HandlerList<ServerTickable>(ServerTickable.class);
  153 +
  154 + /**
149 155 * ctor
150 156 *
151 157 * @param loader
... ... @@ -203,6 +209,7 @@ public abstract class LiteLoaderEventBroker&lt;TClient, TServer extends MinecraftSe
203 209 delegate.registerInterface(PlayerInteractionListener.class);
204 210 delegate.registerInterface(PlayerMoveListener.class);
205 211 delegate.registerInterface(CommonPluginChannelListener.class);
  212 + delegate.registerInterface(ServerTickable.class);
206 213 }
207 214  
208 215 /**
... ... @@ -249,6 +256,14 @@ public abstract class LiteLoaderEventBroker&lt;TClient, TServer extends MinecraftSe
249 256 {
250 257 this.playerMoveListeners.add(playerMoveListener);
251 258 }
  259 +
  260 + /**
  261 + * @param serverTickable
  262 + */
  263 + public void addServerTickable(ServerTickable serverTickable)
  264 + {
  265 + this.serverTickListeners.add(serverTickable);
  266 + }
252 267  
253 268 /**
254 269 * @param instance
... ... @@ -349,9 +364,10 @@ public abstract class LiteLoaderEventBroker&lt;TClient, TServer extends MinecraftSe
349 364 this.loader.onWorldChanged(world);
350 365 }
351 366  
352   - public void onServerTick(MinecraftServer minecraftServer)
  367 + public void onServerTick(MinecraftServer server)
353 368 {
354   - this.playerStateList.all().onTick();
  369 + this.playerStateList.all().onTick(server);
  370 + this.serverTickListeners.all().onTick(server);
355 371 }
356 372  
357 373 public boolean onPlaceBlock(NetHandlerPlayServer netHandler, EntityPlayerMP playerMP, BlockPos pos, EnumFacing facing)
... ...
java/common/com/mumfrey/liteloader/core/PlayerEventState.java
... ... @@ -3,6 +3,7 @@ package com.mumfrey.liteloader.core;
3 3 import java.lang.ref.WeakReference;
4 4  
5 5 import net.minecraft.entity.player.EntityPlayerMP;
  6 +import net.minecraft.server.MinecraftServer;
6 7 import net.minecraft.util.BlockPos;
7 8 import net.minecraft.util.EnumFacing;
8 9 import net.minecraft.util.MovingObjectPosition;
... ... @@ -70,7 +71,7 @@ public class PlayerEventState implements IEventState
70 71 }
71 72  
72 73 @Override
73   - public void onTick()
  74 + public void onTick(MinecraftServer server)
74 75 {
75 76 if (this.leftClick && this.suppressLeftTicks == 0)
76 77 {
... ...