Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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?

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

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.