-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
124 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); | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
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,87 @@ | ||
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 + "Unloc.Name:" + RESET + " [%s]", itemStack.getUnlocalizedName())); | ||
if (UID != null) addChatMessage(String.format(GREEN + "ItemName:" + RESET + " [%s]", UID)); | ||
addChatMessage(String.format(GREEN + "ItemMeta:" + RESET + " [%s]", itemStack.getItemDamage())); | ||
printFluidContent(itemStack); | ||
addChatMessage(String.format(GREEN + "ClassName:" + RESET + " [%s]", itemStack.getItem().getClass())); | ||
addChatMessage(String.format(GREEN + "NBT Tag:" + RESET + " [%s]", itemStack.stackTagCompound == null ? "null" : itemStack.stackTagCompound.toString())); | ||
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); | ||
} | ||
|
||
} |