Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Potion weirdness when ID exceeds 128


BourgeoisArab
 Share

Recommended Posts

I've been working on adding custom potion effects in my mod and to do so, have expanded the vanilla potion array to accomodate my potions thus:

public static void expandPotionArray(int arraySize) {
	Potion[] potionTypes = null;
	boolean successful = false;
	for (Field f : Potion.class.getDeclaredFields()) {
		f.setAccessible(true);
		try {
			if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a")) {
				Field modfield = Field.class.getDeclaredField("modifiers");
				modfield.setAccessible(true);
				modfield.setInt(f, f.getModifiers() & ~Modifier.FINAL);
				potionTypes = (Potion[]) f.get(null);
				final Potion[] newPotionTypes = new Potion[arraySize];
				System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length);
				f.set(null, newPotionTypes);
				successful = true;
			}
		} catch (Exception e) {
			System.err.println("BourgeoisArab made a serious boo-boo. Please report this ASAP:");
			System.err.println(e);
		}
	}
	if (successful) {
		Log.info("Potion array was expanded to " + arraySize);
	}
}

 

This is all fine and dandy, but once an effect is added to an entity, with an ID with 128 or greater causes the game to crash. This happens regardless of what the array size is, beyond 128.

With a potion ID of 150, the following error is shown:

---- Minecraft Crash Report ----
// I blame Dinnerbone.

Time: 23.6.15 11:17
Description: Ticking entity

java.lang.ArrayIndexOutOfBoundsException: -106
at net.minecraft.potion.PotionEffect.onUpdate(PotionEffect.java:124)
at net.minecraft.entity.EntityLivingBase.updatePotionEffects(EntityLivingBase.java:588)
at net.minecraft.entity.EntityLivingBase.onEntityUpdate(EntityLivingBase.java:336)
at net.minecraft.entity.Entity.onUpdate(Entity.java:386)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1766)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327)
at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:96)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2298)
at net.minecraft.world.World.updateEntity(World.java:2258)
at net.minecraft.world.World.updateEntities(World.java:2108)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2097)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039)
at net.minecraft.client.Minecraft.run(Minecraft.java:962)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

 

It appears that at 128 and beyond, the IDs are shifted by 256, into the negatives. However from debugging, this shift only seems to happen client-side, while on the server, the ID is the correct one at 150.

One might say that I don't need an array larger than 128, and that is true if only my mod is installed. But in a modpack with other mods installed, like Blood Magic, Biomes O Plenty, Witchery and Ars Magica, those 128 slots for potions suddenly become very tight.

Any ideas what is causing this, or how to fix it?

 

Update: I've tested this with even higher IDs, like 700, and they are still shifted into negatives. It appears that it is shifted by a multiple of 128, until it becomes smaller than 128. Could it be that the potion ID being sent as a byte, instead of an int?

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

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.