In 1.7 the Tick handlers have switched to events. There are a few different ones such as player tick and client tick. These events are registered on the FML bus rather than the forge bus.
FMLCommonHandler.instance().bus().register(Your Event Class Here);
The event itself is rather standard. There are five variations that all behave similarly to the old tick handlers.
//Called whenever the player is updated or ticked.
@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
}
//Called when the client ticks.
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
}
//Called when the server ticks. Usually 20 ticks a second.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
}
//Called when a new frame is displayed (See fps)
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent event) {
}
//Called when the world ticks
@SubscribeEvent
public void onWorldTick(TickEvent.WorldTickEvent event) {
}
Typically you put it somewhere in your main class, such as during the FMLInitializationEvent.
However, I highly recommend against using a TickEvent (aka TickHandler) unless you absolutely have no other options. See the section under 'Tick Handlers' here for other ways you can manage ticks without using a TickEvent.
Which one would I use for making a block under a player?
Here's my event handler class code:
public class Player_Tick_Events { @SubscribeEvent public void onPlayerTick(LivingUpdateEvent e) { if (e.entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)e.entity; if(player.isSneaking()) { makeBlockUnderPlayer(player); } } }
private void makeBlockUnderPlayer(EntityPlayer player) { int x, y, z; Block blockUnderPlayer; World world; x = MathHelper.floor_double(player.posX); y = MathHelper.floor_double(player.boundingBox.minY)-1; z = MathHelper.floor_double(player.posZ); blockUnderPlayer = player.worldObj.getBlock(x, y, z); world = player.getEntityWorld(); if (blockUnderPlayer == Blocks.air) { world.setBlock(x, y, z, Block.Stone); } } }
Yep, use the PlayerTickEvent, but only set blocks on the server side (i.e. when the world is NOT remote) or you will end up with strange graphical glitches / ghost blocks.
public void postInit(FMLPostInitializationEvent e)
{
// System.out.println(name + " " + version + " is now up and running!");
if ( FMLCommonHandler.instance().getSide().isServer())
{
FMLCommonHandler.instance().bus().register(new Player_Tick_Events());
MinecraftForge.EVENT_BUS.register(new Player_Tick_Events());
}
if ( FMLCommonHandler.instance().getSide().isClient())
{
I am trying to register a tick handler in the latest forge for 1.7.10. I know in the past you would have to use this code.
TickRegistry.registerTickHandler(new RandomBattleTickHandler(), Side.SERVER);
but when I try this in the new forge it doesnt work. Help would be greatly appreciated.
The event itself is rather standard. There are five variations that all behave similarly to the old tick handlers.
Farewell everyone o/
because I can't figure it out.
However, I highly recommend against using a TickEvent (aka TickHandler) unless you absolutely have no other options. See the section under 'Tick Handlers' here for other ways you can manage ticks without using a TickEvent.
Here's my event handler class code: