@@ -6,14 +6,20 @@ module.exports = () => async (bot) => {
66
77 const villagerType = bot . registry . entitiesByName . villager ? 'villager' : 'Villager'
88 const testFluctuations = bot . supportFeature ( 'selectingTradeMovesItems' )
9+
910 const summonCommand = bot . supportFeature ( 'indexesVillagerRecipes' )
10- ? `/summon ${ villagerType } ~ ~1 ~ {NoAI:1, Offers:{Recipes:[0:{maxUses:7 ,buy:{id:"minecraft:emerald",Count:2},sell:{id:"minecraft:pumpkin_pie",Count:2},uses: 1},1:{maxUses:7 ,buy:{id:"minecraft:emerald",Count:2},buyB:{id:"minecraft:pumpkin_pie",Count:2},sell:{id:"minecraft:wheat",Count:2}, uses:1}]}}`
11- : `/summon ${ villagerType } ~ ~1 ~ {NoAI:1, Offers:{Recipes:[{maxUses:7 ,buy:{id:"minecraft:emerald",Count:2},sell:{id:"minecraft:pumpkin_pie",Count:2},${ testFluctuations ? 'demand:60,priceMultiplier:0.05f,specialPrice:-4,' : '' } uses: 1},{maxUses:7 ,buy:{id:"minecraft:emerald",Count:2},buyB:{id:"minecraft:pumpkin_pie",Count:2},sell:{id:"minecraft:wheat",Count:2}, uses:1}]}}`
11+ ? `/summon ${ villagerType } ~ ~1 ~ {NoAI:1, Offers:{Recipes:[0:{maxUses:12 ,buy:{id:"minecraft:emerald",Count:2},sell:{id:"minecraft:pumpkin_pie",Count:2},uses: 1},1:{maxUses:12 ,buy:{id:"minecraft:emerald",Count:2},buyB:{id:"minecraft:pumpkin_pie",Count:2},sell:{id:"minecraft:wheat",Count:2}, uses:1},2:{maxUses:12,buy:{id:"minecraft:emerald",Count:1},sell:{id:"minecraft:glass",Count:4},uses: 1},3:{maxUses:12,buy:{id:"minecraft:emerald",Count:36},buyB:{id:"minecraft:book",Count:1},sell:{id:"minecraft:wooden_sword",Count:1},uses: 1}]}}`
12+ : `/summon ${ villagerType } ~ ~1 ~ {NoAI:1, Offers:{Recipes:[{maxUses:12 ,buy:{id:"minecraft:emerald",Count:2},sell:{id:"minecraft:pumpkin_pie",Count:2},${ testFluctuations ? 'demand:60,priceMultiplier:0.05f,specialPrice:-4,' : '' } uses: 1},{maxUses:12 ,buy:{id:"minecraft:emerald",Count:2},buyB:{id:"minecraft:pumpkin_pie",Count:2},sell:{id:"minecraft:wheat",Count:2}, uses:1},{maxUses:12,buy:{id:"minecraft:emerald",Count:1},sell:{id:"minecraft:glass",Count:4},uses: 1},{maxUses:12,buy:{id:"minecraft:emerald",Count:36},buyB:{id:"minecraft:book",Count:1},sell:{id:"minecraft:wooden_sword",Count:1},uses: 1}]}}`
1213
1314 const commandBlockPos = bot . entity . position . offset ( 0.5 , 0 , 0.5 )
1415 const redstoneBlockPos = commandBlockPos . offset ( 1 , 0 , 0 )
1516
16- await bot . test . setInventorySlot ( 36 , new Item ( bot . registry . itemsByName . emerald . id , 64 , 0 ) )
17+ let shouldHaveEmeralds = 0
18+ for ( let slot = 9 ; slot <= 17 ; slot += 1 ) {
19+ await bot . test . setInventorySlot ( slot , new Item ( bot . registry . itemsByName . emerald . id , 64 , 0 ) )
20+ shouldHaveEmeralds += 64
21+ }
22+ await bot . test . setInventorySlot ( 18 , new Item ( bot . registry . itemsByName . book . id , 11 , 0 ) )
1723
1824 // A command block is needed to spawn the villager due to the chat's character limit in some versions
1925 bot . test . sayEverywhere ( `/setblock ${ commandBlockPos . toArray ( ) . join ( ' ' ) } command_block` )
@@ -40,9 +46,10 @@ module.exports = () => async (bot) => {
4046 assert . strictEqual ( output . name , 'pumpkin_pie' )
4147 assert . strictEqual ( output . count , 2 )
4248
43- await bot . trade ( villager , 0 , 6 )
44- assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . emerald . id ) , testFluctuations ? 64 - 24 : 64 - 12 )
45- assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . pumpkin_pie . id ) , 12 )
49+ await bot . trade ( villager , 0 , 11 )
50+ shouldHaveEmeralds -= testFluctuations ? ( 2 * 2 * 11 ) : ( 2 * 11 )
51+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . emerald . id ) , shouldHaveEmeralds )
52+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . pumpkin_pie . id ) , 22 )
4653 }
4754
4855 // Handle trade #2 -- takes [2x emerald, 2x pumpkin_pie] and returns 2x wheat
@@ -61,15 +68,59 @@ module.exports = () => async (bot) => {
6168 assert . strictEqual ( output . name , 'wheat' )
6269 assert . strictEqual ( output . count , 2 )
6370
64- await bot . trade ( villager , 1 , 6 )
65- assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . emerald . id ) , testFluctuations ? 64 - 36 : 64 - 24 )
71+ await bot . trade ( villager , 1 , 11 )
72+ shouldHaveEmeralds -= 11 * 2
73+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . emerald . id ) , shouldHaveEmeralds )
6674 assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . pumpkin_pie . id ) , 0 )
67- assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . wheat . id ) , 12 )
75+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . wheat . id ) , 22 )
76+ }
77+
78+ // Handle trade #3 -- takes 1x emerald and returns 4x glass
79+ {
80+ const trade = villager . trades [ 2 ]
81+ assert . strictEqual ( trade . inputs . length , 1 , 'Expected single input from villager on first trade' )
82+ verifyTrade ( trade )
83+
84+ const [ input ] = trade . inputs
85+ assert . strictEqual ( input . name , 'emerald' )
86+ assert . strictEqual ( input . count , 1 )
87+
88+ const [ output ] = trade . outputs
89+ assert . strictEqual ( output . name , 'glass' )
90+ assert . strictEqual ( output . count , 4 )
91+
92+ await bot . trade ( villager , 2 , 11 )
93+ shouldHaveEmeralds -= 11
94+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . emerald . id ) , shouldHaveEmeralds )
95+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . glass . id ) , 44 )
96+ }
97+
98+ // Handle trade #4 -- takes [36x emerald, 1x book] and returns 1x wooden sword
99+ {
100+ const trade = villager . trades [ 3 ]
101+ assert . strictEqual ( trade . inputs . length , 2 , 'Expected two inputs from villager on second trade' )
102+ verifyTrade ( trade )
103+
104+ const [ input1 , input2 ] = trade . inputs
105+ assert . strictEqual ( input1 . name , 'emerald' )
106+ assert . strictEqual ( input1 . count , 36 )
107+ assert . strictEqual ( input2 . name , 'book' )
108+ assert . strictEqual ( input2 . count , 1 )
109+
110+ const [ output ] = trade . outputs
111+ assert . strictEqual ( output . name , 'wooden_sword' )
112+ assert . strictEqual ( output . count , 1 )
113+
114+ await bot . trade ( villager , 3 , 11 )
115+ shouldHaveEmeralds -= 11 * 36
116+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . emerald . id ) , shouldHaveEmeralds )
117+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . book . id ) , 0 )
118+ assert . strictEqual ( bot . currentWindow . count ( bot . registry . itemsByName . wooden_sword . id ) , 11 )
68119 }
69120
70121 function verifyTrade ( trade ) {
71122 assert . strictEqual ( trade . nbTradeUses , 1 )
72- assert . strictEqual ( trade . maximumNbTradeUses , 7 )
123+ assert . strictEqual ( trade . maximumNbTradeUses , 12 )
73124 assert . strictEqual ( trade . tradeDisabled , false )
74125
75126 const printCountInv = function ( item ) {
0 commit comments