Jump to content

Recommended Posts

Posted

Hi, so I have a item that when held adds the regeneration effect to you. But for the regeneration to work it needs to tick down, so I want to call the script that adds the potion every three seconds when the item is held.

This is the script I want called every 3 seconds:

 

@Override

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){

super.onUpdate(stack, world, entity, par4, par5);

EntityPlayer player = (EntityPlayer) entity;

ItemStack equipped = player.getCurrentEquippedItem();

if(equipped == stack){

player.addPotionEffect(new PotionEffect(Potion.regeneration.getId(), 60, 2));

}

}

 

Thanks in advanced!

Posted

Well you could use livingupdate event. Use a counter so every 60 ticks you would Check if the entity is a Player and then Check if hes holding the item.

Posted

I have no code access right now so i can just give ideas because I dont know the functions.

You want something to happen every three seconds. Three seconds Are 60 ticks.

I See two ways.

Acess the buffs of the Player and Check if the Regen buff is already applied at least three seconds. (acutalDuration<maxDuration-60)

Check every three seconds if the Player is Holding ur item. That means saving the last tick where u checked, get the actual tick and Check if its 60 ticks later

Posted

Two ways:

 

1. Per-item solution:

- Use ItemStack's NBT to store how many ticks ago buff was added.

- +1 with every check.

- If value reaches 60, add buff.

Flaws: Vanilla is retarded and can't handle ItemStacks' NBT changes like normal human being would, and "recreates" ItemStack with every NBT change, instead of just changing value - which, in many cases, is stupid.

Opinion: Don't do this, too easy, too cheesy.

 

2. Per-entity solution

- Use IExtendedEntityProperties to store integer (ticks elapsed) and utilize Tick event to ++ it.

- Same as in 1. when tick reaches 60, do update (add effect).

Pros: Good and efficient, proper thing to do.

 

How-to:

Decide if effect should be for all entities or only players, pick LivingUpdateEvent or PlayerTickEvent.

Create class that implements IExtendedEntityProperties and save your value.

Use that value in previously created event.

 

How to use events: google has like million examples/tuts.

How to IEEP:

Working, long: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-1-7-2-1-6-4-eventhandler-and

Short: It's quite easy, look at code :D

 

EDIT

3. There is also other per-item solution that includes saving timestamp the moment when buff was last added, then instead of incrementing tick-count in NBT every tick, you simply check timestamp and see if 60 ticks passed - if so - save new timestamp and re-apply.

For timestamp you can sue currentWorldTime.

Flaws: Timestamps are not always cool to work with.

Pros: Better than 1; still worse than 2.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Is there an easier way to add a delay in my script after I do:

player.addPotionEffect(new PotionEffect(Potion.regeneration.getId(), 100, 0));

??

Posted

If you can't do it, it's most likely lack of Java experience, in which case i suggest learning and not give up :D

 

Even if you can't Java good - just by googling it you would be able to get it working, I told you what to look for.

 

If you are not planning to use that info:

Know this:

- Potion effects should be added server-side.

@Override
   public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
      super.onUpdate(stack, world, entity, par4, par5);
      if (!world.isRemote) // This will run on server
     {
         EntityPlayer player = (EntityPlayer) entity;
         ItemStack equipped = player.getCurrentEquippedItem();
         if(equipped == stack){
            player.addPotionEffect(new PotionEffect(Potion.regeneration.getId(), 60, 2));
         }
      }
  }

- Applying potion effect every tick is NOT BAD. Vanilla handles it on it's own, so as long as you want to keep potion effect all the time when item is held, you can leave code as it is.

- Setting potion duration to 1 will cause glitches, always use 2+ values (this has to do with update of effects, that might occur before or after you added the potion, thus - effect can act weird).

 

 

Is there an easier way to add a delay

No, I told you all possible proper ways, anything out of this (3 ways) is probably weird or same thing wrapped in different code (or is it?)

1.7.10 is no longer supported by forge, you are on your own.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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