-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge iih + mt hand command in one (#84)
* merge iih + mt hand command in one * remove the nbt tag, it's included in the mt hand line below * address review
- Loading branch information
Showing
3 changed files
with
123 additions
and
0 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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/gtnewhorizon/gtnhlib/commands/GTNHClientCommand.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,34 @@ | ||
package com.gtnewhorizon.gtnhlib.commands; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.command.CommandBase; | ||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.util.ChatComponentText; | ||
import net.minecraft.util.IChatComponent; | ||
|
||
public abstract class GTNHClientCommand extends CommandBase { | ||
|
||
@Override | ||
public boolean canCommandSenderUseCommand(ICommandSender sender) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getCommandUsage(ICommandSender sender) { | ||
return "/" + this.getCommandName(); | ||
} | ||
|
||
protected void addChatMessage(String msg) { | ||
addChatMessage(new ChatComponentText(msg)); | ||
} | ||
|
||
protected void addChatMessage(IChatComponent msg) { | ||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(msg); | ||
} | ||
|
||
protected void copyToClipboard(String s) { | ||
GuiScreen.setClipboardString(s); | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
src/main/java/com/gtnewhorizon/gtnhlib/commands/ItemInHandCommand.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,86 @@ | ||
package com.gtnewhorizon.gtnhlib.commands; | ||
|
||
import static net.minecraft.util.EnumChatFormatting.*; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import net.minecraft.client.entity.EntityClientPlayerMP; | ||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import net.minecraftforge.fluids.IFluidContainerItem; | ||
import net.minecraftforge.oredict.OreDictionary; | ||
|
||
import cpw.mods.fml.common.registry.GameRegistry; | ||
|
||
public class ItemInHandCommand extends GTNHClientCommand { | ||
|
||
@Override | ||
public String getCommandName() { | ||
return "iteminhand"; | ||
} | ||
|
||
@Override | ||
public List<String> getCommandAliases() { | ||
return Collections.singletonList("iih"); | ||
} | ||
|
||
@Override | ||
public void processCommand(ICommandSender iCommandSender, String[] args) { | ||
// spotless:off | ||
if (iCommandSender instanceof EntityClientPlayerMP player) { | ||
ItemStack itemStack = player.getCurrentEquippedItem(); | ||
if (itemStack == null) { | ||
addChatMessage("Hand is empty!"); | ||
return; | ||
} | ||
GameRegistry.UniqueIdentifier UID = GameRegistry.findUniqueIdentifierFor(itemStack.getItem()); | ||
addChatMessage(GREEN.toString() + STRIKETHROUGH + "--------------------" + RESET + " Item info " + GREEN + STRIKETHROUGH + "--------------------"); | ||
addChatMessage(String.format(GREEN + "UnlocalizedName:" + RESET + " [%s]", itemStack.getUnlocalizedName())); | ||
if (UID != null) addChatMessage(String.format(GREEN + "RegistryName:" + RESET + " [%s]", UID)); | ||
addChatMessage(String.format(GREEN + "ItemMeta:" + RESET + " [%s]", itemStack.getItemDamage())); | ||
printFluidContent(itemStack); | ||
addChatMessage(String.format(GREEN + "ClassName:" + RESET + " [%s]", itemStack.getItem().getClass())); | ||
printMTHand(itemStack); | ||
addChatMessage(GREEN.toString() + STRIKETHROUGH + "--------------------------------------------------"); | ||
} | ||
// spotless:on | ||
} | ||
|
||
private void printFluidContent(ItemStack itemStack) { | ||
if (itemStack.getItem() instanceof IFluidContainerItem tFluidContainer) { | ||
FluidStack fluidStack = tFluidContainer.getFluid(itemStack); | ||
if (fluidStack != null) { | ||
String s = String.format( | ||
"FluidID: [%d], UnlocName: [%s], Name: [%s]", | ||
fluidStack.getFluid().getID(), | ||
fluidStack.getFluid().getUnlocalizedName(), | ||
fluidStack.getFluid().getName()); | ||
addChatMessage(String.format(GREEN + "FluidContainer:" + RESET + " [%s]", s)); | ||
} | ||
} | ||
} | ||
|
||
private void printMTHand(ItemStack itemStack) { | ||
StringBuilder result = new StringBuilder(); | ||
result.append('<'); | ||
result.append(Item.itemRegistry.getNameForObject(itemStack.getItem())); | ||
if (itemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { | ||
result.append(":*"); | ||
} else if (itemStack.getItemDamage() > 0) { | ||
result.append(':').append(itemStack.getItemDamage()); | ||
} | ||
result.append('>'); | ||
if (itemStack.getTagCompound() != null) { | ||
result.append(".withTag("); | ||
result.append(itemStack.getTagCompound().toString()); | ||
result.append(")"); | ||
} | ||
String msg = result.toString(); | ||
addChatMessage(GREEN + "mt hand: " + RESET + msg); | ||
copyToClipboard(msg); | ||
} | ||
|
||
} |