Posted March 15, 20214 yr 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); }
March 15, 20214 yr So, you're holding `Item`s in a HashSet but the generic is just an Object? You are also checking if some ItemStack is contained in a set of `Item`s.
March 15, 20214 yr 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
March 15, 20214 yr 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?
March 15, 20214 yr 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?
March 15, 20214 yr 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
March 15, 20214 yr 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.
March 15, 20214 yr 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
March 15, 20214 yr 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.
March 15, 20214 yr Author as in: public static void main(String[] args) { getList(); } Edited March 15, 20214 yr by [email protected]
March 15, 20214 yr Author It works when i do if(player.inventory.getCurrentItem() == ItemInit.FLOUR.get()) though
March 15, 20214 yr 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
March 15, 20214 yr Author Lollypoplove08/1.16.4-Kitchen-Mod: A Kitchen Mod made by SantaPexie (github.com)
March 15, 20214 yr 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
March 15, 20214 yr 1 hour ago, [email protected] said: as in: public static void main(String[] args) { getList(); } Why do you have this? 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.