Posted February 8, 20232 yr Good days sorry is hard to express compex ideas in a non native languague i been working in a drill and i need this drill needs to have two animation the one is just the drill spining and drilling that one is on right clickand works holding right click anyway to switch the json models and the animation i need to read the values from the capability in the ModItemModelProperties thats an issue i having know i dont know how to get the capability thing to read the values soo i just have his bunch of debris code Spoiler // #########################################################################3 // ###### ###### ###### ###### ###### ###### public static void make_drill_drill(Item drill) { ItemProperties.register(drill, new ResourceLocation("pull"), (itemstack, warudo, le, p_174638_) -> { // do nothing if (le == null) { return 0; } // do nothing if (le.getUseItem() != itemstack) { return 0F; } int ticks = 0; /* ticks = ( itemstack.getUseDuration() - le.getUseItemRemainingTicks() ); ticks = (ticks > 15 )? 15 : ticks;//max itemstack.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler00 -> { if (handler00 instanceof item_handler) { item_handler ih = (item_handler) handler00; int tick = ((( ih.get_tick() ) % 4) + 1) ; } }); */ item_handler ih = new item_handler(itemstack); System.out.println("make_drill_drill() action => " + ih.action + ", " + ih.get_tick()); // + ticks = ((( ih.get_tick() ) % 4) + 1) ; //Capability<IItemHandler> ih = CapabilityManager.get(new CapabilityToken<>(){}); return ticks; }); // si esta holding right click devuelve 1.0F ItemProperties.register(drill, new ResourceLocation("pulling"), (itemstack, warudo, le, p_174638_) -> { return (le != null && le.getUseItem() == itemstack) ? 1.0F : 0.0F; }); } this is mi capability Spoiler package merctool.item.taladro; 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 (action != this.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; } 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; } } exactly i need to get the output from the method public int get_tick() to use thnks for your time
February 9, 20232 yr Author lets try again the drill has two animations and to play this two animations i beign using the same technich used to animate the bow or the shield Spoiler { "overrides": [ { "predicate": { "pull": 0 }, "model": "merctool:item/taladro/taladro00" }, { "predicate": { "pull": 1 }, "model": "merctool:item/taladro/taladro01" }, { "predicate": { "pull": 2 }, "model": "merctool:item/taladro/taladro02" }, { "predicate": { "pull": 3 }, "model": "merctool:item/taladro/taladro03" }, { "predicate": { "pull": 4 }, "model": "merctool:item/taladro/taladro04" }, { "predicate": { "pull": 20 }, "model": "merctool:item/taladro/taladro00" }, { "predicate": { "pull": 21 }, "model": "merctool:item/taladro/taladro_load_00" }, { "predicate": { "pull": 22 }, "model": "merctool:item/taladro/taladro_load_01" }, { "predicate": { "pull": 23 }, "model": "merctool:item/taladro/taladro_load_02" }, { "predicate": { "pull": 24 }, "model": "merctool:item/taladro/taladro_load_03" }, { "predicate": { "pull": 25 }, "model": "merctool:item/taladro/taladro_load_00" }, { "predicate": { "pull": 26 }, "model": "merctool:item/taladro/taladro_load_04" }, { "predicate": { "pull": 27 }, "model": "merctool:item/taladro/taladro_load_05" }, { "predicate": { "pull": 28 }, "model": "merctool:item/taladro/taladro_load_06" }, { "predicate": { "pull": 29 }, "model": "merctool:item/taladro/taladro_load_07" }, { "predicate": { "pull": 30 }, "model": "merctool:item/taladro/taladro_load_08" }, { "predicate": { "pull": 31 }, "model": "merctool:item/taladro/taladro_load_09" }, { "predicate": { "pull": 32 }, "model": "merctool:item/taladro/taladro_load_10" }, { "predicate": { "pull": 33 }, "model": "merctool:item/taladro/taladro_load_11" }, { "predicate": { "pull": 34 }, "model": "merctool:item/taladro/taladro_load_12" }, { "predicate": { "pull": 35 }, "model": "merctool:item/taladro/taladro_load_13" }, { "predicate": { "pull": 36 }, "model": "merctool:item/taladro/taladro_load_14" }, { "predicate": { "pull": 37 }, "model": "merctool:item/taladro/taladro_load_15" } ] } now this json works whit a property called "pull" and i have to declare it to the drill item and pass the values from the item handler capability to this ItemModelProperties notive than to determine what animation gonna be played i use the variable called "action" from the capability Spoiler package merctool.item.taladro; 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 (action != this.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; } 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; } } ######################### then it comes the problem the code i have to read from the itemcpability is an enclosed arrow function this is not a problem if just need to read or change some value then return but becoze ItemModelProperties is also an arrow function it dont letme just return the calculate value //register the pull property Spoiler ItemProperties.register(drill, new ResourceLocation("pull"), (itemstack, warudo, le, p_174638_) -> { itemstack.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler00 -> { if (handler00 instanceof item_handler) { item_handler ih = (item_handler) handler00; System.out.println("ItemProperties() action => " + ih.action + ", " + ih.get_tick()); int tick = 0; //drill if(ih.action == 1) { tick = ((ih.get_tick() % 4) + 1); } //load redstone if(ih.action == 2) { tick = (ih.get_tick() + 20); tick = (tick > 40)? 40 : tick; } return tick; //this is not allow coze arrow function can only return lazy optional, not int } }); }); ItemProperties() action => 1, 0 ItemProperties() action => 1, 1 ItemProperties() action => 1, 2 ItemProperties() action => 1, 3 ItemProperties() action => 1, 4 ItemProperties() action => 1, 5 soo i need to pull out the capability not as an arrow but as normal class/object soo i can just return the tick value thats the problem i currently have @NotNull LazyOptional<IItemHandler> handler00 = itemstack.getCapability(ForgeCapabilities.ITEM_HANDLER); //item_handler ih = (item_handler) handler00;//Cannot cast from LazyOptional<IItemHandler> to item_handler if (handler00 instanceof item_handler) { item_handler ih = (item_handler) handler00; //how i do cast from lazyoptional to mi capability class ???? } Edited February 9, 20232 yr by perromercenary00
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.