Jump to content

[1.7.10]How to count ticks properly?


FlatronEZ

Recommended Posts

Hey there,

 

I want to count ticks in my mod, to delay some methods. I found out that onUpdate() gets called on every tick, but I don't really know how to use this. I know I need some kind of event handler to implement this but while being a complete modding greenhorn  I don't really understand how to implement this. After searching through a lot of threads and tutorials I couldn't find recent information that helps me for Forge 1.7.10.

 

How do I need to use onUpdate / what kind of event handler do I need for this?

Link to comment
Share on other sites

Where do you want to count ticks?

 

Overall, if you have a method that gets called every tick, you can just increment a field. If that field is over a certain threshold, reset that field and do your stuff you want to be called every so often.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Where do you want to count ticks?

 

Overall, if you have a method that gets called every tick, you can just increment a field. If that field is over a certain threshold, reset that field and do your stuff you want to be called every so often.

 

I want to count ticks (not in but for) one of my classes, where I'd like to implement a cooldown for a command. Because I am just beginning mod development I have no idea how to increase a number every tick because I cant get a event handler working.

Link to comment
Share on other sites

One thing 1st: When we ask what exactly you need - it will be better for you to answer exactly what you need.

 

I want to count ticks (not in but for) one of my classes

 

This doesn't say anything. Class can be entity, block, tile, player, server, world - tick are in EVERY aspect of game and for each of those aspects you do it more or less differently.

 

Please describe where and why you need ticker - that is very important.

 

If you want to go blindly:

ServerTickEvent

WorldTcikEvent

PlayerTickEvent

 

Overrid entity's onUpdate() or onLivingUpdate(), there is PLENTY of places.

 

How to work with it?

Google Forge Event tutorial.

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

Link to comment
Share on other sites

If you just want to execute things delayed there is a method in The Minecraft routine where you can pass a runnable Object and a number that stands for The amount of ticks The task should be delayed. Could be in The MinecraftServer class, I think ernio might know what im talking about.. (Maybe just search your IDE for it since im on my mobile)

Link to comment
Share on other sites

If you just want to execute things delayed there is a method in The Minecraft routine where you can pass a runnable Object and a number that stands for The amount of ticks The task should be delayed. Could be in The MinecraftServer class, I think ernio might know what im talking about.. (Maybe just search your IDE for it since im on my mobile)

 

If someone is not strong enough in Java to understand how to count ticks, I don't think it is good to suggest they try multi-threading.

 

You shouldn't need to use multi-threading for delays anyway, since there is no need. All you need is to either hook into a method that is called every tick, or one of the tick events. For things like entities, there is even a field already called ticksExisted that automatically increments, and there is also a world time that counts ticks as well.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Hi

If your doing this to delay an Item, you must use NBT as item fields are singletons. There are a vast amount of events / methods:

 

EVENTS:

* ServerTickEvent (every tick called server side)

* ClientTickEvent (every tick called client side)

* WorldTickEvent (every tick called for the world when player joined)

* PlayerTickEvent (every tick called for the player when in a world)

* RenderTickEvent (only when rendering)

* LivingUpdateEvent (only on entities)

* RenderGameOverlayEvent (only in GUI's)

 

METHODS:

* onUpdate(args) (called in Item.class)

 

Use this piece of code to increment:

private int count;

@SubscribeEvent
public void playerTickEvent(PlayerTickEvent event) //CHOOSE THE EVENT THAT BEST SUITS YOUR NEEDS
{
    if(this.count < SOMEINTEGER)
    {
        this.count++;
    }
    else
    {
        this.count = 0;
        //EXECUTE YOUR METHOD HERE
    }
}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

[snip]

This is a bad example! PlayerTickEvent will fire for every player, so in that case you would need IExtendedEntityProperties additionally to store the tick count.

Wow I did not know that! Guess I learned something today. @OP don't use PlayerTickEvent, much more events out there!

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

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

    • You shouldn't be extracting the mod .jar, just place it in your mods folder.
    • so basically another rundown of my probelm. Im the admin of a 1.20.1 modded server. Were using forge 47.2.0 but tested this issue in other forge versions too on sevrer and client side. so the forge version isnt the issue. The bug happens in following instances. Were using the attacks of the jujutsucraft mod by orca normally. And for everyone that stands there nothing changes. But everyone who wasnt in the chunks before or who relogins again those chunks will appear invisible for the most part. I tried fixing this be removing and adding following mods in many combinations. Embeddium, canary, memoryleakfix, ai improvements, Krypton reforges, better chunkloading, radium reforged, embeddium plus, farsight, betterchunkloading, oculus I tested most of these mods alone and in differents combinations with each other and without the mods. What i noticed is zhat when i removed  . most invisible chunks will return or semi return. and only ine or two chunks stay invisible. I rechanged those mids mostly on the cöient side but also some in the serveside. Ir most likely isnt an issue with another non performance mod since i noticed this thing with embeddium. Ans also the problem wasnt there im the beginning of the server. Granted since then we updated some of the mods that add content and their lib mod. But i went to every big mods discord and community that we have and i didnt find someone else havinf that chunk problem. Heres the link to a video of the Problem. https://streamable.com/9v1if2     heres the link to the modlist: https://ibb.co/myF8dtX     Pleaee im foghting for months with this problem. All the performance mods kn the modlist are for sure not the issue i tested without all of them.
    • It looks like you're only setting the health if the thing you are hitting is a player.  
    • It sounds like you accidentally have two items that are both named "orange". Ensure that you give items unique names in the string when you register them. That's one of the more annoying errors to track down if you don't know what's causing it, though.
    • when i tried downloading blockfront from curseforge for version 1.20.1 i get the winrar file  and that i extract and i just get the "manifest.json" file no mod when exctracted
  • Topics

×
×
  • Create New...

Important Information

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