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

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.

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.