Tutorials-By-Kaupenjoe / Forge-Tutorial-1.20.X

Repository for my Forge 1.20.X Tutorial Series on YouTube. Playlist link below!
https://www.youtube.com/playlist?list=PLKGarocXCE1H9Y21-pxjt5Pt8bW14twa-
MIT License
113 stars 30 forks source link

Item that is not Consumed while Crafting #2

Open oOJoshOo opened 10 months ago

oOJoshOo commented 10 months ago

Hey,

could you make an Tutorial wich shows how to make an Item that will not be consumed when you craft with it. Or uses Durebility at Crafting?

Like a Chissle that can cave some Stone and will not Break.

Thank You

zenteno125 commented 10 months ago

I haven't tested it, but you could create a 'generic class' to make non-consumable items. Extend it from Item and implement the logic you desire within the method that returns the item to your hand once crafted. That way, it won't technically be consumed; it will be returned back to you. example: public class UnconsumableItem extends Item { public UnconsumableItem(Properties properties) { super(properties); }

@Override
public InteractionResultHolder<ItemStack> useOn(UseOnContext context) {
    // Your crafting logic here
    // For example, you can check if it's being used on a crafting table and create the desired output

    return InteractionResultHolder.success(context.getItemInHand());
}

} att: It's an example, you can get the idea of the class from that, but that code isn't functional (I think).

drkhodakarami commented 10 months ago

that may not be useful for all conditions, think about industrial BE, you may want to use tools inside the machine (like cutter or casts or other items) they are part of a recipe for BE but still won't be consumed or damaged. There is old fashion way of handling each recipe in code, that is true, but I think there should be a way to use json for these conditions?

Unknown303YT commented 5 months ago

You could take a look at the Item.Properties class, and try and work off of the craftRemainder method. It would be different in several ways, but it could work. Anytime I want to do something there is no tutorial for, I just look at vanilla and what other people have said, and modify it to my needs.

Unknown303YT commented 1 month ago

@oOJoshOo What you could do is making a craftremainder that somehow is the same item but as a ItemStack that has less durability. I'm not sure though. You might have to improvise.