22
33import appeng .api .implementations .blockentities .IWirelessAccessPoint ;
44import appeng .api .implementations .menuobjects .ItemMenuHost ;
5+ import appeng .api .networking .IGrid ;
56import appeng .blockentity .networking .WirelessAccessPointBlockEntity ;
67import appeng .helpers .WirelessTerminalMenuHost ;
78import net .minecraft .world .entity .player .Player ;
89import net .minecraft .world .item .ItemStack ;
10+ import org .spongepowered .asm .mixin .Final ;
911import org .spongepowered .asm .mixin .Mixin ;
1012import org .spongepowered .asm .mixin .Shadow ;
1113import org .spongepowered .asm .mixin .injection .At ;
1214import org .spongepowered .asm .mixin .injection .Inject ;
15+ import org .spongepowered .asm .mixin .injection .Redirect ;
1316import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
1417import uk .co .hexeption .aeinfinitybooster .setup .ModItems ;
1518
@@ -25,18 +28,20 @@ public class MixinWirelessTerminalMenuHost extends ItemMenuHost {
2528 @ Shadow
2629 private double currentDistanceFromGrid ;
2730
31+ @ Shadow @ Final private IGrid targetGrid ;
32+
2833 public MixinWirelessTerminalMenuHost (Player player , int slot , ItemStack itemStack ) {
2934 super (player , slot , itemStack );
3035 }
3136
32- @ Inject (method = "testWap " , at = @ At ("HEAD" ), cancellable = true )
33- private void testWap (IWirelessAccessPoint wirelessAccessPoint , CallbackInfoReturnable <Boolean > cir ) {
37+ @ Inject (method = "getWapSqDistance " , at = @ At ("HEAD" ), cancellable = true )
38+ private void testWap (IWirelessAccessPoint wirelessAccessPoint , CallbackInfoReturnable <Double > cir ) {
3439
3540 wirelessAccessPoint .getGrid ().getMachines (WirelessAccessPointBlockEntity .class ).forEach (wirelessBlockEntity -> {
3641
3742 if (wirelessBlockEntity .getInternalInventory ().getStackInSlot (0 ).is (ModItems .DIMENSION_CARD .get ())) {
3843 currentDistanceFromGrid = 32 ;
39- cir .setReturnValue (true );
44+ cir .setReturnValue (Double . MAX_VALUE / 2 );
4045 }
4146
4247 if (!this .getPlayer ().level ().dimension ().location ().toString ().equals (wirelessAccessPoint .getLocation ().getLevel ().dimension ().location ().toString ())) {
@@ -45,9 +50,23 @@ private void testWap(IWirelessAccessPoint wirelessAccessPoint, CallbackInfoRetur
4550
4651 if (wirelessBlockEntity .getInternalInventory ().getStackInSlot (0 ).is (ModItems .INFINITY_CARD .get ())) {
4752 currentDistanceFromGrid = 16 ;
48- cir .setReturnValue (true );
53+ cir .setReturnValue (Double . MAX_VALUE / 2 );
4954 }
5055 });
5156 }
5257
58+ // Make sure we don't use more power than we should
59+ @ Redirect (method = "extractAEPower" , at = @ At (value = "INVOKE" , target = "Ljava/lang/Math;min(DD)D" ))
60+ private double testPowerMultiplier (double a , double b ) {
61+ for (var wap : this .targetGrid .getMachines (WirelessAccessPointBlockEntity .class )) {
62+ if (wap .getInternalInventory ().getStackInSlot (0 ).is (ModItems .INFINITY_CARD .get ())) {
63+ return 16 ;
64+ }
65+ if (wap .getInternalInventory ().getStackInSlot (0 ).is (ModItems .DIMENSION_CARD .get ())) {
66+ return 32 ;
67+ }
68+ }
69+ return Math .min (a , b );
70+ }
71+
5372}
0 commit comments