summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/potions
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/potions')
-rwxr-xr-x[-rw-r--r--]src/main/java/darkknight/jewelrycraft/potions/PotionBase.java7
-rwxr-xr-x[-rw-r--r--]src/main/java/darkknight/jewelrycraft/potions/PotionList.java86
-rwxr-xr-x[-rw-r--r--]src/main/java/darkknight/jewelrycraft/potions/PotionStun.java17
3 files changed, 41 insertions, 69 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/potions/PotionBase.java b/src/main/java/darkknight/jewelrycraft/potions/PotionBase.java
index 3160e91..0c170e5 100644..100755
--- a/src/main/java/darkknight/jewelrycraft/potions/PotionBase.java
+++ b/src/main/java/darkknight/jewelrycraft/potions/PotionBase.java
@@ -1,11 +1,12 @@
package darkknight.jewelrycraft.potions;
import java.util.ArrayList;
+
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.Potion;
public class PotionBase extends Potion {
- private static ArrayList<PotionBase> potions = new ArrayList<PotionBase>();
+ private static ArrayList<PotionBase> potions = new ArrayList<>();
public PotionBase(int id, boolean isBad, int color) {
super(id, isBad, color);
@@ -16,5 +17,7 @@ public class PotionBase extends Potion {
return potions;
}
- public void action(EntityLivingBase entity) {}
+ public void action(EntityLivingBase entity) {
+ // Do nothing
+ }
}
diff --git a/src/main/java/darkknight/jewelrycraft/potions/PotionList.java b/src/main/java/darkknight/jewelrycraft/potions/PotionList.java
index 6749c37..632e92a 100644..100755
--- a/src/main/java/darkknight/jewelrycraft/potions/PotionList.java
+++ b/src/main/java/darkknight/jewelrycraft/potions/PotionList.java
@@ -3,76 +3,32 @@
*/
package darkknight.jewelrycraft.potions;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
-import darkknight.jewelrycraft.JewelrycraftMod;
import net.minecraft.potion.Potion;
/**
- * @author Sorin
- * Code for extending Potion list from Mithion
- * SOurce: https://github.com/Mithion/ArsMagica2/blob/master/src/main/java/am2/buffs/BuffList.java
+ * @author Sorin Code for extending Potion list from Mithion SOurce:
+ * https://github.com/Mithion/ArsMagica2/blob/master/src/main/java/am2/buffs/BuffList.java
*/
-public class PotionList
-{
- public static Potion stun;
- private static int potionDefaultOffset = 0;
-
- public static void preInit(FMLPreInitializationEvent e)
- {
- }
-
- private static void setFinalStatic(Field field, Object newValue) throws Exception
- {
- field.setAccessible(true);
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
- field.set(null, newValue);
- }
-
- private static void extendPotionsArray() throws Exception
- {
- JewelrycraftMod.logger.info("Extending potions array");
- JewelrycraftMod.logger.info("Injecting potions starting from index " + Potion.potionTypes.length);
- potionDefaultOffset = Potion.potionTypes.length;
- setPotionArrayLength(255);
- }
-
- private static void setPotionArrayLength(int length) throws Exception
- {
- if (length <= Potion.potionTypes.length)
- return;
- Potion[] potions = new Potion[length];
- for(int i = 0; i < Potion.potionTypes.length; ++i){
- potions[i] = Potion.potionTypes[i];
- }
- Field field = null;
- Field[] fields = Potion.class.getDeclaredFields();
- for(Field f: fields){
- if (f.getType().equals(Potion[].class)) {
- field = f;
- break;
- }
- }
- setFinalStatic(field, potions);
- }
-
- public static void init(FMLInitializationEvent e)
- {
- try{
- extendPotionsArray();
- }
- catch(Throwable t){
- JewelrycraftMod.logger.error("Failed to extend potion ids!");
- t.printStackTrace();
- }
- stun = new PotionStun(potionDefaultOffset + 0, true, 0x000000);
- }
-
- public static void postInit(FMLPostInitializationEvent e)
- {}
+public class PotionList {
+ public static Potion stun;
+
+ public static void preInit(FMLPreInitializationEvent e) {
+ // Do nothing
+ }
+
+ public static void init(FMLInitializationEvent e) {
+ if (Potion.potionTypes.length > 231) {
+ stun = new PotionStun(230, true, 0x000000);
+ } else {
+ stun = new PotionStun(Potion.potionTypes.length - 2, true,
+ 0x000000);
+ }
+ }
+
+ public static void postInit(FMLPostInitializationEvent e) {
+ // Do nothing
+ }
}
diff --git a/src/main/java/darkknight/jewelrycraft/potions/PotionStun.java b/src/main/java/darkknight/jewelrycraft/potions/PotionStun.java
index e1f43e6..a361e9f 100644..100755
--- a/src/main/java/darkknight/jewelrycraft/potions/PotionStun.java
+++ b/src/main/java/darkknight/jewelrycraft/potions/PotionStun.java
@@ -15,20 +15,33 @@ public class PotionStun extends PotionBase {
this.setPotionName(Variables.MODID + ".potion.stun");
}
+ @Override
public void action(EntityLivingBase entity) {
entity.motionX *= 0D;
entity.motionZ *= 0D;
entity.motionY *= 0D;
+
entity.isSwingInProgress = false;
+
entity.moveForward = 0F;
entity.moveStrafing = 0F;
+
entity.setAIMoveSpeed(0F);
+
entity.limbSwing = 0F;
entity.limbSwingAmount = 0F;
entity.swingProgressInt = 0;
+
entity.rotationPitch = entity.prevRotationPitch;
entity.rotationYaw = entity.prevRotationYaw;
- entity.worldObj.spawnParticle("spell", entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ, 0.0D, 0.3D, 0.0D);
- if (entity.getActivePotionEffect(PotionList.stun).getDuration() == 0) entity.removePotionEffect(PotionList.stun.id);
+
+ entity.worldObj.spawnParticle("spell", entity.posX,
+ entity.posY + entity.getEyeHeight(), entity.posZ, 0.0D,
+ 0.3D, 0.0D);
+
+ if (entity.getActivePotionEffect(PotionList.stun)
+ .getDuration() == 0) {
+ entity.removePotionEffect(PotionList.stun.id);
+ }
}
}