Basically i've been thinking of making non villager entities be able to trade items simmilarly to how villagers trade, and also give them professions like villagers, but not exactly being a villager, just something where when you right click them they open a trade window, if anyone's got any idea how to do this, and no i'm not considering to add a whole new entity just for this, i think it'd be just better to change an already existing entity like a zombie or something cuz i basically want trading zombies so yeah !
#How to add villager trades to non villager entities?
15 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
const SMP = Java.loadClass('net.minecraft.world.SimpleMenuProvider')
const MerchantMenu = Java.loadClass('net.minecraft.world.inventory.MerchantMenu')
const MerchantOffers = Java.loadClass('net.minecraft.world.item.trading.MerchantOffers')
const MerchantOffer = Java.loadClass('net.minecraft.world.item.trading.MerchantOffer')
ItemEvents.rightClicked(e => {
e.server.tell(e.target.entity.nbt.Offers)
const offer = new MerchantOffer(
Item.of('minecraft:dirt', 10), //costA stack
'minecraft:cobblestone', //costB stack
'minecraft:diamond', //result stack
0, //number of trades before requiring restock
20, //max uses
2 //xp
)
const offers = new MerchantOffers().add(0, offer)
e.player.openMenu(new SMP((i, inv, items) => new MerchantMenu(i, inv).setOffers(offers), 'guiname'))
})
something like this should work
im going to test using compound tag later
the code above isnt workin
basically its a combination of these two:
https://discord.com/channels/303440391124942858/1301189826313191514
[➤](#1301888139358371951 message)
const AnvilMenu = Java.loadClass('net.minecraft.world.inventory.AnvilMenu')
const SMP = Java.loadClass('net.minecraft.world.SimpleMenuProvider')
ItemEvents.rightClicked(e => {
e.player.openMenu(new SMP((i, inv, items) => AnvilMenu(i, inv), 'test'))
})
create offers on interact, and store them in pdata
I’ve been thinking about this very thing. Would this also be editable with moreJS or is it purely just editable in that specific code?
i believe this is the closest try, the offer is added and being valid, but no offer is shown on the menu
const SMP = Java.loadClass('net.minecraft.world.SimpleMenuProvider');
const MerchantMenu = Java.loadClass('net.minecraft.world.inventory.MerchantMenu');
const MerchantOffers = Java.loadClass('net.minecraft.world.item.trading.MerchantOffers');
const MerchantOffer = Java.loadClass('net.minecraft.world.item.trading.MerchantOffer');
ItemEvents.entityInteracted(e => {
if(e.hand == 'off_hand') return;
const offers = new MerchantOffers();
const offer = new MerchantOffer(
'minecraft:acacia_boat', //costA
'minecraft:air', //costB
'minecraft:emerald', //result
0, //number of trades before requiring restock
20, //maxuses
10, //xp
0.05, //price multiplier
-24 //demand
)
offers.add(offer);
e.server.tell('1 ' + offers.getFirst().demand) //check point 1
const menu = new SMP((i, inv, items) => {
const merchantMenu = new MerchantMenu(i, inv);
e.server.tell('2 ' + merchantMenu.getOffers().getFirst().demand) //check point 2
return merchantMenu;
}, 'guiname2');
e.player.openMenu(menu);
})
this is working↓
e.server.tell(offers.getFirst().demand)
Got it! Yea this should be helpful
@strong rampart got any ideas?
Honestly no idea lmao