Skip to content

Commit 21eccdf

Browse files
ghzdudeZorbatron
andauthored
Port Multiblocks to MUI2 (#2672)
Co-authored-by: Zorbatron <[email protected]>
1 parent b33edac commit 21eccdf

File tree

101 files changed

+5690
-2550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+5690
-2550
lines changed

src/main/java/gregtech/api/capability/GregtechDataCodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public static int assignId() {
9999
public static final int UPDATE_UPWARDS_FACING = assignId();
100100
public static final int UPDATE_FLIP = assignId();
101101
public static final int LOCK_FILL = assignId();
102+
public static final int MUFFLER_OBSTRUCTED = assignId();
102103

103104
// Item Bus Item Stack Auto Collapsing
104105
public static final int TOGGLE_COLLAPSE_ITEMS = assignId();

src/main/java/gregtech/api/capability/IHPCAComponentHatch.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package gregtech.api.capability;
22

3-
import gregtech.api.gui.resources.TextureArea;
3+
import gregtech.api.metatileentity.MetaTileEntity;
4+
import gregtech.api.mui.GTGuiTextures;
5+
6+
import com.cleanroommc.modularui.drawable.UITexture;
47

58
public interface IHPCAComponentHatch {
69

@@ -46,5 +49,17 @@ default void setDamaged(boolean damaged) {}
4649
/**
4750
* The icon for this component in the HPCA's UI. Should be a 13x13 px sprite.
4851
*/
49-
TextureArea getComponentIcon();
52+
default UITexture getComponentIcon() {
53+
return GTGuiTextures.HPCA_ICON_EMPTY_COMPONENT;
54+
}
55+
56+
/**
57+
* The untranslated name of the tile implementing an HPCA component
58+
*/
59+
default String getTileName() {
60+
if (this instanceof MetaTileEntity mte) {
61+
return mte.getMetaFullName();
62+
}
63+
return "";
64+
}
5065
}

src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.jetbrains.annotations.Nullable;
4444

4545
import java.util.ArrayList;
46+
import java.util.Collections;
4647
import java.util.List;
4748

4849
import static gregtech.api.GTValues.ULV;
@@ -70,8 +71,10 @@ public abstract class AbstractRecipeLogic extends MTETrait implements IWorkable,
7071
protected int progressTime;
7172
protected int maxProgressTime;
7273
protected long recipeEUt;
73-
protected List<FluidStack> fluidOutputs;
74-
protected List<ItemStack> itemOutputs;
74+
@NotNull
75+
protected List<FluidStack> fluidOutputs = Collections.emptyList();
76+
@NotNull
77+
protected List<ItemStack> itemOutputs = Collections.emptyList();
7578

7679
protected boolean isActive;
7780
protected boolean workingEnabled = true;
@@ -338,6 +341,10 @@ public void setParallelRecipesPerformed(int amount) {
338341
this.parallelRecipesPerformed = amount;
339342
}
340343

344+
public int getParallelRecipesPerformed() {
345+
return parallelRecipesPerformed;
346+
}
347+
341348
/**
342349
* Update the current running recipe's progress
343350
* <p>
@@ -974,8 +981,8 @@ protected void completeRecipe() {
974981
this.progressTime = 0;
975982
setMaxProgress(0);
976983
this.recipeEUt = 0;
977-
this.fluidOutputs = null;
978-
this.itemOutputs = null;
984+
this.fluidOutputs = Collections.emptyList();
985+
this.itemOutputs = Collections.emptyList();
979986
this.hasNotEnoughEnergy = false;
980987
this.wasActiveAndNeedsUpdate = true;
981988
this.parallelRecipesPerformed = 0;
@@ -1135,8 +1142,8 @@ public void invalidate() {
11351142
progressTime = 0;
11361143
maxProgressTime = 0;
11371144
recipeEUt = 0;
1138-
fluidOutputs = null;
1139-
itemOutputs = null;
1145+
fluidOutputs = Collections.emptyList();
1146+
itemOutputs = Collections.emptyList();
11401147
parallelRecipesPerformed = 0;
11411148
isOutputsFull = false;
11421149
invalidInputsForRecipes = false;
@@ -1211,7 +1218,7 @@ public void deserializeNBT(@NotNull NBTTagCompound compound) {
12111218
this.itemOutputs.add(new ItemStack(itemOutputsList.getCompoundTagAt(i)));
12121219
}
12131220
NBTTagList fluidOutputsList = compound.getTagList("FluidOutputs", Constants.NBT.TAG_COMPOUND);
1214-
this.fluidOutputs = new ArrayList<>();
1221+
this.fluidOutputs = new ArrayList<>(fluidOutputsList.tagCount());
12151222
for (int i = 0; i < fluidOutputsList.tagCount(); i++) {
12161223
this.fluidOutputs.add(FluidStack.loadFluidStackFromNBT(fluidOutputsList.getCompoundTagAt(i)));
12171224
}

src/main/java/gregtech/api/capability/impl/BoilerRecipeLogic.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public class BoilerRecipeLogic extends AbstractRecipeLogic implements ICategoryO
4949

5050
public BoilerRecipeLogic(MetaTileEntityLargeBoiler tileEntity) {
5151
super(tileEntity, null);
52-
this.fluidOutputs = Collections.emptyList();
53-
this.itemOutputs = Collections.emptyList();
5452
}
5553

5654
@Override

src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
public class MultiblockFuelRecipeLogic extends MultiblockRecipeLogic {
2424

2525
protected long totalContinuousRunningTime;
26+
private int previousDuration = 0;
2627

2728
public MultiblockFuelRecipeLogic(RecipeMapMultiblockController tileEntity) {
2829
super(tileEntity);
@@ -127,18 +128,24 @@ public String getRecipeFluidInputInfo() {
127128
} else {
128129
recipe = previousRecipe;
129130
}
131+
previousDuration = recipe.getDuration();
130132
FluidStack requiredFluidInput = recipe.getFluidInputs().get(0).getInputFluidStack();
131133

132134
int ocAmount = GTUtility.safeCastLongToInt(getMaxVoltage() / recipe.getEUt());
133135
int neededAmount = ocAmount * requiredFluidInput.amount;
134136
if (rotorHolder != null && rotorHolder.hasRotor()) {
135-
neededAmount /= (rotorHolder.getTotalEfficiency() / 100.0);
137+
neededAmount /= (int) (rotorHolder.getTotalEfficiency() / 100.0);
136138
} else if (rotorHolder != null && !rotorHolder.hasRotor()) {
137139
return null;
138140
}
139141
return TextFormatting.RED + TextFormattingUtil.formatNumbers(neededAmount) + "L";
140142
}
141143

144+
@Override
145+
public int getPreviousRecipeDuration() {
146+
return previousDuration;
147+
}
148+
142149
public FluidStack getInputFluidStack() {
143150
// Previous Recipe is always null on first world load, so try to acquire a new recipe
144151
if (previousRecipe == null) {

src/main/java/gregtech/api/fluids/GTFluid.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import gregtech.api.fluids.attribute.FluidAttribute;
55
import gregtech.api.unification.material.Material;
66

7-
import net.minecraft.client.resources.I18n;
87
import net.minecraft.util.ResourceLocation;
98
import net.minecraft.util.text.TextComponentTranslation;
109
import net.minecraftforge.fluids.Fluid;
1110
import net.minecraftforge.fluids.FluidStack;
1211
import net.minecraftforge.fml.relauncher.Side;
1312
import net.minecraftforge.fml.relauncher.SideOnly;
1413

14+
import com.cleanroommc.modularui.api.drawable.IKey;
1515
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
16+
import org.jetbrains.annotations.ApiStatus;
1617
import org.jetbrains.annotations.NotNull;
1718
import org.jetbrains.annotations.Nullable;
1819
import org.jetbrains.annotations.Unmodifiable;
@@ -62,6 +63,8 @@ public GTMaterialFluid(@NotNull String fluidName, ResourceLocation still, Resour
6263
return this.material;
6364
}
6465

66+
@Deprecated
67+
@ApiStatus.ScheduledForRemoval(inVersion = "2.10")
6568
public @NotNull TextComponentTranslation toTextComponentTranslation() {
6669
TextComponentTranslation localizedName;
6770
String customMaterialTranslation = "fluid." + material.getUnlocalizedName();
@@ -78,22 +81,27 @@ public GTMaterialFluid(@NotNull String fluidName, ResourceLocation still, Resour
7881
return localizedName;
7982
}
8083

81-
@Override
82-
@SideOnly(Side.CLIENT)
83-
public String getLocalizedName(FluidStack stack) {
84-
String localizedName;
84+
public @NotNull IKey getLocalizedKey() {
85+
IKey localizedName;
8586
String customMaterialTranslation = "fluid." + material.getUnlocalizedName();
8687

87-
if (I18n.hasKey(customMaterialTranslation)) {
88-
localizedName = I18n.format(customMaterialTranslation);
88+
if (net.minecraft.util.text.translation.I18n.canTranslate(customMaterialTranslation)) {
89+
localizedName = IKey.lang(customMaterialTranslation);
8990
} else {
90-
localizedName = I18n.format(material.getUnlocalizedName());
91+
localizedName = IKey.lang(material.getUnlocalizedName());
9192
}
9293

9394
if (translationKey != null) {
94-
return I18n.format(translationKey, localizedName);
95+
return IKey.lang(translationKey, localizedName);
9596
}
97+
9698
return localizedName;
9799
}
100+
101+
@Override
102+
@SideOnly(Side.CLIENT)
103+
public String getLocalizedName(FluidStack stack) {
104+
return getLocalizedKey().get();
105+
}
98106
}
99107
}

src/main/java/gregtech/api/gui/widgets/ProgressWidget.java

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import gregtech.api.gui.resources.TextureArea;
66
import gregtech.api.util.Position;
77
import gregtech.api.util.Size;
8+
import gregtech.api.util.function.impl.TimedProgressSupplier;
89
import gregtech.common.ConfigHolder;
910

1011
import net.minecraft.client.renderer.GlStateManager;
@@ -295,38 +296,4 @@ public void drawInForeground(int mouseX, int mouseY) {
295296
}
296297
}
297298
}
298-
299-
public static class TimedProgressSupplier implements DoubleSupplier {
300-
301-
private final int msPerCycle;
302-
private final int maxValue;
303-
private final boolean countDown;
304-
private long startTime;
305-
306-
public TimedProgressSupplier(int ticksPerCycle, int maxValue, boolean countDown) {
307-
this.msPerCycle = ticksPerCycle * 50;
308-
this.maxValue = maxValue;
309-
this.countDown = countDown;
310-
this.startTime = System.currentTimeMillis();
311-
}
312-
313-
public void resetCountdown() {
314-
startTime = System.currentTimeMillis();
315-
}
316-
317-
@Override
318-
public double getAsDouble() {
319-
return calculateTime();
320-
}
321-
322-
private double calculateTime() {
323-
long currentTime = System.currentTimeMillis();
324-
long msPassed = (currentTime - startTime) % msPerCycle;
325-
double currentValue = 1.0 * msPassed * maxValue / msPerCycle;
326-
if (countDown) {
327-
return (maxValue - currentValue) / maxValue;
328-
}
329-
return currentValue / maxValue;
330-
}
331-
}
332299
}

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public GTGuiTheme getUITheme() {
492492
}
493493

494494
@Override
495-
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) {
495+
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManager) {
496496
return null;
497497
}
498498

@@ -892,7 +892,11 @@ private void updateSound() {
892892
if (sound == null) {
893893
return;
894894
}
895-
if (isValid() && isActive()) {
895+
boolean canPlay = isValid() && isActive();
896+
if (this instanceof IControllable controllable) {
897+
canPlay &= controllable.isWorkingEnabled();
898+
}
899+
if (canPlay) {
896900
if (--playSoundCooldown > 0) {
897901
return;
898902
}

src/main/java/gregtech/api/metatileentity/multiblock/FuelMultiblockController.java

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import gregtech.api.capability.IMultipleTankHandler;
66
import gregtech.api.capability.impl.EnergyContainerList;
77
import gregtech.api.capability.impl.MultiblockFuelRecipeLogic;
8+
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIBuilder;
9+
import gregtech.api.mui.sync.FixedIntArraySyncValue;
810
import gregtech.api.recipes.RecipeMap;
911
import gregtech.api.util.GTUtility;
1012
import gregtech.api.util.TextComponentUtil;
@@ -16,8 +18,13 @@
1618
import net.minecraft.util.text.Style;
1719
import net.minecraft.util.text.TextComponentTranslation;
1820
import net.minecraft.util.text.TextFormatting;
21+
import net.minecraftforge.fluids.Fluid;
22+
import net.minecraftforge.fluids.FluidRegistry;
1923
import net.minecraftforge.fluids.FluidStack;
2024

25+
import com.cleanroommc.modularui.api.drawable.IKey;
26+
import com.cleanroommc.modularui.screen.RichTooltip;
27+
import com.cleanroommc.modularui.value.sync.StringSyncValue;
2128
import org.jetbrains.annotations.NotNull;
2229

2330
import java.util.ArrayList;
@@ -41,16 +48,22 @@ protected void initializeAbilities() {
4148
}
4249

4350
@Override
44-
protected void addDisplayText(List<ITextComponent> textList) {
51+
protected void configureDisplayText(MultiblockUIBuilder builder) {
4552
MultiblockFuelRecipeLogic recipeLogic = (MultiblockFuelRecipeLogic) recipeMapWorkable;
4653

47-
MultiblockDisplayText.builder(textList, isStructureFormed())
48-
.setWorkingStatus(recipeLogic.isWorkingEnabled(), recipeLogic.isActive())
54+
builder.setWorkingStatus(recipeLogic.isWorkingEnabled(), recipeLogic.isActive())
4955
.addEnergyProductionLine(getMaxVoltage(), recipeLogic.getRecipeEUt())
5056
.addFuelNeededLine(recipeLogic.getRecipeFluidInputInfo(), recipeLogic.getPreviousRecipeDuration())
5157
.addWorkingStatusLine();
5258
}
5359

60+
@Override
61+
protected void configureWarningText(MultiblockUIBuilder builder) {
62+
builder.addLowDynamoTierLine(isDynamoTierTooLow());
63+
if (hasMaintenanceMechanics())
64+
builder.addMaintenanceProblemLines(getMaintenanceProblems(), true);
65+
}
66+
5467
protected long getMaxVoltage() {
5568
IEnergyContainer energyContainer = recipeMapWorkable.getEnergyContainer();
5669
if (energyContainer != null && energyContainer.getEnergyCapacity() > 0) {
@@ -60,13 +73,6 @@ protected long getMaxVoltage() {
6073
}
6174
}
6275

63-
@Override
64-
protected void addWarningText(List<ITextComponent> textList) {
65-
MultiblockDisplayText.builder(textList, isStructureFormed(), false)
66-
.addLowDynamoTierLine(isDynamoTierTooLow())
67-
.addMaintenanceProblemLines(getMaintenanceProblems());
68-
}
69-
7076
protected boolean isDynamoTierTooLow() {
7177
if (isStructureFormed()) {
7278
IEnergyContainer energyContainer = recipeMapWorkable.getEnergyContainer();
@@ -138,6 +144,7 @@ protected int[] getTotalFluidAmount(FluidStack testStack, IMultipleTankHandler m
138144
return new int[] { fluidAmount, fluidCapacity };
139145
}
140146

147+
@Deprecated
141148
protected void addFuelText(List<ITextComponent> textList) {
142149
// Fuel
143150
int fuelStored = 0;
@@ -170,4 +177,26 @@ protected void addFuelText(List<ITextComponent> textList) {
170177
"0 / 0 L"));
171178
}
172179
}
180+
181+
/**
182+
* @param tooltip the tooltip to populate
183+
* @param amounts the sync value containing an array of [fuel stored, fuel capacity]
184+
* @param fuelNameValue the name of the fuel
185+
*/
186+
protected void createFuelTooltip(@NotNull RichTooltip tooltip, @NotNull FixedIntArraySyncValue amounts,
187+
@NotNull StringSyncValue fuelNameValue) {
188+
if (isStructureFormed()) {
189+
Fluid fluid = fuelNameValue.getStringValue() == null ? null :
190+
FluidRegistry.getFluid(fuelNameValue.getStringValue());
191+
if (fluid == null) {
192+
tooltip.addLine(IKey.lang("gregtech.multiblock.large_combustion_engine.fuel_none"));
193+
} else {
194+
tooltip.addLine(
195+
IKey.lang("gregtech.multiblock.large_combustion_engine.fuel_amount", amounts.getValue(0),
196+
amounts.getValue(1), fluid.getLocalizedName(new FluidStack(fluid, 1))));
197+
}
198+
} else {
199+
tooltip.addLine(IKey.lang("gregtech.multiblock.invalid_structure"));
200+
}
201+
}
173202
}

0 commit comments

Comments
 (0)