Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[FIXED] [1.14.4] How to make item stay in the crafting grid?


Xander402
 Share

Recommended Posts

I know what a containerItem is, but can this field be somehow utilized in order to make the item stay in the crafting grid? It's not about returning some empty bottle from recipe that requires a bottled substance. It's about a knife staying untouched after crafting something with it.

I tried two things:

package ...

import ...

public class UtilityItem extends Item {

    public UtilityItem(Properties p_i48487_1_) {
        super(p_i48487_1_);
    }

    @Override
    public ItemStack getContainerItem(ItemStack itemStack) {
        return new ItemStack(this);
    }
}

with regular initialization, and

    // In item init
    public static Item knife = new Item(new Item.Properties().group(SushiMod.TOOLS_GROUP)).setRegistryName(rloc("knife"));
    static {
        knife = new Item(new Item.Properties()
                .containerItem(knife)
                .group(SushiMod.TOOLS_GROUP)).setRegistryName(rloc("knife"));
    }

...which I actually didn't think through. The first had no effect and the second made the knife turn into a purple-black-checked block.minecraft.air item after crafting.

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to comment
Share on other sites

Some mods apply damage to a tool item when it's used to craft something. That suggests me that I'd need to use something different than containerItem. But what?

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to comment
Share on other sites

7 hours ago, Xander402 said:

getContainerItem

Overriding this has no effect if you do not also override hasContainerItem.

 

The 2nd makes zero sense:

  • Don't create items in a static initializer.
  • You assign a value to the knife field, only to immediately overwrite it... with an almost identical value.
  • It's unknown if you register this Item anywhere, probably you didn't, which is why it did not work. All Items must be created and registered in the appropriate registry events.
  • Thanks 1
Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

The 2nd makes zero sense:

  • Don't create items in a static initializer.
  • You assign a value to the knife field, only to immediately overwrite it... with an almost identical value.
  • It's unknown if you register this Item anywhere, probably you didn't, which is why it did not work. All Items must be created and registered in the appropriate registry events.

Yes, I know it's stupid. ? I was aware of this when writing that post.

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to comment
Share on other sites

Oh, well,

Quote

That suggests me that I'd need to use something different than containerItem. 

I was wrong.

11 minutes ago, diesieben07 said:
7 hours ago, Xander402 said:

getContainerItem

Overriding this has no effect if you do not also override hasContainerItem.

That makes sense. The item stays in crafting table after overriding hasContainerItem. Thanks!

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to comment
Share on other sites

2 hours ago, Xander402 said:

Some mods apply damage to a tool item when it's used to craft something.

For somebody who would like to know how to do it, here's my solution:
 

import net.minecraft.item.IItemTier;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;

public class KnifeItem extends SwordItem {

    public KnifeItem(IItemTier p_i48460_1_, int p_i48460_2_, float p_i48460_3_, Properties p_i48460_4_) {
        super(p_i48460_1_, p_i48460_2_, p_i48460_3_, p_i48460_4_);
    }

    @Override
    public boolean hasContainerItem(ItemStack stack) {
        return true;
    }

    @Override
    public ItemStack getContainerItem(ItemStack itemStack) {
        ItemStack ret = new ItemStack(this);
        ret.setDamage(itemStack.getDamage() + 1);
        return ret;
    }
}

 

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to comment
Share on other sites

3 hours ago, Xander402 said:

ret.setDamage(itemStack.getDamage() + 1);

You should use the tryDamageItem() method(s) instead so that your knife can take (and be affected by) the Unbreaking enchantment.

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

Link to comment
Share on other sites

Yeah, you're right. I totally didn't think about Unbreaking, because this knife is intended to be just a kitchen tool. Although I'm not gonna take away a possibility to use this item as a full-fledged weapon.
Just it is
attemptDamageItem(), not tryDamageItem().

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to comment
Share on other sites

5 hours ago, Xander402 said:

attemptDamageItem

That's the one. There's a dozen dozen dozen methods that have had their names changed and I can't remember exactly the right thing.

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.

Link to comment
Share on other sites

Yes, I know that. ? I don't blame you. I've been playing around with modding, adding some basic items and blocks ever since 1.9, and I had to deal with all the changes (not only in naming), too.

Quote

Just it is attemptDamageItem(), not tryDamageItem().

That's just for people who would potentially come to this post not willing to do research and expecting everything to be expounded exactly as it is.

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Link to comment
Share on other sites

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • can someone tell me what is messing up my minecraft??? I have been trying the half and half method for hrs and I can't seem to fine the culprit. Here is my latest crash report: 02:09:39.174 game at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) 02:09:39.174 game at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) 02:09:39.174 game at java.base/java.lang.Thread.run(Thread.java:833) 02:09:39.174 game Caused by: org.spongepowered.asm.mixin.throwables.ClassMetadataNotFoundException: com.simibubi.create.repack.registrate.util.entry.BlockEntry 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.transformMethod(MixinPreProcessorStandard.java:754) 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.transform(MixinPreProcessorStandard.java:739) 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.attach(MixinPreProcessorStandard.java:310) 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.createContextFor(MixinPreProcessorStandard.java:280) 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinInfo.createContextFor(MixinInfo.java:1288) 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:292) 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.TargetClassContext.apply(TargetClassContext.java:383) 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:365) 02:09:39.174 game at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363) 02:09:39.174 game ... 34 more 02:09:39.778 monitor Process Monitor Process crashed with exit code 1
    • https://myfemalefunda.com/الساعة-الان-في-المكسيك/ https://myfemalefunda.com/معلومات-عن-شي-ان/ https://kerbymethodconsulting.com/مستقبل-الطاقة-فى-مصر-95969/ https://sanakanwalfashion.com/وظائف-مصنع-ابو-هشيمة/ https://enjazalkhaleej.com/اسعار-دولار-مقابل-يورو/
    • https://enjazalkhaleej.com/رقم-شركة-ابل-في-مصر/ https://enjazalkhaleej.com/كيف-يتم-تحديد-قيمة-العملة/ https://diamonds.tokyo/بحث-عن-مشكلة-الكهرباء-وحلها/ https://enjazalkhaleej.com/ما-هو-خام-البليت/ https://myfemalefunda.com/تحويل-العمله-من-ريال-سعودي-الى-ريال-عما/
    • https://kerbymethodconsulting.com/بيع-وشراء-وادي-سوف-49397/ https://myfemalefunda.com/عملة-اليورو-اي-دولة/ https://angosiam.com/سعر-عملة-داج-كوين/ https://angosiam.com/100-دولار-كم-ليره/ https://advocatesnairobi.com/جورج-السادس-ملك-المملكة-المتحدة/
    • https://advocatesnairobi.com/هل-العملات-الرقمية-حلال/ https://sanakanwalfashion.com/عروض-البلاك-فرايدي-2022/ https://advocatesnairobi.com/سعر-الدينار-الليبي-اليوم-في-مصر/ https://starsone.site/اسعار-العملات-اليوم-فى-قطر/ https://angosiam.com/تحويل-بتكوين-الى-دولار/
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.