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

Where do you calls the expandPotionArray(...)?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • Author

It is the first thing I call in the preInit method. I don't think expanding the array is an issue, because I checked it and it is at the right size that I set it to.

Then it is not the issue. So how did you give an entity the potion effect?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Yes, its one of the reasons why Forge has not touched this area much.

We can not break protocol.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.