IamP Posted August 11, 2021 Share Posted August 11, 2021 (edited) this is my code @SubscribeEvent public void checkItem(BlockEvent.EntityPlaceEvent event) { if (!event.getWorld().isRemote()) { if (event.getEntity() instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) event.getEntity(); Hand hand = player.getActiveHand(); ItemStack stack = player.getHeldItem(hand); System.out.println(stack); if (stack.getCount() == 1) { System.out.println(stack); int i = this.findItem(player, stack.getItem().getItem()); if (i != -1) { ItemStack item = player.inventory.mainInventory.get(i); player.inventory.mainInventory.set(i, ItemStack.EMPTY); player.setHeldItem(hand, item); System.out.println(stack + " 1"); } } } } } public int findItem(PlayerEntity player, Item item) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) { ItemStack stack = player.inventory.mainInventory.get(i); if (!stack.isEmpty() && stack.getItem().getItem() == item) { return i; } } return -1; } Edited August 17, 2021 by IamP syntax highlighting Quote Link to comment Share on other sites More sharing options...
diesieben07 Posted August 11, 2021 Share Posted August 11, 2021 Define "does not work". Have you used the debugger? My suspicion is that your code finds the item itself and then tries to replace it with itself. Quote Link to comment Share on other sites More sharing options...
IamP Posted August 12, 2021 Author Share Posted August 12, 2021 Thanks for your recommendation Quote Link to comment Share on other sites More sharing options...
IamP Posted August 12, 2021 Author Share Posted August 12, 2021 It's work now. Quote Link to comment Share on other sites More sharing options...
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.