Created
March 30, 2018 00:40
-
-
Save Ruukas97/6e2cb2ac0d844fa9fac4cc8adcbbbb9b to your computer and use it in GitHub Desktop.
Copy item to clipboard in NBTUtil format
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
package ruukas.ftbutilexport; | |
import org.lwjgl.input.Keyboard; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.gui.GuiScreen; | |
import net.minecraft.client.settings.KeyBinding; | |
import net.minecraft.item.ItemStack; | |
import net.minecraftforge.fml.client.registry.ClientRegistry; | |
import net.minecraftforge.fml.common.Mod; | |
import net.minecraftforge.fml.common.Mod.EventHandler; | |
import net.minecraftforge.fml.common.event.FMLInitializationEvent; | |
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | |
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent; | |
@Mod(modid = FTBUtilExport.MODID, name = FTBUtilExport.NAME, version = FTBUtilExport.VERSION, clientSideOnly = true) | |
public class FTBUtilExport { | |
public static final String MODID = "ftbutilexport"; | |
public static final String NAME = "FTBUtil Item Export"; | |
public static final String VERSION = "0.1"; | |
public static KeyBinding[] keybinds; | |
@EventHandler | |
public void init(FMLInitializationEvent event) { | |
keybinds = new KeyBinding[1]; | |
keybinds[0] = new KeyBinding("Copy item to clipboard", Keyboard.KEY_K, "FTBUtil Item Export"); | |
for (KeyBinding k : keybinds) { | |
ClientRegistry.registerKeyBinding(k); | |
} | |
} | |
@Mod.EventBusSubscriber(modid = MODID) | |
public static class KeyEventHandler { | |
@SubscribeEvent | |
public static void onKeyPress(KeyInputEvent event) { | |
if (keybinds[0].isPressed() && Minecraft.getMinecraft().world != null) { | |
ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand(); | |
if (stack == null || stack == ItemStack.EMPTY) { | |
return; | |
} | |
String tag = stack.hasTagCompound() ? stack.getTagCompound().toString() : "{}"; | |
GuiScreen.setClipboardString("{id:\"" + stack.getItem().getRegistryName() + "\",Count:" + stack.getCount() + ",Damage:" + stack.getItemDamage() + ",tag:" + tag + "}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment