// Path: src/main/java/net/mcft/copy/backpacks/misc/util/ClientUtils.java
// public final class ClientUtils {
// 	
// 	private ClientUtils() {  }
// 	
// 	
// 	/** Returns the local (client) player entity. Will crash if called on the server. */
// 	public static EntityPlayer getPlayer() { return getMC().player; }
// 	
// 	/** Returns the local (client) world. Will crash if called on the server. */
// 	public static World getWorld() { return getMC().world; }
// 	
// 	/** Returns the local (client) thread scheduler, which allows tasks to be
// 	 *  scheduled on the main game thread. Will crash if called on the server. */
// 	public static IThreadListener getScheduler() { return getMC(); }
// 	
// 	
// 	private static Minecraft getMC() { return Minecraft.getMinecraft(); }
// 	
// }


import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.mcft.copy.backpacks.misc.util.ClientUtils;
package net.mcft.copy.backpacks.network;




public abstract class BackpacksMessageHandler<T extends IMessage> implements IMessageHandler<T, IMessage> {
	
	/** Returns whether the message handling should be scheduled, meaning it
	 *  will be executed on the world thread instead of the network thread. */
	public boolean isScheduled() { return true; }
	
	public abstract void handle(T message, MessageContext ctx);
	
	// IMessageHandler implementation
	
	@Override
	public final IMessage onMessage(T message, MessageContext ctx) {
		if (!isScheduled()) handle(message, ctx);
		else getScheduler(ctx).addScheduledTask(() -> handle(message, ctx));
		return null;
	}
	
	// Utility methods
	
	/** Returns the player associated with this message context.
	 *  On the server, returns the player who sent the message.
	 *  On the client, returns the local player entity. */
	public static EntityPlayer getPlayer(MessageContext ctx)
// Path: src/main/java/net/mcft/copy/backpacks/misc/util/ClientUtils.java
// public final class ClientUtils {
// 	
// 	private ClientUtils() {  }
// 	
// 	
// 	/** Returns the local (client) player entity. Will crash if called on the server. */
// 	public static EntityPlayer getPlayer() { return getMC().player; }
// 	
// 	/** Returns the local (client) world. Will crash if called on the server. */
// 	public static World getWorld() { return getMC().world; }
// 	
// 	/** Returns the local (client) thread scheduler, which allows tasks to be
// 	 *  scheduled on the main game thread. Will crash if called on the server. */
// 	public static IThreadListener getScheduler() { return getMC(); }
// 	
// 	
// 	private static Minecraft getMC() { return Minecraft.getMinecraft(); }
// 	
// }


// Path: src/main/java/net/mcft/copy/backpacks/network/BackpacksMessageHandler.java
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IThreadListener;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.mcft.copy.backpacks.misc.util.ClientUtils;

package net.mcft.copy.backpacks.network;




public abstract class BackpacksMessageHandler<T extends IMessage> implements IMessageHandler<T, IMessage> {
	
	/** Returns whether the message handling should be scheduled, meaning it
	 *  will be executed on the world thread instead of the network thread. */
	public boolean isScheduled() { return true; }
	
	public abstract void handle(T message, MessageContext ctx);
	
	// IMessageHandler implementation
	
	@Override
	public final IMessage onMessage(T message, MessageContext ctx) {
		if (!isScheduled()) handle(message, ctx);
		else getScheduler(ctx).addScheduledTask(() -> handle(message, ctx));
		return null;
	}
	
	// Utility methods
	
	/** Returns the player associated with this message context.
	 *  On the server, returns the player who sent the message.
	 *  On the client, returns the local player entity. */
	public static EntityPlayer getPlayer(MessageContext ctx)
		{ return (ctx.side.isServer() ? ctx.getServerHandler().player : ClientUtils.getPlayer()); }