Jump to content

[1.12.2] Making a ticking item effect


Recommended Posts

Hi, I'm new to modding minecraft and modding in general. I'm trying to make an item that highlights nearby mobs with the Glowing potion effect for a limited time. I've come up with the following code. It applies the potion effects to the player as desired, and I've confirmed that it also applies the Glowing effect to other mobs as desired. But the update method I've come up with doesn't seem to make the effect persist. I don't think the update method is being called, because I saw no STDOUT output from any System.out.println() statements when I put those in the update method. Any advice on how to resolve this would be greatly appreciated.


Also, I'm not really sure this is the best way to go about this in general. I'm just tinkering with minecraft as I'm bored over the holidays. So if you have any advice on how to better approach this type of item in general that would also be appreciated.


public class ItemMentats extends ItemBase implements ITickable {

    private String name;
    private SoundEvent sound;
    private SoundCategory soundCategory;
    private int stackSize = 8;
    private int duration = 2000;
    private float volume = 0.5f;
    private float pitch = 0.8f;

    private World world = null;
    private EntityPlayer player = null;
    private boolean isActive = false;
    private long startTime = 0;

    public ItemMentats(String name) {
        this.name = name;

        this.maxStackSize = stackSize;

    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
        ItemStack itemstack = player.getHeldItem(hand);

        if(!player.capabilities.isCreativeMode) {

        player.getCooldownTracker().setCooldown(this, 20);

        //do stuff to player
        if(!world.isRemote) {
            this.world = world;
            this.player = player;
            DoChemEffect(player, itemstack);

        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);

    private void DoChemEffect(EntityPlayer player, ItemStack itemstack) {
        player.addPotionEffect(new PotionEffect(MobEffects.GLOWING, duration, 1));
        player.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, duration, 1));
        player.addPotionEffect(new PotionEffect(MobEffects.LUCK, duration, 0));
        player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 100));

        List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, Utils.AABBfromVector(
        for(EntityLivingBase e : entities) {
            e.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 20));

        isActive = true;
        startTime = world.getTotalWorldTime();

    public void update() {
        long time = 0;
        if(world != null) time = world.getTotalWorldTime();
        if(isActive && (time == startTime + duration))
            isActive = false;
            if(time % 20 == 0) {
                List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, Utils.AABBfromVecs(
                for(EntityLivingBase e : entities) {
                    e.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 20));


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.

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.


  • Create New...

Important Information

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