Dread_Boy Posted August 11, 2016 Posted August 11, 2016 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; } Quote
Animefan8888 Posted August 12, 2016 Posted August 12, 2016 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. Quote 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.
Dread_Boy Posted August 12, 2016 Author Posted August 12, 2016 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); Quote
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.