Jump to content

[1.12.2] Making a ticking item effect


quicheman

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

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Slot Bank BRI atau Daftar slot Bank BRI bisa anda lakukan pada situs Museumbola kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di Museumbola adalah anda akan mendapatkan bonus 50% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 10 ribu rupiah saja anda sudah bisa bermain bersama kami di Museumbola. Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.    
    • Museumbola adalah situs judi slot BANK BCA tergacor 2024 dengan minimal deposit  10 ribu rupiah saja anda sudah bisa spin slot gacor di Museumbola. Mulai dari Pragmatic, Pg Soft, Habanero, Playstar, Spadegaming, dan masih banyak lagi. Pilihan slot yang begitu banyak tidak akan membuat anda bosan. Segera daftarkan BANK BCA anda dan jadi member aktif Museumbola. anda akan diberi kesempatan mendapatkan bonus deposit harian setiap hari. Segera Klik DAFTAR sekarang juga sebelum terlambat.  
    • Slot BANK BCA adalah pilihan tergacor untuk memulai bermain slot judi Online dimuka bumi saat ini. Jika anda mempunyai BANK BCA, Anda berkesempatan mendapatkan Akun Pro atau ID pro untuk bermain slot. Tunggu apa lagi? Segera daftarkan diri anda sekarang dan dapatkan kemewahan menang maxwin di Museumbola.
    • SLOT SCATTER HITAM : SLOT MAHJONG SCATTER HITAM - MAHJONG WAYS SCATTER HITAM - SLOT PRAGMATIC SCATTER HITAM KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • SLOT 1000 : SLOT1000 DEPOSIT 1000 VIA DANA - SLOT 1000 VIA QRIS - SLOT DEPOSIT QRIS 1000 - SLOT DEPO 1K - SLOT 1000 BET KECIL KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
  • Topics

×
×
  • Create New...

Important Information

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