Skip to content

Commit 9b2950f

Browse files
authored
Fix various grs hand command issue (GregTechCEu#2785)
1 parent 9681c3b commit 9b2950f

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/main/java/gregtech/integration/RecipeCompatUtil.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import gregtech.api.pipenet.block.material.BlockMaterialPipe;
99
import gregtech.api.recipes.Recipe;
1010
import gregtech.api.recipes.RecipeMap;
11+
import gregtech.api.unification.material.Material;
1112
import gregtech.api.util.GTUtility;
1213
import gregtech.common.blocks.BlockCompressed;
1314
import gregtech.common.blocks.BlockFrame;
@@ -23,6 +24,8 @@
2324
import org.jetbrains.annotations.NotNull;
2425
import org.jetbrains.annotations.Nullable;
2526

27+
import java.util.Objects;
28+
2629
/**
2730
* Contains utilities for recipe compatibility with scripting mods
2831
*/
@@ -51,7 +54,11 @@ public static String getFirstOutputString(@NotNull Recipe recipe) {
5154
public static String getMetaItemId(ItemStack item) {
5255
if (item.getItem() instanceof MetaItem) {
5356
MetaItem<?>.MetaValueItem metaValueItem = ((MetaItem<?>) item.getItem()).getItem(item);
54-
if (metaValueItem != null) return metaValueItem.unlocalizedName;
57+
if (metaValueItem != null) {
58+
String nameSpace = Objects.requireNonNull(metaValueItem.getMetaItem().getRegistryName()).getNamespace();
59+
String name = metaValueItem.unlocalizedName;
60+
return nameSpace.equals(GTValues.MODID) ? name : (nameSpace + ":" + name);
61+
}
5562
}
5663
if (item.getItem() instanceof ItemBlock) {
5764
Block block = ((ItemBlock) item.getItem()).getBlock();
@@ -62,14 +69,17 @@ public static String getMetaItemId(ItemStack item) {
6269
mte.metaTileEntityId.getPath() : mte.metaTileEntityId.toString());
6370
}
6471
}
65-
if (block instanceof BlockCompressed) {
66-
return "block" + ((BlockCompressed) block).getGtMaterial(item).toCamelCaseString();
72+
if (block instanceof BlockCompressed blockCompressed) {
73+
Material material = blockCompressed.getGtMaterial(item);
74+
return getRLPrefix(material) + "block" + material.toCamelCaseString();
6775
}
68-
if (block instanceof BlockFrame) {
69-
return "frame" + ((BlockFrame) block).getGtMaterial(item).toCamelCaseString();
76+
if (block instanceof BlockFrame blockFrame) {
77+
Material material = blockFrame.getGtMaterial(item);
78+
return getRLPrefix(material) + "frame" + material.toCamelCaseString();
7079
}
71-
if (block instanceof BlockMaterialPipe blockMaterialPipe) {
72-
return blockMaterialPipe.getPrefix().name + blockMaterialPipe.getItemMaterial(item).toCamelCaseString();
80+
if (block instanceof BlockMaterialPipe<?, ?, ?>blockMaterialPipe) {
81+
Material material = blockMaterialPipe.getItemMaterial(item);
82+
return getRLPrefix(material) + blockMaterialPipe.getPrefix().name + material.toCamelCaseString();
7383
}
7484
}
7585
return null;
@@ -97,6 +107,10 @@ public static TweakerType getPriorityTweaker() {
97107
return TweakerType.NONE;
98108
}
99109

110+
public static String getRLPrefix(Material material) {
111+
return material.getModid().equals(GTValues.MODID) ? "" : material.getModid() + ":";
112+
}
113+
100114
public static boolean isTweakerLoaded() {
101115
return getPriorityTweaker() != TweakerType.NONE;
102116
}

src/main/java/gregtech/integration/groovy/GrSRecipeHelper.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ public static String getRecipeRemoveLine(RecipeMap<?> recipeMap, Recipe recipe)
3737
for (GTRecipeInput fluidIngredient : recipe.getFluidInputs()) {
3838
builder.append(GroovyScriptCodeConverter.asGroovyCode(fluidIngredient.getInputFluidStack(), false));
3939

40-
if (fluidIngredient.getAmount() > 1) {
41-
builder.append(" * ")
42-
.append(fluidIngredient.getAmount());
43-
}
44-
4540
builder.append(", ");
4641
}
4742
builder.delete(builder.length() - 2, builder.length())

src/main/java/gregtech/integration/groovy/GroovyHandCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ public static void onHandCommand(GsHandEvent event) {
3333
}
3434

3535
// tool info
36-
if (stackInHand.getItem() instanceof IGTTool) {
37-
IGTTool tool = (IGTTool) stackInHand.getItem();
36+
if (stackInHand.getItem() instanceof IGTTool tool) {
3837
event.messages.add(
3938
new TextComponentTranslation("gregtech.command.hand.tool_stats", tool.getToolClasses(stackInHand)));
4039
}
4140

4241
// material info
43-
MaterialStack material = OreDictUnifier.getMaterial(stackInHand);
44-
if (material != null) {
45-
String copyText = "material('" + material.material + "')";
42+
MaterialStack ms = OreDictUnifier.getMaterial(stackInHand);
43+
if (ms != null) {
44+
String materialString = RecipeCompatUtil.getRLPrefix(ms.material) + ms.material;
45+
String copyText = "material('" + materialString + "')";
4646
event.messages.add(TextCopyable.translation(copyText, "gregtech.command.hand.material").build()
47-
.appendSibling(new TextComponentString(" " + material.material)
47+
.appendSibling(new TextComponentString(" " + materialString)
4848
.setStyle(new Style().setColor(TextFormatting.GREEN))));
4949
}
5050
// ore prefix info

0 commit comments

Comments
 (0)