forked from ACGaming/UniversalTweaks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ACGaming#500 from jchung01/vanilla-tweaks
Improve copy seed tweak
- Loading branch information
Showing
8 changed files
with
105 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/mod/acgaming/universaltweaks/tweaks/misc/commands/seed/UTCopyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package mod.acgaming.universaltweaks.tweaks.misc.commands.seed; | ||
|
||
import java.util.Arrays; | ||
import javax.annotation.Nonnull; | ||
import mod.acgaming.universaltweaks.UniversalTweaks; | ||
import mod.acgaming.universaltweaks.config.UTConfigGeneral; | ||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.command.CommandBase; | ||
import net.minecraft.command.CommandException; | ||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.util.text.TextComponentString; | ||
import net.minecraftforge.client.IClientCommand; | ||
|
||
public class UTCopyCommand extends CommandBase implements IClientCommand | ||
{ | ||
public static final String copyCommandBase = "/universalTweaksCopy "; | ||
|
||
@Nonnull | ||
@Override | ||
public String getName() | ||
{ | ||
return copyCommandBase.substring(1).trim(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getUsage(@Nonnull ICommandSender sender) | ||
{ | ||
return copyCommandBase + "<message to copy>"; | ||
} | ||
|
||
@Override | ||
public boolean checkPermission(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender) | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public void execute(@Nonnull MinecraftServer server, ICommandSender sender, @Nonnull String[] args) throws CommandException | ||
{ | ||
// Sanity check | ||
if (!sender.getEntityWorld().isRemote) return; | ||
if (!UTConfigTweaks.MISC.utCopyWorldSeedToggle) | ||
{ | ||
sender.sendMessage(new TextComponentString("\nCopying the seed is disabled on client-side, please enable in 'Universal Tweaks - Tweaks' -> 'Misc' -> 'Copy World Seed'.")); | ||
return; | ||
} | ||
if (args.length < 1) | ||
{ | ||
UniversalTweaks.LOGGER.warn("UTCopyCommand :: Malformed input! " + Arrays.toString(args)); | ||
} | ||
if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTCopyCommand :: Copy seed"); | ||
GuiScreen.setClipboardString(buildString(args, 0)); | ||
sender.sendMessage(new TextComponentString("\nCopied seed to clipboard!")); | ||
} | ||
|
||
@Override | ||
public boolean allowUsageWithoutPrefix(ICommandSender sender, String message) | ||
{ | ||
return false; | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
...in/java/mod/acgaming/universaltweaks/tweaks/misc/commands/seed/mixin/UTCopySeedMixin.java
This file was deleted.
Oops, something went wrong.
50 changes: 19 additions & 31 deletions
50
.../java/mod/acgaming/universaltweaks/tweaks/misc/commands/seed/mixin/UTFormatSeedMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,38 @@ | ||
package mod.acgaming.universaltweaks.tweaks.misc.commands.seed.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import mod.acgaming.universaltweaks.UniversalTweaks; | ||
import mod.acgaming.universaltweaks.config.UTConfigGeneral; | ||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
import mod.acgaming.universaltweaks.tweaks.misc.commands.seed.UTCopyCommand; | ||
import net.minecraft.command.CommandShowSeed; | ||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.util.text.Style; | ||
import net.minecraft.util.text.TextComponentString; | ||
import net.minecraft.util.text.TextComponentTranslation; | ||
import net.minecraft.util.text.TextFormatting; | ||
import net.minecraft.util.text.event.ClickEvent; | ||
import net.minecraft.util.text.event.HoverEvent; | ||
import net.minecraft.world.World; | ||
|
||
import mod.acgaming.universaltweaks.UniversalTweaks; | ||
import mod.acgaming.universaltweaks.config.UTConfigGeneral; | ||
import mod.acgaming.universaltweaks.config.UTConfigTweaks; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
// Courtesy of jchung01 | ||
@Mixin(CommandShowSeed.class) | ||
public class UTFormatSeedMixin | ||
{ | ||
// Can probably also use @ModifyArg + MixinExtras' @Local, but in beta/subject to change | ||
@Inject(method = "execute", at = @At(value = "INVOKE", target = "Lnet/minecraft/command/ICommandSender;sendMessage(Lnet/minecraft/util/text/ITextComponent;)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) | ||
private void utFormatSeedCommand(MinecraftServer server, ICommandSender sender, String[] args, CallbackInfo ci, World world) | ||
@ModifyExpressionValue(method = "execute", at = @At(value = "NEW", target = "(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/util/text/TextComponentTranslation;")) | ||
private TextComponentTranslation utFormatSeedMessage(TextComponentTranslation message) | ||
{ | ||
if (!UTConfigTweaks.MISC.utCopyWorldSeedToggle) return; | ||
if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTFormatSeedMixin :: Format seed"); | ||
|
||
long seed = world.getSeed(); | ||
TextComponentTranslation seedText = new TextComponentTranslation("commands.seed.success", seed); | ||
|
||
// format seed | ||
Style style = new Style(); | ||
style.setColor(TextFormatting.GREEN).setUnderlined(true); | ||
|
||
// make & set events | ||
style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to copy seed to clipboard"))); | ||
// use a dummy command that UTCopySeedMixin will handle | ||
style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/utCopySeed " + seed)); | ||
seedText.setStyle(style); | ||
|
||
sender.sendMessage(seedText); | ||
ci.cancel(); | ||
if (UTConfigTweaks.MISC.utCopyWorldSeedToggle) | ||
{ | ||
if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTFormatSeedMixin :: Format seed"); | ||
// Format seed | ||
Style style = new Style(); | ||
style.setColor(TextFormatting.GREEN).setUnderlined(true); | ||
// Make & set events | ||
style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to copy seed to clipboard"))); | ||
style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, UTCopyCommand.copyCommandBase + message.getFormatArgs()[0])); | ||
message.setStyle(style); | ||
} | ||
return message; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/mod/acgaming/universaltweaks/util/UTCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package mod.acgaming.universaltweaks.util; | ||
|
||
import mod.acgaming.universaltweaks.tweaks.misc.commands.seed.UTCopyCommand; | ||
import net.minecraftforge.client.ClientCommandHandler; | ||
|
||
public class UTCommands | ||
{ | ||
public static void initClientCommands() | ||
{ | ||
ClientCommandHandler.instance.registerCommand(new UTCopyCommand()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters