Jump to content

[1.8.9] Item Holding


Recable

Recommended Posts

What happens is right now when holding the gemstone it gives the holder regeneration 2, however at the moment the timer doesn't tick down, making it so that the player doesn't actually regenerate, how do I fix this?

 

package com.Recable.mod.gemstones;

import java.util.List;

import com.Recable.mod.ModGlobal;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;

public class ModVitalityGemstone extends Item {

public ModVitalityGemstone(String unlocalizedName) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(ModGlobal.ModCreativeTabGemstones);
	this.setMaxStackSize(1);
}

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entity, int i, boolean flag) {
	if (entity instanceof EntityPlayer) {          
    	  EntityPlayer Player = (EntityPlayer) entity;
          if(Player.getCurrentEquippedItem() != null && Player.getCurrentEquippedItem().getItem() instanceof ModVitalityGemstone) {
        	  Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 2 - 1));
        	  Player.removePotionEffect(i);
          }
          else {
        	  Player.removePotionEffect(i);
          }
	}
}
	private void effectPlayer(Entity entityIn, Potion potion, int amplifier) {

		EntityLivingBase player = (EntityLivingBase) entityIn;
		if (player.getActivePotionEffect(potion)== null || player.getActivePotionEffect(potion).getDuration() <=20)
			player.addPotionEffect(new PotionEffect(potion.id, 40 /** Duration */, amplifier, true, true));
}

Link to comment
Share on other sites

Use

EntityLivingBase#isPotionActive(Potion)

to ensure the potion isn't already active before applying it. Your

effectPlayer

method is already doing something similar, but it's never called from anywhere.

 

The

int

argument of

Item#onUpdate

is the inventory slot containing the item, passing it to

EntityLivingBase#removePotionEffect

is a bad idea since it expects a completely different data type (a potion ID).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Regeneration is one of the potion effects that takes its duration remaining into account when applying its effect: it only heals on certain ticks.  Generally speaking, its every 10.  So setting the duration to 50 every tick, it ticks down to 49, 49 % 10 is not 0, no healing is applied.  Repeat.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yeah but the problem is, the timer doesn't tick down at all?

 

Le me spell my post out a little more clearly:

 

Set the duration to 50

It ticks down to 49

49 % 10 is not 0, no healing is applied.

Set the duration to 50

It ticks down to 49

49 % 10 is not 0, no healing is applied.

Set the duration to 50

It ticks down to 49

49 % 10 is not 0, no healing is applied.

Set the duration to 50

It ticks down to 49

49 % 10 is not 0, no healing is applied.

Set the duration to 50

It ticks down to 49

49 % 10 is not 0, no healing is applied.

Set the duration to 50

It ticks down to 49

49 % 10 is not 0, no healing is applied.

 

Rinse, repeat.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.