Jump to content

Potion Effect on armor


MrSpring

Recommended Posts

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;
}

}

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
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.