22
33import com .google .common .collect .Lists ;
44import net .minecraft .block .Block ;
5- import net .minecraft .client .util .math .Vector3f ;
65import net .minecraft .enchantment .Enchantment ;
76import net .minecraft .enchantment .EnchantmentHelper ;
87import net .minecraft .enchantment .InfoEnchantment ;
@@ -30,6 +29,14 @@ public static class SellItemFactory implements TradeOffers.Factory {
3029 private int maxUses ;
3130 private int experience ;
3231 private float multiplier ;
32+ private int randomCostMin =1 ;
33+ private int randomCostMax =64 ;
34+ private boolean randomCost =false ;
35+ private boolean randomCount =false ;
36+ private boolean randomSaleItem =false ;
37+ private boolean randomPriceItem =false ;
38+ private int randomCountMin =1 ;
39+ private int randomCountMax =64 ;
3340
3441 public SellItemFactory (SellItemFactory from ) {
3542 this .sell = from .sell ;
@@ -56,14 +63,26 @@ public SellItemFactory(ItemStack itemStack, int price, int maxUses, int experien
5663 }
5764
5865 public SellItemFactory (ItemStack itemStack , int price , int maxUses , int experience , float multiplier ) {
59- this (itemStack ,new ItemStack (Items .EMERALD , price ), maxUses ,experience ,multiplier );
66+ this (itemStack ,new ItemStack []{ new ItemStack (Items .EMERALD , price ), ItemStack . EMPTY } , maxUses ,experience ,multiplier );
6067 }
6168 public SellItemFactory (ItemStack itemStack , ItemStack price , int maxUses , int experience ) {
62- this (itemStack ,price , maxUses ,experience ,0.05F );
69+ this (itemStack ,new ItemStack []{ price , ItemStack . EMPTY } , maxUses ,experience ,0.05F );
6370 }
6471
65- public SellItemFactory (ItemStack itemStack , ItemStack price , int maxUses , int experience , float multiplier ) {
66- this (itemStack ,new ItemStack []{price ,ItemStack .EMPTY },maxUses ,experience ,multiplier );
72+ public SellItemFactory (ItemStack itemStack , ItemStack [] price , int randomCostMin , int randomCostMax , boolean randomCost , boolean randomCount , int randomCountMin , int randomCountMax , boolean randomSaleItem , boolean randomPriceItem , int maxUses , int experience , float multiplier ) {
73+ this .sell = itemStack ;
74+ this .price = price ;
75+ this .maxUses = maxUses ;
76+ this .experience = experience ;
77+ this .multiplier = multiplier ;
78+ this .randomCost =randomCost ;
79+ this .randomCount =randomCount ;
80+ this .randomCostMin =randomCostMin ;
81+ this .randomCostMax =randomCostMax ;
82+ this .randomCountMin =randomCountMin ;
83+ this .randomCountMax =randomCountMax ;
84+ this .randomSaleItem = randomSaleItem ;
85+ this .randomPriceItem = randomPriceItem ;
6786 }
6887 public SellItemFactory (ItemStack itemStack , ItemStack [] price , int maxUses , int experience , float multiplier ) {
6988 this .sell = itemStack ;
@@ -74,8 +93,34 @@ public SellItemFactory(ItemStack itemStack, ItemStack[] price, int maxUses, int
7493 }
7594
7695 public TradeOffer create (Entity entity , Random random ) {
77- return new TradeOffer (this .price [0 ],this .price [1 ],
78- this .sell , this .maxUses , this .experience , this .multiplier );
96+ ItemStack price0 = this .price [0 ].copy ();
97+ int priceCount =price0 .getCount ();
98+ if (priceCount <1 )
99+ priceCount =1 ;
100+
101+ if (randomPriceItem ) {
102+
103+ price0 =new ItemStack (Registry .ITEM .get (random .nextInt ((int )Registry .ITEM .stream ().count ())),priceCount );
104+ }
105+ if (price0 .isEmpty ()) {
106+ price0 = new ItemStack (Items .EMERALD ,priceCount );
107+ }
108+ if (this .randomCost ) {
109+ price0 .setCount (random .nextInt ((randomCostMax +1 )-randomCostMin )+randomCostMin );
110+ }
111+ ItemStack saleItem = this .sell .copy ();
112+ int saleCount =saleItem .getCount ();
113+ if (saleCount <1 )
114+ saleCount =1 ;
115+
116+ if (randomSaleItem ) {
117+ saleItem =new ItemStack (Registry .ITEM .get (random .nextInt ((int )Registry .ITEM .stream ().count ())),saleCount );
118+ }
119+ if (randomCount ) {
120+ saleItem .setCount (random .nextInt ((randomCountMax +1 )-randomCountMin )+randomCostMin );
121+ }
122+ return new TradeOffer (price0 ,this .price [1 ],
123+ saleItem , this .maxUses , this .experience , this .multiplier );
79124 }
80125 }
81126 public static class SellPotionHoldingItemFactory implements TradeOffers .Factory {
@@ -118,8 +163,8 @@ public EnchantBookFactory(ItemStack[] price, int maxUses, int experience, float
118163 this .priceMultiplier =priceMultiplier ;
119164 this .randomCost =false ;
120165 }
121- public EnchantBookFactory (ItemStack priceItem , int min , int max , boolean doubleTreasureCost , int maxUses , int experience , float priceMultiplier ) {
122- this .price [ 1 ] = priceItem ;
166+ public EnchantBookFactory (ItemStack [] price , int min , int max , boolean doubleTreasureCost , int maxUses , int experience , float priceMultiplier ) {
167+ this .price = price ;
123168 this .experience =experience ;
124169 this .randomCostMin =min ;
125170 this .randomCostMax =max ;
@@ -134,10 +179,13 @@ public TradeOffer create(Entity entity, Random random) {
134179 ItemStack itemStack = EnchantedBookItem .forEnchantment (new InfoEnchantment (enchantment , enchantmentLevel ));
135180 int cost = 0 ;
136181 ItemStack price0 = price [0 ].copy ();
182+ if (price0 .isEmpty ()) {
183+ price0 =new ItemStack (Items .EMERALD );
184+ }
137185 if (randomCost ) {
138186 cost = randomCostMin + random .nextInt (5 +enchantmentLevel *10 )+3 *enchantmentLevel ;
139187 cost = Math .min (Math .max (cost ,randomCostMin ),randomCostMax );
140- price0 = new ItemStack ( Items . EMERALD , cost );
188+ price0 . setCount ( cost );
141189 }
142190 if (doubleTreasureCost ) {
143191 if (enchantment .isTreasure ()) {
@@ -169,11 +217,11 @@ public SellEnchantedItemFactory(ItemStack item, ItemStack[] price, boolean treas
169217 this .priceMultiplier = multiplier ;
170218 this .treasure =treasure ;
171219 }
172- public SellEnchantedItemFactory (ItemStack item , ItemStack price , int min , int max , boolean treasure , int maxUses , int experience , float multiplier ) {
220+ public SellEnchantedItemFactory (ItemStack item , ItemStack [] price , int min , int max , boolean treasure , int maxUses , int experience , float multiplier ) {
173221 this .item = item ;
174222 this .randomCostMin =min ;
175223 this .randomCostMax =max ;
176- this .price [ 1 ] =price ;
224+ this .price =price ;
177225 this .maxUses = maxUses ;
178226 this .experience = experience ;
179227 this .priceMultiplier = multiplier ;
@@ -184,12 +232,13 @@ public TradeOffer create(Entity entity, Random random) {
184232 ItemStack enchantedItem = this .item .copy ();
185233 int enchantPower = 5 + random .nextInt (15 ); // power level
186234 enchantedItem = EnchantmentHelper .enchant (random , enchantedItem , enchantPower , this .treasure );
187- ItemStack price0 ;
235+ ItemStack price0 =price [0 ];
236+ if (price0 .isEmpty ()) {
237+ price0 =new ItemStack (Items .EMERALD );
238+ }
188239 if (randomCost ) {
189240 int cost = Math .min (this .randomCostMin + enchantPower , randomCostMax );
190- price0 = new ItemStack (Items .EMERALD , cost );
191- }else {
192- price0 = price [0 ].copy ();
241+ price0 .setCount (cost );
193242 }
194243 return new TradeOffer (price0 , price [1 ].copy (), enchantedItem , this .maxUses , this .experience , this .priceMultiplier );
195244 }
0 commit comments