Jump to content

Recommended Posts

Posted

I'm a beginner of Modding, and I'm really confusing about how to get a playerEntity

here is my code

PlayerEntity player = [???]

@Override public ItemStack getContainerItem(ItemStack itemStack) { itemStack.damageItem(1,player,null); return new ItemStack(Items.BUCKET); }

 

what should I enter in the [???],I used to enter Minecraft.getInstance().player; but the game crushed because of null pointer

Posted
53 minutes ago, middangeardim said:

I'm a beginner of Modding, and I'm really confusing about how to get a playerEntity

here is my code

PlayerEntity player = [???]

@Override public ItemStack getContainerItem(ItemStack itemStack) { itemStack.damageItem(1,player,null); return new ItemStack(Items.BUCKET); }

 

what should I enter in the [???],I used to enter Minecraft.getInstance().player; but the game crushed because of null pointer

Show the whole code or none can help

Posted
4 minutes ago, eggpasta said:

Show the whole code or none can help

sorry about that.

I want to make a item which will damage when reciping

public class carrot_jam extends TieredItem {

    public carrot_jam() {
        super(ModItemTier.PUMPKINS,new Item.Properties().group(ModGroup.toolsGroup));
        this.getItemStackTileEntityRenderer()
    }
    

    @Override
    public boolean hasContainerItem(ItemStack itemStack) {
        return true;
    }
    
//here is the problem
    @Override
    public ItemStack getContainerItem(ItemStack itemStack) {
        itemStack.damageItem(1,player,null);
        return new ItemStack(Items.BUCKET);
    }

}

 

Posted
3 minutes ago, middangeardim said:

sorry about that.

I want to make a item which will damage when reciping


public class carrot_jam extends TieredItem {

    public carrot_jam() {
        super(ModItemTier.PUMPKINS,new Item.Properties().group(ModGroup.toolsGroup));
        this.getItemStackTileEntityRenderer()
    }
    

    @Override
    public boolean hasContainerItem(ItemStack itemStack) {
        return true;
    }
    
//here is the problem
    @Override
    public ItemStack getContainerItem(ItemStack itemStack) {
        itemStack.damageItem(1,player,null);
        return new ItemStack(Items.BUCKET);
    }

}
 

 

So you want them to get damaged when they craft it ?

if so override

 public void onCraftedBy(ItemStack p_77622_1_, World p_77622_2_, PlayerEntity p_77622_3_) {
   }

 

Posted
9 minutes ago, middangeardim said:

 


itemStack.damageItem(1,player,null);
return new ItemStack(Items.BUCKET);

 

This does not really make sense as you are damaging the carrot jam stack, and then replace it with a bucket in the crafting table.

Posted
7 minutes ago, eggpasta said:

So you want them to get damaged when they craft it ?

if so override


 public void onCraftedBy(ItemStack p_77622_1_, World p_77622_2_, PlayerEntity p_77622_3_) {
   }

 

no I mean, I want use this item to recipe another thing, and when recipe success,this item will reduce 1 durablity

Posted
3 minutes ago, poopoodice said:

This does not really make sense as you are damaging the carrot jam stack, and then replace it with a bucket in the crafting table.

well...I want to return a bucket after the carrot jam used up, need I add an "if" to check whether the item was used up? Which method should I use to check?

Posted
49 minutes ago, middangeardim said:

no I mean, I want use this item to recipe another thing, and when recipe success,this item will reduce 1 durablity

So you don't want to get the playerEntity?

Posted
47 minutes ago, middangeardim said:

well...I want to return a bucket after the carrot jam used up, need I add an "if" to check whether the item was used up? Which method should I use to check?

So you want to use an Item(Carrot Jam) In a crafting recipe and then it loses 1 durability?

If so what is the crafting recipe?

and you would have to add the carrot jam to the players inventory because a vanilla crafting recipe can't return 2 items

Posted
2 minutes ago, eggpasta said:

So you want to use an Item(Carrot Jam) In a crafting recipe and then it loses 1 durability?

If so what is the crafting recipe?

and you would have to add the carrot jam to the players inventory because a vanilla crafting recipe can't return 2 items

for example,the recipe is carrot jam + bread = carrot jam bread

it will recipe a carrot jam bread and return me a carrot jam which reduce 1 reduablity

I need to use itemStack.damageItem(count,LivingEntity,null) to do it,but i have no idea how to get a playerEntity in this method

Posted (edited)
1 hour ago, middangeardim said:

sorry about that.

I want to make a item which will damage when reciping



public class carrot_jam extends TieredItem {

    public carrot_jam() {
        super(ModItemTier.PUMPKINS,new Item.Properties().group(ModGroup.toolsGroup));
        this.getItemStackTileEntityRenderer()
    }
    

    @Override
    public boolean hasContainerItem(ItemStack itemStack) {
        return true;
    }
    
//here is the problem
    @Override
    public ItemStack getContainerItem(ItemStack itemStack) {
        itemStack.damageItem(1,player,null);
        return new ItemStack(Items.BUCKET);
    }

}
 

 

You would want to set a default durability for the item(amount of uses) and also have you tried using null in the place of player you could try :

        @Override
        public ItemStack getContainerItem(ItemStack itemStack) {
            itemStack.getItem().damageItem(itemStack, 1, null,null)
            return new ItemStack(Items.BUCKET);
        }

Or try what poopoodice just suggested

Edited by eggpasta
IncorrectCode
Posted (edited)
43 minutes ago, eggpasta said:

You would want to set a default durability for the item(amount of uses) and also have you tried using null in the place of player you could try :



        @Override
        public ItemStack getContainerItem(ItemStack itemStack) {
            itemStack.getItem().damageItem(itemStack, 1, null,null)
            return new ItemStack(Items.BUCKET);
        }

Or try what poopoodice just suggested

well....it doesn't work,but I success finally using the setDamge(),here is the final code

    @Override
    public ItemStack getContainerItem(ItemStack itemStack) {

        if(itemStack.getDamage() < itemStack.getMaxDamage()){
            ItemStack item = itemStack.copy();
            item.setDamage(item.getDamage() + 1);
            return item;
        }

        return new ItemStack(Items.BUCKET);
    }

 

by the way, thank you very much, both you and poopoodice😀

Edited by middangeardim
Posted

This does, of course, ignore the Unbreaking enchantment if your item is allowed to have it.

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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.