Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve copy seed tweak #500

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import mod.acgaming.universaltweaks.tweaks.items.rarity.UTCustomRarity;
import mod.acgaming.universaltweaks.tweaks.items.useduration.UTCustomUseDuration;
import mod.acgaming.universaltweaks.tweaks.misc.armorcurve.UTArmorCurve;
import mod.acgaming.universaltweaks.util.UTCommands;
import mod.acgaming.universaltweaks.tweaks.misc.endportal.UTEndPortalParallax;
import mod.acgaming.universaltweaks.tweaks.misc.gui.lanserverproperties.UTLanServerProperties;
import mod.acgaming.universaltweaks.tweaks.misc.incurablepotions.UTIncurablePotions;
Expand Down Expand Up @@ -215,6 +216,7 @@ public void postInitClient(FMLPostInitializationEvent event)
if (UTConfigTweaks.MISC.LOAD_SOUNDS.utLoadSoundMode != UTConfigTweaks.MiscCategory.LoadSoundsCategory.EnumSoundModes.NOTHING) UTLoadSound.initLists();
if (UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlTutorialToggle) UTTutorialToast.utTutorialToast();
if (Loader.isModLoaded("botania")) UTBotaniaFancySkybox.initDimList();
UTCommands.initClientCommands();
LOGGER.info(NAME + " client post-initialized");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,12 @@ public static class MiscCategory

@Config.RequiresMcRestart
@Config.Name("Copy World Seed")
@Config.Comment("Enables clicking of `/seed` world seed in chat to copy to clipboard")
public boolean utCopyWorldSeedToggle = false;
@Config.Comment
({
"Enables clicking of `/seed` world seed in chat to copy to clipboard",
"Required on server AND client"
})
public boolean utCopyWorldSeedToggle = true;

@Config.Name("Damage Tilt")
@Config.Comment("Restores feature to tilt the camera when damaged")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.misc.advancements.json", () -> UTConfigTweaks.MISC.utDisableAdvancementsToggle);
put("mixins.tweaks.misc.armorcurve.json", () -> UTConfigTweaks.MISC.ARMOR_CURVE.utArmorCurveToggle);
put("mixins.tweaks.misc.bannerlayers.json", () -> UTConfigTweaks.MISC.utBannerLayers != 6);
put("mixins.tweaks.misc.commands.seed.json", () -> UTConfigTweaks.MISC.utCopyWorldSeedToggle);
put("mixins.tweaks.misc.console.addpacket.json", () -> UTConfigTweaks.MISC.utImprovedEntityTrackerToggle);
put("mixins.tweaks.misc.incurablepotions.json", () -> UTConfigTweaks.MISC.INCURABLE_POTIONS.utIncurablePotionsToggle);
put("mixins.tweaks.misc.lightning.damage.json", () -> UTConfigTweaks.MISC.LIGHTNING.utLightningDamage != 5.0D || UTConfigTweaks.MISC.LIGHTNING.utLightningFireTicks != 8);
Expand Down Expand Up @@ -184,7 +185,6 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.misc.chat.compactmessage.json", () -> UTConfigTweaks.MISC.CHAT.utCompactMessagesToggle);
put("mixins.tweaks.misc.chat.keepsentmessages.json", () -> UTConfigTweaks.MISC.CHAT.utKeepSentMessageHistory);
put("mixins.tweaks.misc.chat.maximumlines.json", () -> UTConfigTweaks.MISC.CHAT.utChatLines != 100);
put("mixins.tweaks.misc.commands.seed.json", () -> UTConfigTweaks.MISC.utCopyWorldSeedToggle);
put("mixins.tweaks.misc.credits.json", () -> UTConfigTweaks.MISC.utSkipCreditsToggle);
put("mixins.tweaks.misc.glint.enchantedbook.json", () -> UTConfigTweaks.MISC.utDisableEnchantmentBookGlint);
put("mixins.tweaks.misc.glint.potion.json", () -> UTConfigTweaks.MISC.utDisablePotionGlint);
Expand Down
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;
}
}

This file was deleted.

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 src/main/java/mod/acgaming/universaltweaks/util/UTCommands.java
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());
}
}
2 changes: 1 addition & 1 deletion src/main/resources/mixins.tweaks.misc.commands.seed.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"client": ["UTCopySeedMixin", "UTFormatSeedMixin"]
"mixins": ["UTFormatSeedMixin"]
}
Loading