File tree 8 files changed +55
-38
lines changed
java/com/plusls/MasaGadget
mod_tweak/tweakeroo/inventoryPreviewSupportTradeOfferList
versions/1.21.0-fabric/src/main/java/com/plusls/MasaGadget/mixin/mod_tweak/tweakeroo/inventoryPreviewSupportTradeOfferList
8 files changed +55
-38
lines changed Original file line number Diff line number Diff line change
1
+ package com .plusls .MasaGadget .api .fake ;
2
+
3
+ import net .minecraft .world .item .trading .MerchantOffers ;
4
+
5
+ public interface AbstractVillagerAccessor {
6
+ MerchantOffers masa_gadget$safeGetOffers ();
7
+ }
Original file line number Diff line number Diff line change 1
1
package com .plusls .MasaGadget .impl .feature .entityInfo ;
2
2
3
3
import com .google .common .collect .Lists ;
4
+ import com .plusls .MasaGadget .api .fake .AbstractVillagerAccessor ;
4
5
import com .plusls .MasaGadget .util .PcaSyncProtocol ;
5
6
import net .minecraft .ChatFormatting ;
6
7
import net .minecraft .client .Minecraft ;
@@ -43,7 +44,7 @@ public class VillageTradeEnchantedBookInfo {
43
44
44
45
List <Component > ret = Lists .newArrayList ();
45
46
46
- for (MerchantOffer tradeOffer : villager . getOffers ()) {
47
+ for (MerchantOffer tradeOffer : (( AbstractVillagerAccessor ) ( villager )). masa_gadget$safeGetOffers ()) {
47
48
ItemStack sellItem = tradeOffer .getResult ();
48
49
ItemStackCompat sellItemCompat = ItemStackCompat .of (sellItem );
49
50
Original file line number Diff line number Diff line change 1
1
package com .plusls .MasaGadget .impl .feature .entityInfo ;
2
2
3
+ import com .plusls .MasaGadget .api .fake .AbstractVillagerAccessor ;
3
4
import com .plusls .MasaGadget .mixin .accessor .AccessorVillager ;
4
5
import com .plusls .MasaGadget .util .PcaSyncProtocol ;
5
6
import net .minecraft .ChatFormatting ;
@@ -61,7 +62,7 @@ public class VillagerNextRestockTimeInfo {
61
62
// 因为刁民的需要补货的函数,会检查当前货物是否被消耗,从使用的角度只需要关心当前货物是否用完
62
63
private static boolean needsRestock (@ NotNull Villager villagerEntity ) {
63
64
if (villagerEntity .getVillagerData ().getProfession () != VillagerProfession .NONE ) {
64
- for (MerchantOffer offer : villagerEntity . getOffers ()) {
65
+ for (MerchantOffer offer : (( AbstractVillagerAccessor ) ( villagerEntity )). masa_gadget$safeGetOffers ()) {
65
66
if (offer .isOutOfStock ()) {
66
67
return true ;
67
68
}
Original file line number Diff line number Diff line change
1
+ package com .plusls .MasaGadget .mixin ;
2
+
3
+ import com .plusls .MasaGadget .api .fake .AbstractVillagerAccessor ;
4
+ import net .minecraft .world .entity .npc .AbstractVillager ;
5
+ import net .minecraft .world .item .trading .MerchantOffers ;
6
+ import org .spongepowered .asm .mixin .Mixin ;
7
+ import org .spongepowered .asm .mixin .Shadow ;
8
+
9
+ //#if MC > 12006
10
+ //$$ import org.jetbrains.annotations.Nullable;
11
+ //#endif
12
+
13
+ @ Mixin (AbstractVillager .class )
14
+ public abstract class MixinAbstractVillager implements AbstractVillagerAccessor {
15
+ //#if MC > 12006
16
+ //$$ @Shadow
17
+ //$$ @Nullable
18
+ //$$ protected MerchantOffers offers;
19
+ //$$ @Shadow
20
+ //$$ protected abstract void updateTrades();
21
+ //#else
22
+ @ Shadow
23
+ public abstract MerchantOffers getOffers ();
24
+ //#endif
25
+
26
+ @ Override
27
+ public MerchantOffers masa_gadget$safeGetOffers () {
28
+ //#if MC > 12006
29
+ //$$ if (this.offers == null) {
30
+ //$$ this.offers = new MerchantOffers();
31
+ //$$ this.updateTrades();
32
+ //$$ }
33
+ //$$
34
+ //$$ return this.offers;
35
+ //#else
36
+ return this .getOffers ();
37
+ //#endif
38
+ }
39
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
package com .plusls .MasaGadget .mixin .mod_tweak .tweakeroo .inventoryPreviewSupportTradeOfferList ;
2
2
3
+ import com .plusls .MasaGadget .api .fake .AbstractVillagerAccessor ;
3
4
import com .plusls .MasaGadget .game .Configs ;
4
5
import com .plusls .MasaGadget .impl .generic .HitResultHandler ;
5
6
import com .plusls .MasaGadget .util .ModId ;
@@ -74,12 +75,12 @@ private static Container renderTradeOfferList(Container inv) {
74
75
75
76
SimpleContainer simpleInventory = new SimpleContainer (MixinRenderUtils .masa_gadget$maxTradeOfferSize );
76
77
77
- for (MerchantOffer tradeOffer : abstractVillager . getOffers ()) {
78
- for (int i = 0 ; i < simpleInventory .getContainerSize (); ++ i ) {
78
+ for (MerchantOffer tradeOffer : (( AbstractVillagerAccessor ) ( abstractVillager )). masa_gadget$safeGetOffers ()) {
79
+ for (int i = 0 ; i < simpleInventory .getContainerSize (); i ++ ) {
79
80
ItemStack itemStack = simpleInventory .getItem (i );
80
81
81
82
if (itemStack .isEmpty ()) {
82
- simpleInventory .setItem (i , tradeOffer .getResult (). copy () );
83
+ simpleInventory .setItem (i , tradeOffer .getResult ());
83
84
break ;
84
85
}
85
86
}
Original file line number Diff line number Diff line change 5
5
"compatibilityLevel" : " JAVA_8" ,
6
6
"plugin" : " top.hendrixshen.magiclib.impl.mixin.MagicMixinPlugin" ,
7
7
"client" : [
8
+ " MixinAbstractVillager" ,
8
9
" MixinConnection" ,
9
10
" accessor.AccessorAbstractMinecartContainer" ,
10
11
" accessor.AccessorAbstractVillager" ,
50
51
" mod_tweak.tweakeroo.inventoryPreviewSupportSelect.MixinInGameHud" ,
51
52
" mod_tweak.tweakeroo.inventoryPreviewSupportSelect.MixinInventoryOverlay" ,
52
53
" mod_tweak.tweakeroo.inventoryPreviewSupportShulkerBoxItemEntity.MixinRenderUtils" ,
53
- " mod_tweak.tweakeroo.inventoryPreviewSupportTradeOfferList.MixinAbstractVillager" ,
54
54
" mod_tweak.tweakeroo.inventoryPreviewSupportTradeOfferList.MixinRenderUtils" ,
55
55
" mod_tweak.tweakeroo.inventoryPreviewSyncDataClientOnly.MixinClientPacketListener" ,
56
56
" mod_tweak.tweakeroo.inventoryPreviewUseCache.MixinMixinRenderUtils"
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments