Jump to content

[1.14.3] Looking for what replaced tick in Block.class


kwpugh

Recommended Posts

Hi All,

 

I'm looking for guidance.   I'm converting an item that ticks crops when held in main hand.   I had used the tick method in the Block.class.

 

Since it has been deprecated:


   @Deprecated
   public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
   }

 

Where should I be looking?

 

Thank you.

 

Link to comment
Share on other sites

Quote

Cross-referencing, a quick how-to

  • Oh no! Method FooClass.BarMethod disappeared in 1.13/1.14! Where did it go? Follow these easy steps for a guaranteed 80% success rate!
  1. Open a 1.12 workspace (this is why you use a separate workspace to update, by the way)
  2. Browse to FooClass.BarMethod
  3. Use your IDE's find usages tool to see where it was called from in vanilla
  4. Pick a call site
  5. Go to that same call site in 1.13/1.14
  6. What does it call instead?
  7. ???
  8. Profit

(if these steps don't apply, then you're allowed to ask)

 

  • Like 1
  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

If I'm looking at this right, it seem that the places updateTick was called from by vanilla have been replaced with animateTick, which does not work for accelerating block state transitions (not sure if I said that right).   

 

Basically, I want to be able to accelerate the ticks received by IGrowables in a defined block distance while my item is held in the main hand.

 

Any suggestions?

 

 

Link to comment
Share on other sites

Surely the wheat block has code that runs in some tick-like manner that is the code you want to call. Have you tried looking at the wheat block?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

In digging around in the Minecraft references, I was able to figure out that the IGrowable interface controls the crops and saplings.

 

I was able to adapt my existing 1.12.2 code to work.  However, the effect is instant, which is not exactly what I want.

package com.kwpugh.gobber2.items.rings;

import java.util.List;

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.IGrowable;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;

public class ItemCustomRingFarmer extends Item
{

	public ItemCustomRingFarmer(Properties properties)
	{
		super(properties);
	}

	public void inventoryTick(ItemStack stack, World world, Entity entity, int par4, boolean par5)
    {
        
    	if(!(entity instanceof PlayerEntity) || world.isRemote)
        {
            return;
        }

    	PlayerEntity player = (PlayerEntity)entity;
        ItemStack equipped = player.getHeldItemMainhand();
        
        if(stack == equipped)
        {
            int range = 7;
            for(int x = -range; x < range+1; x++)
            {
                for(int z = -range; z < range+1; z++)
                {
                    for(int y = -range; y < range+1; y++)
                    {
                        int theX = MathHelper.floor(player.posX+x);
                        int theY = MathHelper.floor(player.posY+y);
                        int theZ = MathHelper.floor(player.posZ+z);
                        
                        BlockPos posInQuestion = new BlockPos(theX, theY, theZ);
                        
                        BlockState blockstate = world.getBlockState(posInQuestion);
                        
                        if ((blockstate.getBlock() instanceof IGrowable))
                        {
                            IGrowable igrowable = (IGrowable)blockstate.getBlock();
                            
                            if((igrowable == Blocks.GRASS_BLOCK) ||
                            		(igrowable == Blocks.TALL_GRASS) ||
                            		(igrowable == Blocks.GRASS) ||
                            		(igrowable == Blocks.SUNFLOWER) || 
                            		(igrowable == Blocks.LILAC) || 
                            		(igrowable == Blocks.ROSE_BUSH) || 
                            		(igrowable == Blocks.PEONY) || 
                            		(igrowable == Blocks.SEAGRASS) ||
                            		(igrowable == Blocks.TALL_SEAGRASS))
                            {
                            	continue;
                            }
                            if (igrowable.canGrow(world, posInQuestion, blockstate, world.isRemote))
                            {
                                {
                                	if (!world.isRemote)
                                    {
                                		igrowable.grow(world, world.rand, posInQuestion, blockstate);
                                    }
                                }
                            }       
                        }
                    }
                }
            }
       }
    }
	
    @Override
	public void addInformation(ItemStack stack, World world, List<ITextComponent> list, ITooltipFlag flag)
	{
		super.addInformation(stack, world, list, flag);				
		list.add(new StringTextComponent("Works on: wheat, beetroot, carrot, potato, and tree saplings"));
		list.add(new StringTextComponent("Range: 14 blocks"));
		list.add(new StringTextComponent("Still a bit of a WIP"));
	}  
}

Oddly, the Sunflower, Lilac, Rose Buse, and Peony will constantly drop their ItemStack if I don't exclude them.

 

Can anyone provide some suggestions for writing a safe and proper timing method that can add a delay in the process?  I have seen reference to COOLDOWN in some of the minecraft references, is that a built-in method for that purpose?

 

Any guidance would be greatly appreciated.

 

Thank you and kind regards.

 

 

 

Link to comment
Share on other sites

3 hours ago, kwpugh said:

I have seen reference to COOLDOWN in some of the minecraft references, is that a built-in method for that purpose?

Corus fruit uses it. I believe it is an acceptable general use feature, yes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thank you for the suggestion, but frankly, I have  no idea what that means.  I'll do some research to see if I can figure it out.

 

Questions for clarification:

- by modulo, I presume you are talking about the remainder of the division of two numbers?

- the ticksExisted of the entity, where the "entity" is the plant or crop?

 

 

 

Link to comment
Share on other sites

17 hours ago, kwpugh said:

- by modulo, I presume you are talking about the remainder of the division of two numbers?

Yes. It is the % operator.

17 hours ago, kwpugh said:

- the ticksExisted of the entity, where the "entity" is the plant or crop?

Crops aren't entities, they're blocks. Plants are also crops and also blocks.

In this case you can use the Player as the entity in question.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thank you for the clarification.

 

I found these examples in the reference code, that seem to control the rate that natural regeneration occurs:

    if (this.getHealth() < this.getMaxHealth() && this.ticksExisted % 20 == 0) {
            this.heal(1.0F);
         }

         if (this.foodStats.needFood() && this.ticksExisted % 10 == 0) {
            this.foodStats.setFoodLevel(this.foodStats.getFoodLevel() + 1);
         }

What I do not understand from looking at this is "what is ticksExisted" containing?  Is this a continuing count of the # of ticks the player entity has existed or something else?

 

I see the ticksExisted is an int variable declared in Entiy.java, but I do not understand what it is storing.  

 

Regards.

Link to comment
Share on other sites

So, through a little "trial-n-error" I was able to get a delay working.

 

if (igrowable.canGrow(world, tagetPos, blockstate, world.isRemote))
                            {
                                {
                                	if (!world.isRemote)
                                    {
                                		 if (player.ticksExisted % 60 == 0) {
                                			 igrowable.grow(world, world.rand, tagetPos, blockstate);
                                		 }
                                    }
                                }
                            } 

A value of 60 goes much slower, smaller numbers make it faster.  

 

Since I do not know what the value is stored in ticksExisted, it could just be luck.   I still would like to understand what that variable contains and how it works.

 

Regards.

 

Link to comment
Share on other sites

ticksExisted is a field that stores the number of ticks the entity has existed. It's...pretty self-documenting.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
  • Topics

×
×
  • Create New...

Important Information

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