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

merge iih + mt hand command in one #84

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions src/main/java/com/gtnewhorizon/gtnhlib/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.client.ClientCommandHandler;

import com.gtnewhorizon.gtnhlib.client.model.ModelLoader;
import com.gtnewhorizon.gtnhlib.commands.ItemInHandCommand;
import com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber;
import com.gtnewhorizon.gtnhlib.util.AboveHotbarHUD;

Expand All @@ -32,6 +34,7 @@ public void preInit(FMLPreInitializationEvent event) {
@Override
public void init(FMLInitializationEvent event) {
super.init(event);
ClientCommandHandler.instance.registerCommand(new ItemInHandCommand());
}

@Override
Expand Down
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);
}

}
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 + "Unloc.Name:" + RESET + " [%s]", itemStack.getUnlocalizedName()));
if (UID != null) addChatMessage(String.format(GREEN + "ItemName:" + RESET + " [%s]", UID));
Alexdoru marked this conversation as resolved.
Show resolved Hide resolved
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]",
Alexdoru marked this conversation as resolved.
Show resolved Hide resolved
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);
}

}