Posted August 11, 20169 yr Hi, I'm struggling with automated villager trading. I've extended GuiMerchant, added some buttons and now I'm implementing actual trading. Method that should do the trading is: void StartTrading() { IMerchant villager = getMerchant(); EntityPlayer player = villager.getCustomer(); MerchantRecipeList trades = villager.getRecipes(player); MerchantRecipe trade = trades.get(0); ItemStack input = trade.getItemToBuy(); ItemStack materials = getFirstAvailableItemStack(player, input); if(materials == null) return; ContainerMerchant merchant = ((ContainerMerchant)inventorySlots); merchant.getMerchantInventory().setInventorySlotContents(0, materials); inventorySlots.transferStackInSlot(player, 2); inventorySlots.transferStackInSlot(player, 0); } Method works as expected but as soon as I click on newly acquired emeralds, all changes are reverted. I assume I'm missing something but I can't find any tutorial that would address this problem. getFirstAvailableItemStack method in case you are interested: ItemStack getFirstAvailableItemStack(EntityPlayer player, ItemStack itemStack){ for(ItemStack stack:player.inventory.mainInventory){ if(stack != null){ if(stack.getItem().equals(itemStack.getItem())) return stack; } } return null; }
August 12, 20169 yr You sre handling the inventory on the clients s8de of things it needs to be handled server side, aince you are trying to make it only client side you should use some of the default packets if there are any. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 12, 20169 yr Author Yesterday I found a solution to this. I could either send appropriate packets to a server or I could simulate user clicks. I went for second option and it's as simple as handleMouseClick(slot30, slot30.slotNumber, 0, ClickType.PICKUP); handleMouseClick(slot30, slot30.slotNumber, 0, ClickType.PICKUP_ALL); handleMouseClick(slot0, slot0.slotNumber, 0, ClickType.PICKUP); handleMouseClick(slot2, slot2.slotNumber, 0, ClickType.QUICK_MOVE);
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.