Skip to content

Commit

Permalink
/gt hand improvements (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 authored Apr 6, 2022
1 parent dee9333 commit 38c86ed
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 75 deletions.
1 change: 0 additions & 1 deletion src/main/java/gregtech/api/util/CTRecipeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static String getMetaItemId(ItemStack item) {
return ((BlockMaterialPipe<?, ?, ?>) block).getPrefix().name + ((BlockMaterialPipe<?, ?, ?>) block).getItemMaterial(item).toCamelCaseString();
}
}

return null;
}

Expand Down
74 changes: 47 additions & 27 deletions src/main/java/gregtech/common/command/CommandHand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import gregtech.api.items.toolitem.ToolMetaItem;
import gregtech.api.items.toolitem.ToolMetaItem.MetaToolValueItem;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.unification.stack.MaterialStack;
import gregtech.api.util.CTRecipeHelper;
import gregtech.api.util.ClipboardUtil;
import net.minecraft.command.CommandBase;
Expand All @@ -16,10 +18,7 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
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.*;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.ClickEvent.Action;
import net.minecraft.util.text.event.HoverEvent;
Expand All @@ -32,6 +31,7 @@
import java.util.Set;

public class CommandHand extends CommandBase {

@Nonnull
@Override
public String getName() {
Expand All @@ -41,26 +41,29 @@ public String getName() {
@Nonnull
@Override
public String getUsage(@Nonnull ICommandSender sender) {
return "gregtech.command.util.hand.usage";
return "gregtech.command.hand.usage";
}

@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args) throws CommandException {
if (sender instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) sender;
ItemStack stackInHand = player.inventory.getCurrentItem();
ItemStack stackInHand = player.getHeldItemMainhand();
if (stackInHand.isEmpty()) {
throw new CommandException("gregtech.command.util.hand.no_item");
stackInHand = player.getHeldItemOffhand();
if (stackInHand.isEmpty()) {
throw new CommandException("gregtech.command.hand.no_item");
}
}
String registryName = stackInHand.getItem().getRegistryName().toString();
ClickEvent itemNameEvent = new ClickEvent(Action.OPEN_URL, registryName);
player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.item_id", registryName, stackInHand.getItemDamage())
player.sendMessage(new TextComponentTranslation("gregtech.command.hand.item_id", registryName, stackInHand.getItemDamage())
.setStyle(new Style().setClickEvent(itemNameEvent)));

IElectricItem electricItem = stackInHand.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
IFluidHandlerItem fluidHandlerItem = stackInHand.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (electricItem != null) {
player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.electric",
player.sendMessage(new TextComponentTranslation("gregtech.command.hand.electric",
electricItem.getCharge(),
electricItem.getMaxCharge(),
electricItem.getTier(),
Expand All @@ -71,45 +74,60 @@ public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sen
for (IFluidTankProperties properties : fluidHandlerItem.getTankProperties()) {
FluidStack contents = properties.getContents();
String fluidName = contents == null ? "empty" : contents.getFluid().getName();
ClickEvent fluidClickEvent = new ClickEvent(Action.OPEN_URL, fluidName);
player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.fluid",
fluidName,
player.sendMessage(new TextComponentTranslation("gregtech.command.hand.fluid",
contents == null ? 0 : contents.amount,
properties.getCapacity(),
Boolean.toString(properties.canFill()), Boolean.toString(properties.canDrain()))
.setStyle(new Style().setClickEvent(fluidClickEvent)));
Boolean.toString(properties.canFill()), Boolean.toString(properties.canDrain())));
if (contents != null) {
player.sendMessage(new TextComponentTranslation("gregtech.command.hand.fluid2", fluidName).appendSibling(new TextComponentString(" " + fluidName).setStyle(new Style().setColor(TextFormatting.GREEN)))
.setStyle(getCopyStyle("<liquid:" + fluidName + ">", false)));
}
}
}

String id = CTRecipeHelper.getMetaItemId(stackInHand);
if (id != null) {
String ctId = "<metaitem:" + id + ">";
ClipboardUtil.copyToClipboard(player, ctId);
player.sendMessage(new TextComponentTranslation("gregtech.command.hand.meta_item", id).appendSibling(new TextComponentString(" " + id).setStyle(new Style().setColor(TextFormatting.GREEN)))
.setStyle(getCopyStyle(ctId, true)));
}

if (stackInHand.getItem() instanceof MetaItem) {
MetaItem<?> metaItem = (MetaItem<?>) stackInHand.getItem();
MetaValueItem metaValueItem = metaItem.getItem(stackInHand);
if (metaValueItem != null) {
// tool info
if (metaValueItem instanceof ToolMetaItem.MetaToolValueItem) {
IToolStats toolStats = ((MetaToolValueItem) metaValueItem).getToolStats();
player.sendMessage(new TextComponentTranslation("gregtech.command.util.hand.tool_stats", toolStats.getClass().getName()));
player.sendMessage(new TextComponentTranslation("gregtech.command.hand.tool_stats", toolStats.getClass().getName()));
}
}
}

String id = CTRecipeHelper.getMetaItemId(stackInHand);
if (id != null) {
String ctId = "<metaitem:" + id + ">";
ClipboardUtil.copyToClipboard(player, ctId);
player.sendMessage(new TextComponentString("MetaItem Id: ").appendSibling(new TextComponentString(id).setStyle(new Style().setColor(TextFormatting.GREEN)))
.setStyle(getCopyStyle(ctId, true)));
// material info
MaterialStack material = OreDictUnifier.getMaterial(stackInHand);
if (material != null) {
player.sendMessage(new TextComponentTranslation("gregtech.command.hand.material").appendSibling(new TextComponentString(" " + material.material).setStyle(new Style().setColor(TextFormatting.GREEN)))
.setStyle(getCopyStyle("<material:" + material.material + ">", false)));
}
// ore prefix info
OrePrefix orePrefix = OreDictUnifier.getPrefix(stackInHand);
if (orePrefix != null) {
player.sendMessage(new TextComponentTranslation("gregtech.command.hand.ore_prefix").appendSibling(new TextComponentString(" " + orePrefix.name).setStyle(new Style().setColor(TextFormatting.GREEN)))
.setStyle(getCopyStyle(orePrefix.name, false)));
}

Set<String> oreDicts = OreDictUnifier.getOreDictionaryNames(stackInHand);
if (!oreDicts.isEmpty()) {
sender.sendMessage(new TextComponentString("\u00A73OreDict Entries:"));
sender.sendMessage(new TextComponentTranslation("gregtech.command.hand.ore_dict_entries"));
for (String oreName : oreDicts) {
player.sendMessage(new TextComponentString(" \u00A7e- \u00A7b" + oreName)
.setStyle(getCopyStyle("<ore:" + oreName + ">", false)));
}
}
} else {
throw new CommandException("gregtech.command.util.hand.not_a_player");
throw new CommandException("gregtech.command.hand.not_a_player");
}
}

Expand All @@ -118,11 +136,13 @@ public static Style getCopyStyle(String copyMessage, boolean alreadyCopied) {
ClickEvent click = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/gt copy " + copyMessage);
style.setClickEvent(click);

String hoverMsg = alreadyCopied ? "\u00A76" + copyMessage + "\u00A7r was copied to clipboard. \nClick to copy again" : "Click to copy \u00A76" + copyMessage + "\u00A7r";

HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(hoverMsg));
style.setHoverEvent(hoverEvent);
ITextComponent text = alreadyCopied ?
new TextComponentString("").appendSibling(new TextComponentString(copyMessage + " ").setStyle(new Style().setColor(TextFormatting.GOLD)))
.appendSibling(new TextComponentTranslation("gregtech.command.copy.copied_and_click")) :
new TextComponentTranslation("gregtech.command.copy.click_to_copy")
.appendSibling(new TextComponentString(" " + copyMessage).setStyle(new Style().setColor(TextFormatting.GOLD)));

style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, text));
return style;
}
}
8 changes: 6 additions & 2 deletions src/main/java/gregtech/common/command/GregTechCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
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.minecraftforge.server.command.CommandTreeBase;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;

