Jump to content

Trying to look for a hashset list in player.inventory.getCurrentItem()


rafferty.smith@hotmail.com

Recommended Posts

Im not sure why this is not working and i would appricate any help. I want (like a composter) for items in a hashset or a list to do .contains(player.inventory.getCurrentItem()) so the code will only run when you are holding the certain tems. My code so far is this:

 

private static HashSet<Object> canMix = new HashSet<Object>();

	public static HashSet<Object> getList() {
		canMix.add(ItemInit.FLOUR.get());
		canMix.add(Items.ACACIA_BOAT);
		return canMix;
	}
@SuppressWarnings("deprecation")
	@Override
	public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player,
			Hand handIn, BlockRayTraceResult hit) {
		
		if(handIn.MAIN_HAND == handIn) {
		if(!worldIn.isRemote) {
			if (player.inventory.getCurrentItem() != null) {
				if (canMix.contains(player.inventory.getCurrentItem())) {
					player.getHeldItemMainhand().shrink(1);
				}
			      }
	    		else {
	    			return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
	    		}
	    	}
			return ActionResultType.SUCCESS;
		}
		return super.onBlockActivated(state,worldIn,pos,player,handIn,hit);
}

 

Link to comment
Share on other sites

public static void init() {
      CHANCES.defaultReturnValue(-1.0F);
      float f = 0.3F;
      float f1 = 0.5F;
      float f2 = 0.65F;
      float f3 = 0.85F;
      float f4 = 1.0F;
      registerCompostable(0.3F, Items.JUNGLE_LEAVES);
      registerCompostable(0.3F, Items.OAK_LEAVES);
      registerCompostable(0.3F, Items.SPRUCE_LEAVES);
   }

   private static void registerCompostable(float chance, IItemProvider itemIn) {
      CHANCES.put(itemIn.asItem(), chance);
   }
public static final Object2FloatMap<IItemProvider> CHANCES = new Object2FloatOpenHashMap<>();

Looking trough the composter class i found this. Is that a good way to do it?

 

Link to comment
Share on other sites

Do you ever call getList()?

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

1 hour ago, [email protected] said:

as in:

 

public static void main(String[] args) {
        getList();
    }

Why do you have this? :D

Your class isn't the one being called by the JVM.

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

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.



×
×
  • Create New...

Important Information

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