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.

Featured Replies

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

 

  • Author

I was changing the <object> thing around like an IItemProvider and a <Item> the error saying unlikely argument types came up but im not sure how i would fix it in theis case

  • Author
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?

 

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?

  • Author

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

So then create a Set of items that can be added to the bowl and then check if the bowl contains the item being clicked on it. You can use ItemStack#getItem to get the item from the hand to check.

  • Author
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

 

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.

1 minute ago, [email protected] said:

It works when i do if(player.inventory.getCurrentItem() == ItemInit.FLOUR.get()) though

can you post more of your code? a repository on github would be the best

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

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

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.