Jump to content

Recommended Posts

Posted (edited)

Hi, I'm trying to make a mod in which when you do some action (havent decided yet) it will refresh the current merchant trades into other basic merchant trades (Rather than break the workstation and replace it, I would rather just be able to hit a button/interact with specific item and the trades would refresh). This is what I have so far, 

@SubscribeEvent
public static void villagerRefresh(EntityInteractSpecific event) {
	LivingEntity targetEntity = (LivingEntity) event.getTarget();
	PlayerEntity playerEntity = event.getPlayer();

	if (targetEntity instanceof VillagerEntity) {
		VillagerEntity villagerEntity = (VillagerEntity) targetEntity;
		MerchantOffers offers = villagerEntity.getOffers();
		MerchantOffers newOffers = new MerchantOffers(offers.write());

		if (playerEntity.getHeldItem(event.getHand()).getItem() == Items.STICK.getItem()) {
			VillagerEntity.setOffers(newOffers);
		}
	}
}

With some testing I can confirm that it does enter the second if statement, but I can't actually set the new trades. Any help would be greatly appreciated :)

Edited by HutchCS
Added version
  • HutchCS changed the title to [1.16.4] Refreshing Villager Trades
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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