Posted June 23, 201510 yr 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?
June 23, 201510 yr 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.
June 23, 201510 yr 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.
June 23, 201510 yr 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.
June 23, 201510 yr http://wiki.vg/Protocol#Entity_Effect http://wiki.vg/Protocol#Data_types I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
June 23, 201510 yr Author http://wiki.vg/Protocol#Entity_Effect http://wiki.vg/Protocol#Data_types So it is a byte. Does this mean there is no solution and I just have to make do with 128 slots?
June 23, 201510 yr 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.