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.

  Quote

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).

 

 

  On 5/20/2015 at 8:40 PM, Caleb6801 said:

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?)

  Quote

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

    • my game keeps crashing right before launching the game before full screen and keeps poping up this error message "error code 1 " The game crashed: rendering overlay Error: java.lang.IllegalAccessError: failed to access class com.mojang.blaze3d.platform.GlStateManager$TextureState from class net.coderbot.iris.gl.IrisRenderSystem$DSAARB (com.mojang.blaze3d.platform.GlStateManager$TextureState is in module minecraft@1.18.2 of loader 'TRANSFORMER' @d919544; net.coderbot.iris.gl.IrisRenderSystem$DSAARB is in module oculus@1.6.4 of loader 'TRANSFORMER' @d919544)
    • removing oculus or any of ETF or EMF or even embeddium doesn't change anything it just crashes again with error -1  https://gist.github.com/Tikalian-coconut/d49e8fb83bf57d5e04eb042522046786 this time i removed all 4 at same time and that gave it something is wrong with the game seriously..
    • crash report -> https://gist.github.com/Tikalian-coconut/18c41f97bdacef54725e5141f57697d7 from what i see it seems like Entity Texture Features doesn't like Oculus doing something or invert.. not sure it's why everything is all black textured but that causes a -1 error
    • well that's bad, cuz there's no crash report at all (the last crash report is from previous replies) it's probably another issue that doesn't fit in this bug report, the game works fine except that everything is black, no texture except the sky and skin, everything else is just black i've tried reloading the textures in game, see for drivers updates but it did nothing, seems like an issue with Embeddium or Oculus i think, but i know nothing compared to you i can still send the latest debug and latest.log files.. edit: it seems that when i re-add rechiseled (1.1.6-1.20.1) it crashes as error 1 (i can't remove it off from the modpack cuz that'll break all my builds on some maps) lemme start the game and get it to crash to get a crash report done)
    • If you've fallen victim to a crypto scam, you're not alone and thankfully, you're not without options. I highly recommend iBolt Cyber Hacker Company for anyone seeking professional and effective assistance in recovering scammed cryptocurrency. After extensive research and hearing from multiple satisfied clients, it's clear that iBolt stands out in a crowded and often unreliable market. Their team of experienced cyber experts and blockchain analysts uses advanced tracking techniques to follow stolen funds across the blockchain and engage with crypto exchanges when possible. They’re not just tech-savvy—they’re strategic and persistent. WHY CHOOSE iBOLT CYBER HACKER COMPANY? (1) Proven success in crypto asset recovery (2) Fast, professional, and discreet service (3) Skilled in blockchain forensics and cyber investigation (4) Committed to fighting online fraud and supporting victims Don’t give up. I strongly recommend reaching out to iBolt Cyber Hacker Company. ENQUIRIES: info @ iboltcyberhack . org/ www . iboltcyberhack. org/ +39. 351. 105. 3619.
  • Topics

×
×
  • Create New...

Important Information

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