Jump to content

[1.16.5] edit Villager MerchantOffers when right clicked


Recommended Posts

Posted (edited)

I just want to change the villager MerchantOffers when rightclickt with a custom item.

So i creat this the offer will set but when i close the gui and open it again the offers will reset but why

have i to save them? or is there something wrong/is there a better way to do this?

 

	@SubscribeEvent
	public static void EntityInteractSpecific(PlayerInteractEvent.EntityInteractSpecific event) {
		
		PlayerEntity player = event.getPlayer();
		LivingEntity target = (LivingEntity) event.getTarget();
		World world = event.getWorld();
		
		if (target instanceof VillagerEntity) {
			
			VillagerEntity villager = (VillagerEntity) target;
			MerchantOffers offers = villager.getOffers();
			MerchantOffers newOffers = new MerchantOffers(offers.write());
			String uuid = villager.getUniqueID().toString().replace("-", "");
			int uniqueInteger = Integer.parseInt(uniqueHex(uuid, 2), 16) / 10;
			player.sendMessage(new StringTextComponent("uniqueInteger: " + uniqueInteger), player.getUniqueID());
			
			if (world.getDayTime() >= 3000 && world.getDayTime() <= 10000) {
				
				for (MerchantOffer merchantOffer : offers) {
					
					merchantOffer.resetUses();
					
				}
				
			}
			
			if (player.getHeldItem(event.getHand()).getItem() == CaveItems.RUBY_APPLE.get()) {
				
				if (!player.abilities.isCreativeMode) {
					
					player.getHeldItem(event.getHand()).shrink(1);
					
				}
				
				for (MerchantOffer merchantOffer : newOffers) {
					
					player.sendMessage(new StringTextComponent("getSpecialPrice: " + merchantOffer.getSpecialPrice() * (-1)), player.getUniqueID());
					
					ItemStack buyingStack = merchantOffer.getBuyingStackFirst();
					ItemStack sellingStack = merchantOffer.getSellingStack();
					
					if (buyingStack.getCount() > 1) {
						
						merchantOffer.setSpecialPrice(uniqueInteger * (-1));
						
					} else if (sellingStack.getCount() > 1) {
						
						
						
					}
					
				}
				
				villager.setOffers(newOffers);
				
			}
			
		}
	}

 

Edited by Luis_ST
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.