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

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) {
        super(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) {
            itemstack.shrink(1);
        }

        //world.playSound(());
        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(
                this.player.getPositionVector().subtract(12,12,12),
                this.player.getPositionVector().addVector(12,12,12)));
        for(EntityLivingBase e : entities) {
            e.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 20));
        }

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


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

 

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.