[email protected] Posted March 15, 2021 Posted March 15, 2021 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); } Quote
ChampionAsh5357 Posted March 15, 2021 Posted March 15, 2021 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. Quote
[email protected] Posted March 15, 2021 Author Posted March 15, 2021 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 Quote
[email protected] Posted March 15, 2021 Author Posted March 15, 2021 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? Quote
ChampionAsh5357 Posted March 15, 2021 Posted March 15, 2021 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? Quote
[email protected] Posted March 15, 2021 Author Posted March 15, 2021 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 Quote
ChampionAsh5357 Posted March 15, 2021 Posted March 15, 2021 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. Quote
[email protected] Posted March 15, 2021 Author Posted March 15, 2021 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 Quote
Draco18s Posted March 15, 2021 Posted March 15, 2021 Do you ever call getList()? Quote 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.
[email protected] Posted March 15, 2021 Author Posted March 15, 2021 (edited) as in: public static void main(String[] args) { getList(); } Edited March 15, 2021 by [email protected] Quote
kiou.23 Posted March 15, 2021 Posted March 15, 2021 Just now, [email protected] said: i dont think so ... so what do you expect?? Quote
[email protected] Posted March 15, 2021 Author Posted March 15, 2021 It works when i do if(player.inventory.getCurrentItem() == ItemInit.FLOUR.get()) though Quote
kiou.23 Posted March 15, 2021 Posted March 15, 2021 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 Quote
[email protected] Posted March 15, 2021 Author Posted March 15, 2021 Lollypoplove08/1.16.4-Kitchen-Mod: A Kitchen Mod made by SantaPexie (github.com) Quote
kiou.23 Posted March 15, 2021 Posted March 15, 2021 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 Quote
Draco18s Posted March 15, 2021 Posted March 15, 2021 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. Quote 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.
Recommended Posts
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.