Jump to content

Make something happen when the game ticks (ITickHandler Replacement)


dude22072

Recommended Posts

Back in 1.6.4 i had this code:

package dudesmods.lozmod2.proxy;

import java.util.EnumSet;

import javax.activation.CommandMap;

import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandHandler;
import net.minecraft.command.CommandServerOp;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.ServerCommand;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.world.WorldSettings;
import net.minecraftforge.event.CommandEvent;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import dudesmods.lozmod2.LOZmod;
import dudesmods.lozmod2.LOZmodTCAPI;

public class CommonTickHandler implements ITickHandler {

public void onPlayerTick(EntityPlayer player) {
	if(player.getCurrentItemOrArmor(0) != null && player.getHealth() < 19) {
		ItemStack hand = player.getCurrentItemOrArmor(0);

		if(hand.getItem() == LOZmod.healingStone && hand.getItemDamage() > 0 && hand.getItemDamage() < 500){
			hand.damageItem(1, player);
			player.heal(2.0F);
		}
	}
}

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if(type.equals(EnumSet.of(TickType.PLAYER))){
		onPlayerTick((EntityPlayer) tickData[0]);
	}
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {

}

@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.PLAYER, TickType.SERVER);

}

@Override
public String getLabel() {
	return null;
}

}

 

What would the replacement for this be in 1.7.2???

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

Get rid of the @ForgeSubscibe and replace it with @SubscribeEvent, and register it with this in your preinit:

FMLCommonHandler.instance().bus().register(new CommonTickHandler());

instead of the old way.

 

 

Also change onPlayerTick(tickevent event) into onPlayerTick(TickEvent.PlayerTickEvent event){ }

 

Hope this helps!!

Creator of Metroid Cubed! Power Suits, Beams, Hypermode and more!

width=174 height=100http://i.imgur.com/ghgWmA3.jpg[/img]

Link to comment
Share on other sites

Better yet, remove your tick event / handler altogether and use the Item onArmorTick method, which is called every tick for custom armor while worn.

 

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack stack) {
if (this == LOZmod.healingStone && stack.getItemDamage() > 0 etc.) {
// heal
}
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.