Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;
    }

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.

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.