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

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));
}

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.

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.

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.

  • Author

Because you are adding a new potion effect every tick.

This new effect has the full duration.

 

Then how would I make it not add every tick and instead only at 0 seconds duration?

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.