Posted February 4, 20232 yr So I want to create a delay in my method that destroys a block, waits for 20 ticks and then destroys the block below the destroyed one Thank you
February 4, 20232 yr My recommendation is to make a capability which you can start a timer for a given block and destroy it once that timer has finished. It would probably be a list which you can tick that holds the block position and then calls the destroy block method in the level once it finishes.
February 4, 20232 yr Author Just now, Rex_Technology said: Ok, thank you but how do I start the timer? And I should note I am a beginner
February 5, 20232 yr On 2/4/2023 at 9:52 AM, Rex_Technology said: Ok, thank you but how do I start the timer? By calling a method in the capability you make to start it? On 2/4/2023 at 9:58 AM, Rex_Technology said: And I should note I am a beginner Beginner in Java?
February 6, 20232 yr Author 23 hours ago, ChampionAsh5357 said: Beginner in Java? In java and in minecraft modding. I've learned java for minecraft modding.
February 6, 20232 yr I would suggest learning Java before modding. It's an absolutely terrible idea to learn it at the same time because Minecraft contains numerous bad practices and you are expected to have an intermediate level of Java knowledge beforehand since we do not explain Java concepts, only answer Minecraft related questions. It's like trying to run before figuring out how to stand.
February 15, 20232 yr Author I already learned java, I followed a java tutorial made by Kaupenjoe that is made for minecraft modding
February 15, 20232 yr 4 hours ago, Rex_Technology said: I already learned java, I followed a java tutorial made by Kaupenjoe that is made for minecraft modding Following a tutorial is not the same as learning a language, but your choice. Regardless, I gave the answer above, use a capability on the level and create a timer method to handle the destroying. If you are using a block entity to destroy the block, then use that instead of a capability on the level. There are docs, wikis, and tutorials on capabilities if you are unsure of their system.
February 15, 20232 yr 1 hour ago, perromercenary00 said: does a capabilities has an onTick() method You need to make your own capability, and you can give it whatever methods you want.
February 17, 20232 yr On 2/15/2023 at 12:36 PM, Alpvax said: You need to make your own capability, and you can give it whatever methods you want. well yes but not quite short ago i have to made a capability extending itemhandler to make a custome drill and i need to recalculate the value of tick to calculate animation frame and fuel comsumtion but i cannot make it so i end quickitng an made just a public int get_tick() { if( this.tick > 0) { } else if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 this.tick = (this.tick > this.limit)? this.limit : this.tick; } } return this.tick; } so everytime the code ask for that variable it recalculate it coze idont find any ontick() or public void tick() that works inside the capability Spoiler package merctool.item.tool; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.items.ItemStackHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /* helditem.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler00 -> { item_handler ih = (item_handler)handler00; System.out.println(warudo.isClientSide + " ih.fuel => " + ih.fuel ); }); */ public class item_handler extends ItemStackHandler { public ItemStack container = null; public float fuel = 0; public int munition = 0; public long start = 0; public int action = 0; public int tick = 0; public int limit = 1200; public item_handler(ItemStack container) { super(0); this.container = container; } public void print(String mensaje) { System.out.println("\n" + mensaje); System.out.println("this.fuel = " + this.fuel); System.out.println("this.munition = " + this.munition); System.out.println("this.start = " + this.start); System.out.println("this.action = " + this.action); System.out.println("this.tick = " + this.tick); System.out.println("this.limit = " + this.limit); System.out.println("\n"); } @Override public int getSlotLimit(int slot) { return 64; } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { if (stack == null || stack.isEmpty()) // || stack.getItem() instanceof BasketBlockItem { return false; } else { return super.isItemValid(slot, stack); } } @Override public void setStackInSlot(int slot, @NotNull ItemStack stack) { //// System.out.println("setStackInSlot(" + slot + ")"); validateSlotIndex(slot); this.stacks.set(slot, stack); onContentsChanged(slot); if (this.container != null) { // write_item_to_slot(this.container, slot, stack); } } // ########## ########## ########## ########## // @Override public static NonNullList<ItemStack> read_items_from(ItemStack itemstack) { NonNullList<ItemStack> contained_items = NonNullList.withSize(9, ItemStack.EMPTY);// this.getContainerSize() if (itemstack.hasTag()) { CompoundTag compoundtag = itemstack.getTag(); ListTag listtag = null; int size = 0; if (compoundtag.contains("Items")) { // ListTag listtag = new ListTag(); listtag = compoundtag.getList("Items", 10); size = listtag.size(); // contained_items = NonNullList.withSize(size, ItemStack.EMPTY); for (int i = 0; i < listtag.size(); ++i) { CompoundTag itemstacktag = listtag.getCompound(i); int j = compoundtag.getByte("Slot") & 255; if (j >= 0 && j < contained_items.size()) { contained_items.set(j, ItemStack.of(itemstacktag)); } } } } return contained_items; } // ########## ########## ########## ########## // @Override public void write_item_to_slot(ItemStack container, int slot, @NotNull ItemStack stack) { // , NonNullList<ItemStack> contained_items CompoundTag compoundtag = null; if (container.hasTag()) { compoundtag = container.getTag(); } else { compoundtag = new CompoundTag(); } ListTag listtag = null; if (compoundtag.contains("Items")) { listtag = compoundtag.getList("Items", 10); } else { listtag = new ListTag(); } CompoundTag itemstacktag = null; if (slot < listtag.size()) { itemstacktag = listtag.getCompound(slot); } else { itemstacktag = new CompoundTag(); } itemstacktag.putByte("Slot", (byte) slot); stack.save(itemstacktag); listtag.add(itemstacktag); // aqui tengi una duda, se sobreescrive o crea otra ?? compoundtag.put("Items", listtag); container.setTag(compoundtag); } @Override public CompoundTag serializeNBT() { ListTag nbtTagList = new ListTag(); for (int i = 0; i < stacks.size(); i++) { if (!stacks.get(i).isEmpty()) { CompoundTag itemTag = new CompoundTag(); itemTag.putInt("Slot", i); stacks.get(i).save(itemTag); nbtTagList.add(itemTag); } } CompoundTag nbt = new CompoundTag(); nbt.put("Items", nbtTagList); nbt.putInt("Size", stacks.size()); nbt.putInt("munition", this.munition); nbt.putFloat("fuel", this.fuel); nbt.putLong("start", this.start); nbt.putShort("action", (short) this.action); nbt.putShort("limit", (short) this.limit); this.tick = 0; //print("serializeNBT()"); return nbt; } @Override public void deserializeNBT(CompoundTag nbt) { setSize(nbt.contains("Size", Tag.TAG_INT) ? nbt.getInt("Size") : stacks.size()); ListTag tagList = nbt.getList("Items", Tag.TAG_COMPOUND); for (int i = 0; i < tagList.size(); i++) { CompoundTag itemTags = tagList.getCompound(i); int slot = itemTags.getInt("Slot"); if (slot >= 0 && slot < stacks.size()) { stacks.set(slot, ItemStack.of(itemTags)); } } this.munition = nbt.getInt("munition"); this.fuel = nbt.getFloat("fuel"); this.limit = nbt.getShort("limit"); this.start = nbt.getLong("start"); this.action = nbt.getShort("action"); //System.out.println( "DeserializeNBT()" ); //print("DeserializeNBT()"); onLoad(); } public void start(int action) { if ( this.action != action ) { this.action = action; this.start = System.currentTimeMillis(); // 50 this.tick = 0; } } public void stop() { this.action = 0; this.start = 0; // 50 this.tick = 0; this.limit = 1200; } public int get_tick() { if( this.tick > 0) { } else if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 = 20ticksxsecond this.tick = (this.tick > this.limit)? this.limit : this.tick; } } return this.tick; } }
February 18, 20232 yr On 2/17/2023 at 9:08 AM, perromercenary00 said: well yes but not quite short ago i have to made a capability extending itemhandler to make a custome drill and i need to recalculate the value of tick to calculate animation frame and fuel comsumtion but i cannot make it Animation frame rendering can be lerped using the current tick data and the previous tick data. So, there's no 'not quite'. You can make an method and implement it like any other method in java.
February 21, 20232 yr oo that when i made the animations using the tick provided by onUseTick causes chopping animations when the game start skiping frames an sometimes the animation locks in a cicle and dont let the item continue whit is normal use then i just begin to store the statr time as epoch and calculate the frame from it and fix the problem
February 21, 20232 yr 12 hours ago, perromercenary00 said: then i just begin to store the statr time as epoch and calculate the frame from it and fix the problem Ok, so you're just calculating partial tick yourself instead of using the one provided by vanilla.
February 22, 20232 yr if theres is a work around to make the logic inside the capability it would make things easier i try puting and onload method and launchi it from Spoiler @Override public CompoundTag serializeNBT() { ListTag nbtTagList = new ListTag(); for (int i = 0; i < stacks.size(); i++) { if (!stacks.get(i).isEmpty()) { CompoundTag itemTag = new CompoundTag(); itemTag.putInt("Slot", i); stacks.get(i).save(itemTag); nbtTagList.add(itemTag); } } CompoundTag nbt = new CompoundTag(); nbt.put("Items", nbtTagList); nbt.putInt("Size", stacks.size()); nbt.putInt("munition", this.munition); nbt.putFloat("fuel", this.fuel); nbt.putLong("start", this.start); nbt.putShort("action", (short) this.action); nbt.putShort("limit", (short) this.limit); this.tick = 0; //print("serializeNBT()"); onSave(); return nbt; } //@Override protected void onSave() { //System.out.println("item_handler __ onSave() "); if(this.action > 0) { //this.tick = get_tick(); if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 this.tick = (this.tick > this.limit)? this.limit : this.tick; } } } System.out.println("item_handler __ onSave() " + this.tick ); } i notice this methods ticks for a while afther you read the capability from the item and lives while the item is in the hotbar but if you put it on the inventory and close the menu it dies so is not is not reliable becoze it only ticks a few times and stop so is unfited to make a long count and do something after like finishing the drilling action and consume the fuel value saving the numbers back to item the other option would be to call the capability once and again from the itemstack in older version there was a onupdate() method that constantly tick even when you toss the item into the world i dot find it in 1.19.2 surely the name has change
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.