public class GregTechCommand extends CommandTreeBase {
Expand Down Expand Up @@ -55,7 +57,9 @@ public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sen

if (sender.getCommandSenderEntity() instanceof EntityPlayerMP) {
ClipboardUtil.copyToClipboard((EntityPlayerMP) sender.getCommandSenderEntity(), message.toString());
sender.sendMessage(new TextComponentString("Copied [\u00A76" + message.toString() + "\u00A7r] to the clipboard"));
sender.sendMessage(new TextComponentTranslation("gregtech.command.copy.copied_start")
.appendSibling(new TextComponentString(message.toString()).setStyle(new Style().setColor(TextFormatting.GOLD)))
.appendSibling(new TextComponentTranslation("gregtech.command.copy.copied_end")));
}
return;
}
Expand Down
35 changes: 21 additions & 14 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -4824,24 +4824,31 @@ gregtech.multiblock.pyrolyse_oven.speed=Processing Speed: %s%%

gregtech.multiblock.cracking_unit.energy=Energy Usage: %s%%

gregtech.command.usage=Usage: /gregtech <worldgen/util>
gregtech.command.usage=Usage: /gregtech <worldgen/hand/recipecheck>
gregtech.command.worldgen.usage=Usage: /gregtech worldgen <reload>
gregtech.command.worldgen.reload.usage=Usage: /gregtech worldgen reload
gregtech.command.worldgen.reload.success=Worldgen successfully reloaded from config.
gregtech.command.worldgen.reload.failed=Worldgen reload failed. Check console for errors.
gregtech.command.util.usage=Usage: /gregtech util <hand>
gregtech.command.util.hand.usage=Usage: /gregtech util hand
gregtech.command.util.hand.item_id=Item: %s (Metadata: %d)
gregtech.command.util.hand.electric=Electric Info: %d / %d EU - Tier: %d; Is Battery: %s
gregtech.command.util.hand.fluid=Fluid Info: %s %d / %d L; Can Fill: %s; Can Drain: %s
gregtech.command.util.hand.material_meta_item=Ore Prefix: %s; Material: %s
gregtech.command.util.hand.tool_stats=Tool Stats Class: %s
gregtech.command.util.hand.not_a_player=This command is only usable by a player.
gregtech.command.util.hand.no_item=You must hold something in mainhand before executing this command.
gregtech.command.util.recipecheck.usage=Usage: /gregtech recipecheck
gregtech.command.util.recipecheck.begin=Starting recipe conflict check...
gregtech.command.util.recipecheck.end=Recipe conflict check found %d possible conflicts. Check the server log for more info
gregtech.command.util.recipecheck.end_no_conflicts=No recipe conflicts found!
gregtech.command.hand.usage=Usage: /gregtech hand
gregtech.command.hand.item_id=Item: %s (Metadata: %d)
gregtech.command.hand.electric=Electric Info: %d / %d EU - Tier: %d; Is Battery: %s
gregtech.command.hand.fluid=Fluid Info: %d / %d L; Can Fill: %s; Can Drain: %s
gregtech.command.hand.fluid2=Fluid Id:
gregtech.command.hand.material=Material Id:
gregtech.command.hand.ore_prefix=Ore prefix:
gregtech.command.hand.meta_item=MetaItem Id:
gregtech.command.hand.ore_dict_entries=§3Ore dictionary entries:
gregtech.command.hand.tool_stats=Tool Stats Class: %s
gregtech.command.hand.not_a_player=This command is only usable by a player.
gregtech.command.hand.no_item=You must hold something in main hand or off hand before executing this command.
gregtech.command.recipecheck.usage=Usage: /gregtech recipecheck
gregtech.command.recipecheck.begin=Starting recipe conflict check...
gregtech.command.recipecheck.end=Recipe conflict check found %d possible conflicts. Check the server log for more info
gregtech.command.recipecheck.end_no_conflicts=No recipe conflicts found!
gregtech.command.copy.copied_and_click=copied to clipboard. Click to copy again
gregtech.command.copy.click_to_copy=Click to copy
gregtech.command.copy.copied_start=Copied [
gregtech.command.copy.copied_end=] to the clipboard

