Jump to content

Recommended Posts

Posted

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?

Posted

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/

Posted

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.

Posted

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.

Posted

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)

Posted

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/

Posted

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]

Posted

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

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

    • logs too big for one pastebin https://pastebin.com/ZjUGHu3u  https://pastebin.com/RqCUZf3X  https://pastebin.com/6ZPS99nD
    • You probably used jd-gui to open it, didn't you? Nothing wrong with that, I also made that mistake, except that Notch was a smart guy and he obfuscated the code. That's why you only see files called "a", "b", "c" and then a file that combines them all. As I said, use RetroMCP to deobfuscate the code so that you will 100% understand it and be able to navigate it.
    • Decompiling minecraft indev, infdev, alpha, beta or whichever legacy version is really easy. I'm not a plug, I just also got interested in modding legacy versions (Infdev to be specific). Use https://github.com/MCPHackers/RetroMCP-Java Once you install their client and the Zulu Architecture that they say they recommend (or use your own Java). I encountered some problems, so I run it with: "java -jar RetroMCP-Java-CLI.jar". You should run it in a seperate folder (not in downloads), otherwise the files and folders will go all over the place. How to use RetroMCP: Type setup (every time you want change version), copy-paste the version number from their list (they support indev), write "decompile" and done! The code will now be deobfuscated and filenames will be normal, instead of "a", "b" and "c"! Hope I helped you, but I don't expect you to reply, as this discussion is 9 years old! What a piece of history!  
    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
  • Topics

×
×
  • Create New...

Important Information

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