Added tick handlers and packet handlers

This commit is contained in:
MachineMuse 2012-12-17 21:59:06 -07:00
parent d43a78dcf8
commit 2c513b230a
5 changed files with 139 additions and 1 deletions

View file

@ -1,9 +1,14 @@
package machinemuse.powersuits.client;
import machinemuse.powersuits.common.CommonProxy;
import machinemuse.powersuits.common.Config;
import machinemuse.powersuits.common.PowersuitsMod;
import machinemuse.powersuits.common.TickHandler;
import net.minecraft.item.Item;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
public class ClientProxy extends CommonProxy {
private static EquipmentRenderer eRenderer = new EquipmentRenderer();
@ -22,4 +27,12 @@ public class ClientProxy extends CommonProxy {
MinecraftForgeClient.preloadTexture("/gui/tinktablegui.png");
}
public void registerHandlers() {
tickHandler = new TickHandler();
TickRegistry.registerTickHandler(tickHandler, Side.CLIENT);
packetHandler = new ClientPacketHandler();
NetworkRegistry.instance().registerChannel(packetHandler,
Config.getNetworkChannelName());
}
}

View file

@ -1,13 +1,29 @@
package machinemuse.powersuits.common;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
public class CommonProxy {
public static String ITEMS_PNG = "/tutorial/generic/items.png";
public static String BLOCK_PNG = "/tutorial/generic/block.png";
public static ITickHandler tickHandler;
public static IPacketHandler packetHandler;
// Client stuff
public void registerRenderers() {
// Nothing here as this is the server side proxy
}
public void registerHandlers() {
tickHandler = new TickHandler();
TickRegistry.registerTickHandler(tickHandler, Side.SERVER);
packetHandler = new ServerPacketHandler();
NetworkRegistry.instance().registerChannel(packetHandler,
Config.getNetworkChannelName());
}
}

View file

@ -33,6 +33,10 @@ public class Config extends Configuration {
config.save();
}
public static String getNetworkChannelName() {
return "MachineMuse PowerSuits";
}
public static CreativeTabs getCreativeTab() {
return CreativeTabs.tabMisc;
}
@ -117,5 +121,4 @@ public class Config extends Configuration {
}
}
}

View file

@ -0,0 +1,98 @@
package machinemuse.powersuits.common;
import java.util.EnumSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
public class TickHandler implements ITickHandler {
/**
* Called at the "start" phase of a tick
*
* Multiple ticks may fire simultaneously- you will only be called once with
* all the firing ticks
*/
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
World world;
EntityPlayer player;
if (type.contains(TickType.WORLD)) {
world = (World) tickData[0];
}
}
/**
* Called at the "end" phase of a tick
*
* Multiple ticks may fire simultaneously- you will only be called once with
* all the firing ticks
*/
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
// TODO Auto-generated method stub
}
/**
* Returns the list of ticks this tick handler is interested in receiving at
* the minute
*/
@Override
public EnumSet<TickType> ticks() {
return EnumSet.of(
TickType.WORLD,
TickType.PLAYER);
// return EnumSet.of(TickType.WORLD);
}
/**
* A profiling label for this tick handler
*/
@Override
public String getLabel() {
return "MachineMuse Powersuits";
}
/**
* Tick types:
*
* WORLD - server and client side - Fired during the world evaluation loop
*
* arg 0 : world object of the world that is ticking
*
*
* RENDER - client side Fired during the render processing phase
*
* arg 0 : float "partial render time"
*
* GUI - client side Fired during the render processing phase if a GUI is
* open
*
* arg 0 : float "partial render time"
*
* arg 1 : the open gui or null if no gui is open
*
*
* CLIENTGUI - client side - Fired during the client evaluation loop arg 0 :
* The open gui or null if no gui is open
*
* WORLDLOAD - server side - Fired once as the world loads from disk
*
* CLIENT - client side - Fired once per client tick loop.
*
* PLAYER - client and server side. - Fired whenever the player's update
* loop runs.
*
* arg 0 : the player
*
* arg 1 : the world the player is in
*
*
* SERVER - server side - This is the server game tick. Fired once per tick
* loop on the server.
*/
}

View file

@ -1,9 +1,17 @@
package machinemuse.powersuits.common.augmentation;
import java.util.List;
import net.minecraft.item.ItemStack;
public abstract class Augmentation {
public abstract String getName();
public abstract float getWeight();
public abstract boolean isValidForSlot(int slot);
public abstract List<ItemStack> getMaterialCost();
public abstract List<ItemStack> getMaterialRefund();
}