aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
authorGlease <4586901+Glease@users.noreply.github.com>2021-07-19 19:25:36 +0800
committerGlease <4586901+Glease@users.noreply.github.com>2021-07-30 14:41:39 +0800
commit875ff766ce3801918c9d726a8a14a6710e655147 (patch)
treeab77b5cb6a101d6c572a38af340912d6ca10112e /src/main/java/gregtech/api
parentbfe1836ddc069653d9af9d59008ec23f4dcb6c05 (diff)
downloadGT5-Unofficial-875ff766ce3801918c9d726a8a14a6710e655147.tar.gz
GT5-Unofficial-875ff766ce3801918c9d726a8a14a6710e655147.tar.bz2
GT5-Unofficial-875ff766ce3801918c9d726a8a14a6710e655147.zip
Make block hint text more informative
Also migrated from defer to lazy where possible Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java38
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java200
3 files changed, 209 insertions, 31 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java
index c84ca61eec..5499e756ba 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java
@@ -6,7 +6,7 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import net.minecraft.item.ItemStack;
-import static com.gtnewhorizon.structurelib.structure.StructureUtility.defer;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
@@ -16,7 +16,8 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder;
* A simple 3x3x3 hollow cubic multiblock, that can be arbitrarily rotated, made of a single type of machine casing and accepts hatches everywhere.
* Controller will be placed in front center of the structure.
* <p>
- * Note: You cannot use different casing for the same Class. Make a new subclass for it.
+ * Note: You cannot use different casing for the same Class. Make a new subclass for it. You also should not change the casing
+ * dynamically, i.e. it should be a dumb method returning some sort of constant.
* <p>
* Implementation tips:
* 1. To restrict hatches, override {@link #addDynamoToMachineList(IGregTechTileEntity, int)} and its cousins instead of overriding the whole
@@ -28,20 +29,25 @@ import static gregtech.api.util.GT_StructureUtility.ofHatchAdder;
*/
public abstract class GT_MetaTileEntity_CubicMultiBlockBase<T extends GT_MetaTileEntity_CubicMultiBlockBase<T>> extends GT_MetaTileEntity_EnhancedMultiBlockBase<T> {
protected static final String STRUCTURE_PIECE_MAIN = "main";
- protected static final IStructureDefinition<GT_MetaTileEntity_CubicMultiBlockBase<?>> STRUCTURE_DEFINITION = StructureDefinition.<GT_MetaTileEntity_CubicMultiBlockBase<?>>builder()
- .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{
- {"hhh", "hhh", "hhh"},
- {"h-h", "hhh", "hhh"},
- {"hhh", "hhh", "hhh"},
- }))
- .addElement('h', ofChain(
- defer(t -> ofHatchAdder(GT_MetaTileEntity_CubicMultiBlockBase::addToMachineList, t.getHatchTextureIndex(), 1)),
- onElementPass(
- GT_MetaTileEntity_CubicMultiBlockBase::onCorrectCasingAdded,
- defer(GT_MetaTileEntity_CubicMultiBlockBase::getCasingElement)
- )
- ))
- .build();
+ protected static final ClassValue<IStructureDefinition<GT_MetaTileEntity_CubicMultiBlockBase<?>>> STRUCTURE_DEFINITION = new ClassValue<IStructureDefinition<GT_MetaTileEntity_CubicMultiBlockBase<?>>>() {
+ @Override
+ protected IStructureDefinition<GT_MetaTileEntity_CubicMultiBlockBase<?>> computeValue(Class<?> type) {
+ return StructureDefinition.<GT_MetaTileEntity_CubicMultiBlockBase<?>>builder()
+ .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{
+ {"hhh", "hhh", "hhh"},
+ {"h-h", "hhh", "hhh"},
+ {"hhh", "hhh", "hhh"},
+ }))
+ .addElement('h', ofChain(
+ lazy(t -> ofHatchAdder(GT_MetaTileEntity_CubicMultiBlockBase::addToMachineList, t.getHatchTextureIndex(), 1)),
+ onElementPass(
+ GT_MetaTileEntity_CubicMultiBlockBase::onCorrectCasingAdded,
+ lazy(GT_MetaTileEntity_CubicMultiBlockBase::getCasingElement)
+ )
+ ))
+ .build();
+ }
+ };
private int mCasingAmount = 0;
protected GT_MetaTileEntity_CubicMultiBlockBase(int aID, String aName, String aNameRegional) {
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
index a9b50e6662..cc2513f5c2 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
@@ -128,7 +128,7 @@ public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase<T extends GT_Meta
@Override
public String[] getStructureDescription(ItemStack stackSize) {
- return getTooltip().getStructureInformation();
+ return getTooltip().getStructureHint();
}
protected IAlignmentLimits getInitialAlignmentLimits() {
diff --git a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
index e30fe5d606..84d4bbbd48 100644
--- a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
+++ b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
@@ -1,11 +1,18 @@
package gregtech.api.util;
-import java.util.LinkedList;
-import java.util.List;
-
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import gregtech.api.enums.Materials;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
/**
* This makes it easier to build multi tooltips, with a standardized format. <br>
* Info section order should be:<br>
@@ -32,12 +39,16 @@ import net.minecraft.util.StatCollector;
public class GT_Multiblock_Tooltip_Builder {
private static final String TAB = " ";
private static final String COLON = ": ";
-
+ private static final String SEPARATOR = ", ";
+
private final List<String> iLines;
private final List<String> sLines;
-
+ private final List<String> hLines;
+ private final SetMultimap<Integer, String> hBlocks;
+
private String[] iArray;
private String[] sArray;
+ private String[] hArray;
//Localized tooltips
private static final String TT_machineType = StatCollector.translateToLocal("GT5U.MBTT.MachineType");
@@ -58,11 +69,17 @@ public class GT_Multiblock_Tooltip_Builder {
private static final String TT_pps = StatCollector.translateToLocal("GT5U.MBTT.PPS");
private static final String TT_hold = StatCollector.translateToLocal("GT5U.MBTT.Hold");
private static final String TT_todisplay = StatCollector.translateToLocal("GT5U.MBTT.Display");
+ private static final String TT_structurehint = StatCollector.translateToLocal("GT5U.MBTT.StructureHint");
private static final String TT_mod = StatCollector.translateToLocal("GT5U.MBTT.Mod");
+ private static final String TT_air = StatCollector.translateToLocal("GT5U.MBTT.Air");
+ private static final String[] TT_dots = IntStream.range(0, 16).mapToObj(i -> StatCollector.translateToLocal("GT5U.MBTT.Dots." + i)).toArray(String[]::new);
public GT_Multiblock_Tooltip_Builder() {
iLines = new LinkedList<>();
sLines = new LinkedList<>();
+ hLines = new LinkedList<>();
+ hBlocks = Multimaps.newSetMultimap(new HashMap<>(), HashSet::new);
+ hBlocks.put(0, TT_air);
}
/**
@@ -103,11 +120,10 @@ public class GT_Multiblock_Tooltip_Builder {
}
/**
- * Add a line telling you what the machine type is. Usually, this will be the name of a SB version.<br>
- * Machine Type: machine
+ * Add a line telling how much this machine pollutes.
*
- * @param machine
- * Name of the machine type
+ * @param pollution
+ * Amount of pollution per second when active
*
* @return Instance this method was called on.
*/
@@ -307,7 +323,136 @@ public class GT_Multiblock_Tooltip_Builder {
sLines.add(TAB + TT_outputhatch + COLON + info);
return this;
}
-
+
+ /**
+ * Use this method to add a structural part that isn't covered by the other methods.<br>
+ * (indent)name: info
+ * @param name
+ * Name of the hatch or other component.
+ * @param info
+ * Positional information.
+ * @param dots
+ * The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOtherStructurePart(String name, String info, int... dots) {
+ sLines.add(TAB + name + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, name);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Maintenance Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addMaintenanceHatch(String info, int... dots) {
+ sLines.add(TAB + TT_maintenancehatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_maintenancehatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Muffler Hatch: info
+ *
+ * @param info Location where the hatch goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addMufflerHatch(String info, int... dots) {
+ sLines.add(TAB + TT_mufflerhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_mufflerhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Energy Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addEnergyHatch(String info, int... dots) {
+ sLines.add(TAB + TT_energyhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_energyhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Dynamo Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addDynamoHatch(String info, int... dots) {
+ sLines.add(TAB + TT_dynamohatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_dynamohatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Input Bus: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addInputBus(String info, int... dots) {
+ sLines.add(TAB + TT_inputbus + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_inputbus);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Input Hatch: info
+ *
+ * @param info Location where the hatch goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addInputHatch(String info, int... dots) {
+ sLines.add(TAB + TT_inputhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_inputhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Output Bus: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOutputBus(String info, int... dots) {
+ sLines.add(TAB + TT_outputbus + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_outputbus);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Output Hatch: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOutputHatch(String info, int... dots) {
+ sLines.add(TAB + TT_outputhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_outputhatch);
+ return this;
+ }
+
/**
* Use this method to add non-standard structural info.<br>
* (indent)info
@@ -319,6 +464,30 @@ public class GT_Multiblock_Tooltip_Builder {
sLines.add(TAB + info);
return this;
}
+
+ /**
+ * Use this method to add non-standard structural hint. This info will appear before the standard structural hint.
+ * @param info
+ * The line to be added. This should be an entry into minecraft's localization system.
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addStructureHint(String info) {
+ hLines.add(StatCollector.translateToLocal(info));
+ return this;
+ }
+
+ /**
+ * Use this method to add an entry to standard structural hint without creating a corresponding line in structure information
+ * @param name
+ * The name of block This should be an entry into minecraft's localization system.
+ * @param dots
+ * Possible locations of this block
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addStructureHint(String name, int... dots) {
+ for (int dot : dots) hBlocks.put(dot, StatCollector.translateToLocal(name));
+ return this;
+ }
/**
* Call at the very end.<br>
@@ -331,10 +500,10 @@ public class GT_Multiblock_Tooltip_Builder {
public void toolTipFinisher(String mod) {
iLines.add(TT_hold + " " + EnumChatFormatting.BOLD + "[LSHIFT]" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + " " + TT_todisplay);
iLines.add(TT_mod + COLON + EnumChatFormatting.GREEN + mod + EnumChatFormatting.GRAY);
- iArray = new String[iLines.size()];
- sArray = new String[sLines.size()];
- iLines.toArray(iArray);
- sLines.toArray(sArray);
+ hLines.add(TT_structurehint);
+ iArray = iLines.toArray(new String[0]);
+ sArray = sLines.toArray(new String[0]);
+ hArray = Stream.concat(hLines.stream(), hBlocks.asMap().entrySet().stream().map(e -> TT_dots[e.getKey()] + COLON + String.join(SEPARATOR, e.getValue()))).toArray(String[]::new);
}
public String[] getInformation() {
@@ -345,4 +514,7 @@ public class GT_Multiblock_Tooltip_Builder {
return sArray;
}
+ public String[] getStructureHint() {
+ return hArray;
+ }
}