gregtech.chat.cape=§5Congrats: you just unlocked a new cape! See the Cape Selector terminal app to use it.§r

Expand Down
41 changes: 25 additions & 16 deletions src/main/resources/assets/gregtech/lang/ru_ru.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2368,22 +2368,31 @@ gregtech.multiblock.turbine.low_rotor_durability=ВНИМАНИЕ: Прочно
gregtech.multiblock.large_boiler.temperature=Температура: %s / %s C
gregtech.multiblock.large_boiler.steam_output=Выход пара: %s мВ/т

gregtech.command.usage=Применение: /gregtech <worldgen/util>
gregtech.command.worldgen.usage=Применение: /gregtech worldgen <reload>
gregtech.command.worldgen.reload.usage=Применение: /gregtech worldgen reload
gregtech.command.worldgen.reload.success=Генератор мира успешно перезагрузился из конфига.
gregtech.command.worldgen.reload.failed=Перезагрузка генератора мира окончилась ошибкой. Проверьте ошибки в консоли.
gregtech.command.util.usage=Применение: /gregtech util <hand>
gregtech.command.util.hand.usage=Применение: /gregtech util hand
gregtech.command.util.hand.item_id=Предмет: %s (Метаданные: %d)
gregtech.command.util.hand.electric=Электрическая информация: %d / %d EU - уровень: %d; Батарея: %s
gregtech.command.util.hand.fluid=Жидкостная информация: %s %d / %d мВ; Может заполнить: %s; Может слить: %s
gregtech.command.util.hand.material_meta_item=Префикс руды: %s; Материал: %s
gregtech.command.util.hand.tool_stats=Класс инструмента: %s
gregtech.command.util.hand.meta_item=Название мета-предмета: %s
gregtech.command.util.hand.not_a_player=Эта команда может использоваться только игроком.
gregtech.command.util.hand.no_item=Перед выполнением этой команды, вы должны держать что-то в основной руке.
gregtech.command.util.recipecheck.usage=Применение: /gregtech recipecheck
gregtech.command.usage=Usage: /gregtech <worldgen/hand/recipecheck>
gregtech.command.worldgen.usage=Usage: /gregtech worldgen <reload>
gregtech.command.worldgen.reload.usage=Usage: /gregtech worldgen reload
gregtech.command.worldgen.reload.success=Worldgen successfully reloaded from config.
gregtech.command.worldgen.reload.failed=Worldgen reload failed. Check console for errors.
gregtech.command.hand.usage=Usage: /gregtech hand
gregtech.command.hand.item_id=Item: %s (Metadata: %d)
gregtech.command.hand.electric=Electric Info: %d / %d EU - Tier: %d; Is Battery: %s
gregtech.command.hand.fluid=Fluid Info: %d / %d L; Can Fill: %s; Can Drain: %s
gregtech.command.hand.fluid2=Fluid Id:
gregtech.command.hand.material=Material Id:
gregtech.command.hand.ore_prefix=Ore prefix:
gregtech.command.hand.meta_item=MetaItem Id:
gregtech.command.hand.ore_dict_entries=§3Ore dictionary entries:
gregtech.command.hand.tool_stats=Tool Stats Class: %s
gregtech.command.hand.not_a_player=This command is only usable by a player.
gregtech.command.hand.no_item=You must hold something in main hand or off hand before executing this command.
gregtech.command.recipecheck.usage=Usage: /gregtech recipecheck
gregtech.command.recipecheck.begin=Starting recipe conflict check...
gregtech.command.recipecheck.end=Recipe conflict check found %d possible conflicts. Check the server log for more info
gregtech.command.recipecheck.end_no_conflicts=No recipe conflicts found!
gregtech.command.copy.copied_and_click=copied to clipboard. Click to copy again
gregtech.command.copy.click_to_copy=Click to copy
gregtech.command.copy.copied_start=Copied [
gregtech.command.copy.copied_end=] to the clipboard

gregtech.machine.locked_safe.name=Закрытый сейф
gregtech.machine.locked_safe.malfunctioning=§cСломан!
Expand Down
Loading

0 comments on commit 38c86ed

Please sign in to comment.