Jump to content

[1.7.10] [SOLVED] How to properly extend Potion?


kauan99

Recommended Posts

Do I need my Potion to be registered? My potion ID must really be within the range of the Potion.potionTypes array or does Forge comes to the rescue somehow to avoid mods overwriting each other's potions? How the method setIconIndex works?

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

thanks! but why do I need SRG name? the mod won't work after release if I use the deobfuscated name?

 

also,

 

Field modField = Field.class.getDeclaredField("modifiers");
modField.setAccessible(true);

 

the need of those lines seems to me like a flaw in the reflection framework. I'm reflecting on a class of the java.lang.reflect package itself. this shouldn't be necessary IMO. the framework should allow something like this:

 

Field potionTypesField = Potion.class.getDeclaredField("potionTypes");
int modifiers = potionTypesField.getModifiers();
potionTypesField.setModifiers(modifiers & ~Modifier.FINAL);

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

I see. Well if it's for the sake of optimization then I agree with java dev team. I thought it was just, you know, lack of imagination.

 

one last thing: is there away to find out whether im running my mod in a deobfuscated environment, maybe some forge or fml method. This way I could set that string to the SRG name or the deobfuscated name depending on that, instead of manually changing it before release.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

Is there an event I can subscribe to handle when a potion effect is added and when it's ended? If there isn't, maybe Forge devs could give Potions some attention if I may ask. There should be a way to register them into the GameRegistry instead of having to hack the potionTypes array and all that. and there should also be events related to them. performEffect is executed too often and doesn't fit certain cases very well, the most clear example of that being a potion of flight.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

I can't understand Attribute modifiers at all. What I'm trying to do is a potion of flight. This is what I do:

 

@Override
public void performEffect(EntityLivingBase target, int amplifier)
{
if(target instanceof EntityPlayer)
{
	EntityPlayer player = (EntityPlayer)target;
	if(!player.capabilities.isCreativeMode)
	{
		PotionEffect effect = player.getActivePotionEffect(ModPotions.flight);
		if(effect != null)
		{
			if(effect.getDuration() <= 20)//strangely, it doesn't work with 1
			{
				player.capabilities.allowFlying = false;
				player.capabilities.isFlying = false;
			}
			else
			{
				player.capabilities.allowFlying = true;
		        }
		}
		else
		{
			player.capabilities.allowFlying = false;
		}
	}
}
}

@Override
public boolean isReady(int duration, int amplifier)
{
return duration == 1 || duration % 20 == 0; //returns true every 20 ticks, then performEffect is invoked
}

 

it works but I can't help but feel this is an ugly hack. I was wondering if there was a better way of doing that.

 

I tryed overloading applyAttributesModifiersToEntity and removeAttributesModifiersFromEntity (I would just invoke the super class version of the method and then set the player.capabilities to allow or disallow flight depending on the method) but setting the player's capabilities from inside those methods has no effect, probably something to do with the Side from which those methods are invoked (Server/Client).

 

Is there a better way of doing that?

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

Link to comment
Share on other sites

So my way (doing that thing inside performEffect) is the only way? I thought something invoked from server side only would end up updating the client.

WIP mods: easyautomation, easyenergy, easyelectronics, easymoney, easytrasportation, easysecurity, easymultiverse, easyfactions, easymagick, easyalchemy, easyseasons

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.