Jump to content

[1.10.2] Eclipse error "The constructor ItemStack() is not visible"


Recommended Posts

Posted
Quote

package tortuga.primeiro.items;

import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import tortuga.primeiro.PrimeiroTab;
import tortuga.primeiro.init.ModItems;

public class ItemLightning extends ModItems {

    public ItemLightning(String name, PrimeiroTab tab, int size) {
          super(name, tab, size);
          
         
    }
    
     @Override
        public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        
         if(!worldIn.isRemote){
             RayTraceResult pos = playerIn.rayTrace(100, 20);
             
             double x = pos.getBlockPos().getX();
             double y = pos.getBlockPos().getY();
             double z = pos.getBlockPos().getZ();

             worldIn.addWeatherEffect(new EntityLightningBolt(worldIn, x, y, z, true));
        
        
         }
        
         return new ActionResult(EnumActionResult.SUCCESS, new ItemStack());
            
         
         {
                return new ActionResult(EnumActionResult.FAIL, new ItemStack());
            }

        

     }
     
     
}

I Couldn't solve this error, can anyone help me pls?

Posted (edited)

Look at the source for ItemStack, there is no constructor for it that takes no arguments. You must pass at least a block or item
 

You should return playerIn.getHeldItem(handIn)

Edited by Aarilight
Posted

onItemRightClick gives you a Hand, which probably holds a stack. I think you can operate upon the stack (e.g. decrement its count) and then return it. If count reaches zero, then you may return the empty stack.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
2 hours ago, jeffryfisher said:

onItemRightClick gives you a Hand, which probably holds a stack. I think you can operate upon the stack (e.g. decrement its count) and then return it. If count reaches zero, then you may return the empty stack.

 

An ItemStack with zero count is automatically empty; you don't need to return ItemStack.EMPTY.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.