Posted July 11, 201510 yr 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?
July 11, 201510 yr 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/
July 11, 201510 yr Author 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.
July 11, 201510 yr 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.
July 11, 201510 yr 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)
July 11, 201510 yr 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/
July 12, 201510 yr 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]
July 13, 201510 yr [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]
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.