Posted February 8, 201312 yr I'm making some armor. And I want it to give the player a potion effect while wearing it. Please post what code to write (or at least some of it) and a short explanation. Thank you.
February 8, 201312 yr You'll need to have a tickHandler to do it. put this in your main mod file proxy.registerServerTickHandler(); put this in your commonProxy public void registerServerTickHandler() { TickRegistry.registerTickHandler(new ServerTickHandler(), Side.SERVER); } and make a new file with this in it package matt.lyoko; import java.util.EnumSet; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ServerTickHandler implements ITickHandler { private void onPlayerTick(EntityPlayer player) { if (player.getCurrentItemOrArmor(4) != null && player.getCurrentItemOrArmor(3) != null && player.getCurrentItemOrArmor(2) != null && player.getCurrentItemOrArmor(1) != null) { ItemStack helmet = player.getCurrentItemOrArmor(4); ItemStack chest = player.getCurrentItemOrArmor(3); ItemStack legs = player.getCurrentItemOrArmor(2); ItemStack boots = player.getCurrentItemOrArmor(1); if (helmet.getItem() == HELMET && chest.getItem() == CHEST && legs.getItem() == LEGGINGS && boots.getItem() == BOOTS) { //potion id, number of ticks, level + 1 //ticks can be at 20 because this is updated every tick player.addPotionEffect((new PotionEffect(Potion.jump.getId(), 20, 3))); } } } @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { if (type.equals(EnumSet.of(TickType.PLAYER))) { onPlayerTick((EntityPlayer)tickData[0]); } } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.PLAYER, TickType.SERVER); } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { // TODO Auto-generated method stub } @Override public String getLabel() { // TODO Auto-generated method stub return null; } }
February 8, 201312 yr Author You'll need to have a tickHandler to do it. put this in your main mod file proxy.registerServerTickHandler(); put this in your commonProxy public void registerServerTickHandler() { TickRegistry.registerTickHandler(new ServerTickHandler(), Side.SERVER); } and make a new file with this in it package matt.lyoko; import java.util.EnumSet; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ServerTickHandler implements ITickHandler { private void onPlayerTick(EntityPlayer player) { if (player.getCurrentItemOrArmor(4) != null && player.getCurrentItemOrArmor(3) != null && player.getCurrentItemOrArmor(2) != null && player.getCurrentItemOrArmor(1) != null) { ItemStack helmet = player.getCurrentItemOrArmor(4); ItemStack chest = player.getCurrentItemOrArmor(3); ItemStack legs = player.getCurrentItemOrArmor(2); ItemStack boots = player.getCurrentItemOrArmor(1); if (helmet.getItem() == HELMET && chest.getItem() == CHEST && legs.getItem() == LEGGINGS && boots.getItem() == BOOTS) { //potion id, number of ticks, level + 1 //ticks can be at 20 because this is updated every tick player.addPotionEffect((new PotionEffect(Potion.jump.getId(), 20, 3))); } } } @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { if (type.equals(EnumSet.of(TickType.PLAYER))) { onPlayerTick((EntityPlayer)tickData[0]); } } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.PLAYER, TickType.SERVER); } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { // TODO Auto-generated method stub } @Override public String getLabel() { // TODO Auto-generated method stub return null; } } When i do this code, it gives me the potion effect all the time. I only want it when I have a specific armor on.
February 9, 201312 yr did you change HELMET, CHEST, LEGGINGS, and BOOTS to the corresponding armor item?
February 9, 201312 yr Author did you change HELMET, CHEST, LEGGINGS, and BOOTS to the corresponding armor item? Yes I did. But I still have the potion effect all the time. EDIT: Sorry, I forgot 1 line of code. Now it works. Thank you for your help!
February 9, 201312 yr also, how he can use Scheduladed ticks, if scheduladed ticks just start at the definied tick counts, not when a player wear a armor...
February 9, 201312 yr Author But now I have a new problem. It only works in single player, not in multi player. Anybody know how to do it in multi?
February 10, 201312 yr what is the error that server gives???, and poste the code, also he cant use ScheduladedTicks because, they will need to check if the player haves that armor in the slot(and that, will need to be done every tick )
February 11, 201312 yr Author what is the error that server gives???There is no error. The error is that the Server handles the game. The server simulates everything and only tells the client what to do. If the client starts modifying stuff it all goes crazy.also he cant use ScheduladedTicks because, they will need to check if the player haves that armor in the slot(and that, will need to be done every tick ) If he adds a Potion effect of lets say 5 seconds he only needs to refresh the state every lets say 4 seconds. Not every tick. If I have to use ScheduladedTicks, how can I do it? Could you please tell me how?
February 11, 201312 yr or he can just update to lastest forge and use public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack) { } in the armor file
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.