kwpugh Posted June 28, 2019 Posted June 28, 2019 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. Quote
Draco18s Posted June 28, 2019 Posted June 28, 2019 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! Open a 1.12 workspace (this is why you use a separate workspace to update, by the way) Browse to FooClass.BarMethod Use your IDE's find usages tool to see where it was called from in vanilla Pick a call site Go to that same call site in 1.13/1.14 What does it call instead? Profit (if these steps don't apply, then you're allowed to ask) 1 1 Quote 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.
kwpugh Posted June 28, 2019 Author Posted June 28, 2019 Not sure, but is this what you mean by finding usages? Quote
kwpugh Posted June 29, 2019 Author Posted June 29, 2019 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? Quote
Draco18s Posted June 29, 2019 Posted June 29, 2019 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? Quote 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.
kwpugh Posted June 30, 2019 Author Posted June 30, 2019 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. Quote
Draco18s Posted June 30, 2019 Posted June 30, 2019 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. Quote 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.
Alekseyev Posted July 1, 2019 Posted July 1, 2019 You could also have the inventoryTick function check the modulo of ticksExisted of the entity so that the rest of the code only fires every x ticks. Quote
kwpugh Posted July 1, 2019 Author Posted July 1, 2019 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? Quote
Draco18s Posted July 2, 2019 Posted July 2, 2019 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. Quote 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.
kwpugh Posted July 2, 2019 Author Posted July 2, 2019 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. Quote
kwpugh Posted July 2, 2019 Author Posted July 2, 2019 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. Quote
Draco18s Posted July 2, 2019 Posted July 2, 2019 ticksExisted is a field that stores the number of ticks the entity has existed. It's...pretty self-documenting. Quote 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.
Alekseyev Posted July 3, 2019 Posted July 3, 2019 Which would be +20 ticks per second if your game runs at full speed, and less if the processor can't keep up with all the things it has to compute. Quote
Recommended Posts
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.