Jump to content

Recommended Posts

Posted

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);
}

 

Posted
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?

 

Posted

A good way to do it would be to make the entire thing data driven and pull the data from there; however, it's better to have it working. Just create the set or map like normal and populate it. Do not copy vanilla with the decompiler artifacts. What are you attempting to do?

Posted

I have a block (bowl) that when you right click it with certain items (ItemInit.FLOUR, Items.EGG) it changes model but i cant figure out how to actually make code continue when you right clicked it with the certain items, i could manually do each one but i want a list or smth to make it easier

Posted
if (canMix.contains(itemstack.getItem())) {
					player.getHeldItemMainhand().shrink(1);
				}

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


	public static HashSet<Item> getList() {
		canMix.add(ItemInit.FLOUR.get());
		return canMix;
	}

why wont that work

 

Posted

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.

Posted

getList() is never getting called. And shouldn't be adding the values to the hashSet in getter.

add the values inside the block constructor, and in the getter just return your canMix

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

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.