Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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

}

  • 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.
  • 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!

also, how he can use Scheduladed ticks, if scheduladed ticks just start at the definied tick counts, not when a player wear a armor...

 

 

 

   

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

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 :) )

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

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.