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 package com.mumfrey.liteloader.core; 1 package com.mumfrey.liteloader.core;
2 2
  3 +import net.minecraft.server.MinecraftServer;
  4 +
3 5
4 public interface IEventState 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,6 +34,7 @@ import com.mumfrey.liteloader.PluginChannelListener;
34 import com.mumfrey.liteloader.ServerCommandProvider; 34 import com.mumfrey.liteloader.ServerCommandProvider;
35 import com.mumfrey.liteloader.ServerPlayerListener; 35 import com.mumfrey.liteloader.ServerPlayerListener;
36 import com.mumfrey.liteloader.ServerPluginChannelListener; 36 import com.mumfrey.liteloader.ServerPluginChannelListener;
  37 +import com.mumfrey.liteloader.ServerTickable;
37 import com.mumfrey.liteloader.api.InterfaceProvider; 38 import com.mumfrey.liteloader.api.InterfaceProvider;
38 import com.mumfrey.liteloader.api.Listener; 39 import com.mumfrey.liteloader.api.Listener;
39 import com.mumfrey.liteloader.common.GameEngine; 40 import com.mumfrey.liteloader.common.GameEngine;
@@ -146,6 +147,11 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe @@ -146,6 +147,11 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe
146 private FastIterable<PlayerMoveListener> playerMoveListeners = new HandlerList<PlayerMoveListener>(PlayerMoveListener.class, ReturnLogicOp.AND_BREAK_ON_FALSE); 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 * ctor 155 * ctor
150 * 156 *
151 * @param loader 157 * @param loader
@@ -203,6 +209,7 @@ public abstract class LiteLoaderEventBroker&lt;TClient, TServer extends MinecraftSe @@ -203,6 +209,7 @@ public abstract class LiteLoaderEventBroker&lt;TClient, TServer extends MinecraftSe
203 delegate.registerInterface(PlayerInteractionListener.class); 209 delegate.registerInterface(PlayerInteractionListener.class);
204 delegate.registerInterface(PlayerMoveListener.class); 210 delegate.registerInterface(PlayerMoveListener.class);
205 delegate.registerInterface(CommonPluginChannelListener.class); 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,6 +256,14 @@ public abstract class LiteLoaderEventBroker&lt;TClient, TServer extends MinecraftSe
249 { 256 {
250 this.playerMoveListeners.add(playerMoveListener); 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 * @param instance 269 * @param instance
@@ -349,9 +364,10 @@ public abstract class LiteLoaderEventBroker&lt;TClient, TServer extends MinecraftSe @@ -349,9 +364,10 @@ public abstract class LiteLoaderEventBroker&lt;TClient, TServer extends MinecraftSe
349 this.loader.onWorldChanged(world); 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 public boolean onPlaceBlock(NetHandlerPlayServer netHandler, EntityPlayerMP playerMP, BlockPos pos, EnumFacing facing) 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,6 +3,7 @@ package com.mumfrey.liteloader.core;
3 import java.lang.ref.WeakReference; 3 import java.lang.ref.WeakReference;
4 4
5 import net.minecraft.entity.player.EntityPlayerMP; 5 import net.minecraft.entity.player.EntityPlayerMP;
  6 +import net.minecraft.server.MinecraftServer;
6 import net.minecraft.util.BlockPos; 7 import net.minecraft.util.BlockPos;
7 import net.minecraft.util.EnumFacing; 8 import net.minecraft.util.EnumFacing;
8 import net.minecraft.util.MovingObjectPosition; 9 import net.minecraft.util.MovingObjectPosition;
@@ -70,7 +71,7 @@ public class PlayerEventState implements IEventState @@ -70,7 +71,7 @@ public class PlayerEventState implements IEventState
70 } 71 }
71 72
72 @Override 73 @Override
73 - public void onTick() 74 + public void onTick(MinecraftServer server)
74 { 75 {
75 if (this.leftClick && this.suppressLeftTicks == 0) 76 if (this.leftClick && this.suppressLeftTicks == 0)
76 { 77 {