shmcrae Posted February 24, 2015 Share Posted February 24, 2015 I got it working, but when the time goes to 0 the potion effect still lasts. I'm trying to make an immortal potion so when they drink it nothing can damage them for 25 seconds. Main: public static Potion ImmortalPotion; @PreInit public void load(FMLPreInitializationEvent event) { Potion[] potionTypes = null; 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[256]; System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length); f.set(null, newPotionTypes); } } catch (Exception e) { System.err.println("Severe error, please report this to the mod author:"); System.err.println(e); } MinecraftForge.EVENT_BUS.register(new AlchemyMainEventHooks()); } } @Init public void load(FMLInitializationEvent event) { ImmortalPotion = (new PotionAlchemy(32, false, 0)).setIconIndex(0, 0).setPotionName("potion.ImmortalPotion"); } Event Hook: @ForgeSubscribe public void onEntityUpdate(LivingUpdateEvent event) { if (event.entityLiving.isPotionActive(AlchemyMain.ImmortalPotion)) { if (event.entityLiving.worldObj.rand.nextInt(20) == 0) { PlayerCapabilities.disableDamage = true; } if (event.entityLiving.getActivePotionEffect(AlchemyMain.ImmortalPotion).getDuration() == 0) { event.entityLiving.removePotionEffect(AlchemyMain.ImmortalPotion.id); PlayerCapabilities.disableDamage = false; return; } } } If im missing anything let me know, thanks. Quote Link to comment Share on other sites More sharing options...
Abastro Posted February 24, 2015 Share Posted February 24, 2015 Where did you registered the potion to the array? You didn't in Main class. If you didn't, try adding the potion to the array. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium. Link to comment Share on other sites More sharing options...
shmcrae Posted February 25, 2015 Author Share Posted February 25, 2015 where exactly would i register the potion? and how would i register it? would i replace the potionType with my potion name? Thanks for your time! Quote Link to comment Share on other sites More sharing options...
Abastro Posted February 25, 2015 Share Posted February 25, 2015 Oh I misread the Potion class. The constructor would automatically registers the potion. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium. Link to comment Share on other sites More sharing options...
shmcrae Posted February 25, 2015 Author Share Posted February 25, 2015 So do you see anything wrong in the EventHook class? Quote Link to comment Share on other sites More sharing options...
Abastro Posted February 25, 2015 Share Posted February 25, 2015 It seems that PotionEfect#getDuration() does not return 0 when LivingUpdateEvent called. Maybe changing 0 to 1 would solve your problem. EDIT: No, Don't do the suggestion above. There is some methods in Potion meeting your needs. So. 1. Make your own Potion class, 2. Override applyAttributesModifiersToEntity, and add ability there. 3. Override removeAttributesModifiersFromEntity, and remove ability there. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium. Link to comment Share on other sites More sharing options...
shmcrae Posted February 25, 2015 Author Share Posted February 25, 2015 In my main class @Init public void load(FMLInitializationEvent event) { ImmortalPotion = (new PotionAlchemy(32, false, 0)).setIconIndex(0, 0).setPotionName("potion.ImmortalPotion"); } is the "PotionAlchemy" the potion class? Quote Link to comment Share on other sites More sharing options...
Abastro Posted February 25, 2015 Share Posted February 25, 2015 Of course it is your potion class : PotionAlchemy class. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium. Link to comment Share on other sites More sharing options...
shmcrae Posted February 25, 2015 Author Share Posted February 25, 2015 Like this? @Override public void applyAttributesModifiersToEntity(EntityLivingBase par1EntityLivingBase, BaseAttributeMap par2BaseAttributeMap, int par3) { PlayerCapabilities.disableDamage = true; } @Override public void removeAttributesModifiersFromEntity(EntityLivingBase par1EntityLivingBase, BaseAttributeMap par2BaseAttributeMap, int par3) { PlayerCapabilities.disableDamage = false; } Quote Link to comment Share on other sites More sharing options...
shmcrae Posted February 26, 2015 Author Share Posted February 26, 2015 Anybody? Quote Link to comment Share on other sites More sharing options...
Abastro Posted February 26, 2015 Share Posted February 26, 2015 Like this? @Override public void applyAttributesModifiersToEntity(EntityLivingBase par1EntityLivingBase, BaseAttributeMap par2BaseAttributeMap, int par3) { PlayerCapabilities.disableDamage = true; } @Override public void removeAttributesModifiersFromEntity(EntityLivingBase par1EntityLivingBase, BaseAttributeMap par2BaseAttributeMap, int par3) { PlayerCapabilities.disableDamage = false; } Correct, try that. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium. Link to comment Share on other sites More sharing options...
shadowfacts Posted February 26, 2015 Share Posted February 26, 2015 Update to 1.7.10 if not 1.8, 1.6.4 is ancient. Quote Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods Link to comment Share on other sites More sharing options...
shmcrae Posted February 27, 2015 Author Share Posted February 27, 2015 i don't want to update because im familiar to 1.6.4 code, and i already tested that and it doesn't work sooo im really stuck here Quote Link to comment Share on other sites More sharing options...
jkorn2324swagg Posted February 27, 2015 Share Posted February 27, 2015 Shmcrae if you are familiar to the 1.6 code can you help me with my question I'm also stuck at 1.6.4 Quote Link to comment Share on other sites More sharing options...
shmcrae Posted February 27, 2015 Author Share Posted February 27, 2015 I might be able to help, whats your question Quote Link to comment Share on other sites More sharing options...
jkorn2324swagg Posted February 27, 2015 Share Posted February 27, 2015 My question is the topic right below you It says: [1.6.4] Custom branches and custom leaf patterns Quote Link to comment Share on other sites More sharing options...
shmcrae Posted February 27, 2015 Author Share Posted February 27, 2015 Ok ill see what i can do and ill post on your forum Quote Link to comment Share on other sites More sharing options...
jkorn2324swagg Posted February 27, 2015 Share Posted February 27, 2015 Ok thanks Quote Link to comment Share on other sites More sharing options...
shmcrae Posted February 27, 2015 Author Share Posted February 27, 2015 I still really need help with this if anyone can help me please Quote Link to comment Share on other sites More sharing options...
Abastro Posted February 27, 2015 Share Posted February 27, 2015 What was problem.? Doesn't the code work? Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium. Link to comment Share on other sites More sharing options...
shmcrae Posted February 27, 2015 Author Share Posted February 27, 2015 it doesn't work, do i need to get rid of my EventHook? Quote Link to comment Share on other sites More sharing options...
Abastro Posted February 27, 2015 Share Posted February 27, 2015 Ah yes of course. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium. Link to comment Share on other sites More sharing options...
shmcrae Posted February 27, 2015 Author Share Posted February 27, 2015 ok ill try that Quote Link to comment Share on other sites More sharing options...
shmcrae Posted February 27, 2015 Author Share Posted February 27, 2015 now it doesn't work at all, when i drink it i take damage Quote Link to comment Share on other sites More sharing options...
Abastro Posted February 27, 2015 Share Posted February 27, 2015 Sorry, there was some mistakes I did. 1. You have to check if the Entity is player, and get the PlayerCapabilities for the player, and disable Damage for that. 2. Does applyAttributesModifiersToEntity not called? Check it. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium. Link to comment Share on other sites More sharing options...
Recommended Posts
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.