88import com .mojang .brigadier .builder .RequiredArgumentBuilder ;
99import com .mojang .brigadier .exceptions .CommandSyntaxException ;
1010import com .mojang .brigadier .exceptions .SimpleCommandExceptionType ;
11+ import dev .solcraft .soltweaks .mixins .accessors .WorldBorderCommandAccessor ;
1112import net .minecraft .command .argument .Vec2ArgumentType ;
1213import net .minecraft .server .command .CommandManager ;
1314import net .minecraft .server .command .ServerCommandSource ;
2021import org .spongepowered .asm .mixin .Overwrite ;
2122import org .spongepowered .asm .mixin .Shadow ;
2223import org .spongepowered .asm .mixin .injection .At ;
24+ import org .spongepowered .asm .mixin .injection .Constant ;
2325import org .spongepowered .asm .mixin .injection .Inject ;
26+ import org .spongepowered .asm .mixin .injection .ModifyConstant ;
2427import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2528
2629import java .util .Locale ;
3033@ Mixin (WorldBorderCommand .class )
3134public abstract class MixinWorldBorderCommand {
3235 @ Shadow
33- public static SimpleCommandExceptionType SET_FAILED_BIG_EXCEPTION ;
36+ private static SimpleCommandExceptionType SET_FAILED_BIG_EXCEPTION ;
3437
3538 @ Shadow
3639 @ Final
@@ -40,67 +43,43 @@ public abstract class MixinWorldBorderCommand {
4043
4144 @ Inject (method = "<clinit>" , at = @ At ("RETURN" ))
4245 private static void handleConstructor (CallbackInfo ci ) {
43- SET_FAILED_BIG_EXCEPTION = new SimpleCommandExceptionType (new TranslatableText ("commands.worldborder.set.failed.big" , 4294967294D ));
46+ SET_FAILED_BIG_EXCEPTION = new SimpleCommandExceptionType (new TranslatableText ("commands.worldborder.set.failed.big" , 4294967294D ));
4447 }
4548 /**
4649 * @author Zeta
4750 * @reason Fix wb
4851 */
52+ @ SuppressWarnings ("all" )
4953 @ Overwrite
5054 public static void register (CommandDispatcher <ServerCommandSource > dispatcher ) {
5155 dispatcher .register ((LiteralArgumentBuilder )((LiteralArgumentBuilder )((LiteralArgumentBuilder )((LiteralArgumentBuilder )((LiteralArgumentBuilder )((LiteralArgumentBuilder )((LiteralArgumentBuilder ) CommandManager .literal ("worldborder" ).requires ((source ) -> {
5256 return source .hasPermissionLevel (2 );
5357//TODO: Change these back and remove static import
5458 })).then (CommandManager .literal ("add" ).then (((RequiredArgumentBuilder )CommandManager .argument ("distance" , DoubleArgumentType .doubleArg (-4294967294D , 4294967294D )).executes ((context ) -> {
55- return executeSet ((ServerCommandSource )context .getSource (), ((ServerCommandSource )context .getSource ()).getWorld ().getWorldBorder ().getSize () + DoubleArgumentType .getDouble (context , "distance" ), 0L );
59+ return WorldBorderCommandAccessor . executeSet ((ServerCommandSource )context .getSource (), ((ServerCommandSource )context .getSource ()).getWorld ().getWorldBorder ().getSize () + DoubleArgumentType .getDouble (context , "distance" ), 0L );
5660 })).then (CommandManager .argument ("time" , IntegerArgumentType .integer (0 )).executes ((context ) -> {
57- return executeSet ((ServerCommandSource )context .getSource (), ((ServerCommandSource )context .getSource ()).getWorld ().getWorldBorder ().getSize () + DoubleArgumentType .getDouble (context , "distance" ), ((ServerCommandSource )context .getSource ()).getWorld ().getWorldBorder ().getSizeLerpTime () + (long )IntegerArgumentType .getInteger (context , "time" ) * 1000L );
61+ return WorldBorderCommandAccessor . executeSet ((ServerCommandSource )context .getSource (), ((ServerCommandSource )context .getSource ()).getWorld ().getWorldBorder ().getSize () + DoubleArgumentType .getDouble (context , "distance" ), ((ServerCommandSource )context .getSource ()).getWorld ().getWorldBorder ().getSizeLerpTime () + (long )IntegerArgumentType .getInteger (context , "time" ) * 1000L );
5862 }))))).then (CommandManager .literal ("set" ).then (((RequiredArgumentBuilder )CommandManager .argument ("distance" , DoubleArgumentType .doubleArg (-4294967294D , 4294967294D )).executes ((context ) -> {
59- return executeSet ((ServerCommandSource )context .getSource (), DoubleArgumentType .getDouble (context , "distance" ), 0L );
63+ return WorldBorderCommandAccessor . executeSet ((ServerCommandSource )context .getSource (), DoubleArgumentType .getDouble (context , "distance" ), 0L );
6064 })).then (CommandManager .argument ("time" , IntegerArgumentType .integer (0 )).executes ((context ) -> {
61- return executeSet ((ServerCommandSource )context .getSource (), DoubleArgumentType .getDouble (context , "distance" ), (long )IntegerArgumentType .getInteger (context , "time" ) * 1000L );
65+ return WorldBorderCommandAccessor . executeSet ((ServerCommandSource )context .getSource (), DoubleArgumentType .getDouble (context , "distance" ), (long )IntegerArgumentType .getInteger (context , "time" ) * 1000L );
6266 }))))).then (CommandManager .literal ("center" ).then (CommandManager .argument ("pos" , Vec2ArgumentType .vec2 ()).executes ((context ) -> {
63- return executeCenter ((ServerCommandSource )context .getSource (), Vec2ArgumentType .getVec2 (context , "pos" ));
67+ return WorldBorderCommandAccessor . executeCenter ((ServerCommandSource )context .getSource (), Vec2ArgumentType .getVec2 (context , "pos" ));
6468 })))).then (((LiteralArgumentBuilder )CommandManager .literal ("damage" ).then (CommandManager .literal ("amount" ).then (CommandManager .argument ("damagePerBlock" , FloatArgumentType .floatArg (0.0F )).executes ((context ) -> {
65- return executeDamage ((ServerCommandSource )context .getSource (), FloatArgumentType .getFloat (context , "damagePerBlock" ));
69+ return WorldBorderCommandAccessor . executeDamage ((ServerCommandSource )context .getSource (), FloatArgumentType .getFloat (context , "damagePerBlock" ));
6670 })))).then (CommandManager .literal ("buffer" ).then (CommandManager .argument ("distance" , FloatArgumentType .floatArg (0.0F )).executes ((context ) -> {
67- return executeBuffer ((ServerCommandSource )context .getSource (), FloatArgumentType .getFloat (context , "distance" ));
71+ return WorldBorderCommandAccessor . executeBuffer ((ServerCommandSource )context .getSource (), FloatArgumentType .getFloat (context , "distance" ));
6872 }))))).then (CommandManager .literal ("get" ).executes ((context ) -> {
69- return executeGet ((ServerCommandSource )context .getSource ());
73+ return WorldBorderCommandAccessor . executeGet ((( ServerCommandSource )context .getSource () ));
7074 }))).then (((LiteralArgumentBuilder )CommandManager .literal ("warning" ).then (CommandManager .literal ("distance" ).then (CommandManager .argument ("distance" , IntegerArgumentType .integer (0 )).executes ((context ) -> {
71- return executeWarningDistance ((ServerCommandSource )context .getSource (), IntegerArgumentType .getInteger (context , "distance" ));
75+ return WorldBorderCommandAccessor . executeWarningDistance ((ServerCommandSource )context .getSource (), IntegerArgumentType .getInteger (context , "distance" ));
7276 })))).then (CommandManager .literal ("time" ).then (CommandManager .argument ("time" , IntegerArgumentType .integer (0 )).executes ((context ) -> {
73- return executeWarningTime ((ServerCommandSource )context .getSource (), IntegerArgumentType .getInteger (context , "time" ));
77+ return WorldBorderCommandAccessor . executeWarningTime ((ServerCommandSource )context .getSource (), IntegerArgumentType .getInteger (context , "time" ));
7478 })))));
7579 }
76- /**
77- * @author
78- * @reason
79- */
80- @ Overwrite
81- private static int executeSet (ServerCommandSource source , double distance , long time ) throws CommandSyntaxException {
82- WorldBorder worldBorder = source .getWorld ().getWorldBorder ();
83- double d = worldBorder .getSize ();
84- if (d == distance ) {
85- throw SET_FAILED_NO_CHANGE_EXCEPTION .create ();
86- } else if (distance < 1.0D ) {
87- throw SET_FAILED_SMALL_EXCEPTION .create ();
88- } else if (distance > 4294967294D ) {
89- throw SET_FAILED_BIG_EXCEPTION .create ();
90- } else {
91- if (time > 0L ) {
92- worldBorder .interpolateSize (d , distance , time );
93- if (distance > d ) {
94- source .sendFeedback (new TranslatableText ("commands.worldborder.set.grow" , new Object []{String .format (Locale .ROOT , "%.1f" , distance ), Long .toString (time / 1000L )}), true );
95- } else {
96- source .sendFeedback (new TranslatableText ("commands.worldborder.set.shrink" , new Object []{String .format (Locale .ROOT , "%.1f" , distance ), Long .toString (time / 1000L )}), true );
97- }
98- } else {
99- worldBorder .setSize (distance );
100- source .sendFeedback (new TranslatableText ("commands.worldborder.set.immediate" , new Object []{String .format (Locale .ROOT , "%.1f" , distance )}), true );
101- }
102-
103- return (int )(distance - d );
104- }
80+ // Modify the constant in the executeSet method
81+ @ ModifyConstant (method = "executeSet" , constant = @ Constant (doubleValue = 5.9999968E7 ))
82+ private static double replaceMaxBorderSize (double original ) {
83+ return 4294967294D ;
10584 }
10685}
0 commit comments