Jump to content

Recommended Posts

Posted

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.

 

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

Posted

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?

 

 

Posted

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.

Posted

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.

 

 

 

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

Posted

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?

 

 

 

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

Posted

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.

Posted

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.

 

Posted

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.

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



×
×
  • Create New...

Important Information

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