Skip to content

Commit

Permalink
fix info provider inaccuracy with boosted EUt (#1928)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 authored Jul 13, 2023
1 parent 2d5ed26 commit 68f67e4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ protected IMultipleTankHandler getOutputTank() {
return metaTileEntity.getExportFluids();
}

/**
* @return true if energy is consumed by this Recipe Logic, otherwise false
*/
public boolean consumesEnergy() {
return true;
}

@Nonnull
@Override
public final String getName() {
Expand Down Expand Up @@ -805,6 +812,13 @@ public int getRecipeEUt() {
return recipeEUt;
}

/**
* @return the current recipe's EU/t for TOP/Waila/Tricorder
*/
public int getInfoProviderEUt() {
return getRecipeEUt();
}

/**
* @return the previous recipe's duration
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public Enum<ParallelLogicType> getParallelLogicType() {
return ParallelLogicType.MULTIPLY; //TODO APPEND_FLUIDS
}

@Override
public boolean consumesEnergy() {
return false;
}

@Override
protected boolean hasEnoughPower(@Nonnull int[] resultOverclock) {
// generators always have enough power to run recipes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public int getParallelLimit() {
return Integer.MAX_VALUE;
}

/**
* Boost the energy production.
* Should not change the state of the workable logic. Only read current values.
*
* @param production the energy amount to boost
* @return the boosted energy amount
*/
protected long boostProduction(long production) {
return production;
}
Expand All @@ -90,6 +97,16 @@ protected boolean drawEnergy(int recipeEUt, boolean simulate) {
} else return false;
}

@Override
public int getInfoProviderEUt() {
return (int) boostProduction(super.getInfoProviderEUt());
}

@Override
public boolean consumesEnergy() {
return false;
}

@Override
public void invalidate() {
super.invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ public List<ITextComponent> getDataInfo() {
));
}
// multi amp recipes: change 0 ? 0 : 1 to 0 ? 0 : amperage
if (workable.getRecipeEUt() > 0) {
if (workable.consumesEnergy()) {
list.add(new TextComponentTranslation("behavior.tricorder.workable_consumption",
new TextComponentTranslation(TextFormattingUtil.formatNumbers(workable.getRecipeEUt())).setStyle(new Style().setColor(TextFormatting.RED)),
new TextComponentTranslation(TextFormattingUtil.formatNumbers(workable.getRecipeEUt() == 0 ? 0 : 1)).setStyle(new Style().setColor(TextFormatting.RED))
new TextComponentTranslation(TextFormattingUtil.formatNumbers(workable.getInfoProviderEUt())).setStyle(new Style().setColor(TextFormatting.RED)),
new TextComponentTranslation(TextFormattingUtil.formatNumbers(workable.getInfoProviderEUt() == 0 ? 0 : 1)).setStyle(new Style().setColor(TextFormatting.RED))
));
} else {
list.add(new TextComponentTranslation("behavior.tricorder.workable_production",
new TextComponentTranslation(TextFormattingUtil.formatNumbers(workable.getRecipeEUt() * -1)).setStyle(new Style().setColor(TextFormatting.RED)),
new TextComponentTranslation(TextFormattingUtil.formatNumbers(workable.getRecipeEUt() == 0 ? 0 : 1)).setStyle(new Style().setColor(TextFormatting.RED))
new TextComponentTranslation(TextFormattingUtil.formatNumbers(workable.getInfoProviderEUt())).setStyle(new Style().setColor(TextFormatting.RED)),
new TextComponentTranslation(TextFormattingUtil.formatNumbers(workable.getInfoProviderEUt() == 0 ? 0 : 1)).setStyle(new Style().setColor(TextFormatting.RED))
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public List<ITextComponent> getDataInfo() {
new TextComponentTranslation(TextFormattingUtil.formatNumbers(energyContainer.getEnergyCapacity())).setStyle(new Style().setColor(TextFormatting.YELLOW))
));

if (recipeMapWorkable.getRecipeEUt() < 0) {
if (!recipeMapWorkable.consumesEnergy()) {
list.add(new TextComponentTranslation("behavior.tricorder.workable_production",
new TextComponentTranslation(TextFormattingUtil.formatNumbers(recipeMapWorkable.getRecipeEUt() * -1)).setStyle(new Style().setColor(TextFormatting.RED)),
new TextComponentTranslation(TextFormattingUtil.formatNumbers(recipeMapWorkable.getRecipeEUt() == 0 ? 0 : 1)).setStyle(new Style().setColor(TextFormatting.RED))
new TextComponentTranslation(TextFormattingUtil.formatNumbers(Math.abs(recipeMapWorkable.getInfoProviderEUt()))).setStyle(new Style().setColor(TextFormatting.RED)),
new TextComponentTranslation(TextFormattingUtil.formatNumbers(recipeMapWorkable.getInfoProviderEUt() == 0 ? 0 : 1)).setStyle(new Style().setColor(TextFormatting.RED))
));
}

list.add(new TextComponentTranslation("behavior.tricorder.multiblock_energy_output",
new TextComponentTranslation(TextFormattingUtil.formatNumbers(energyContainer.getOutputVoltage())).setStyle(new Style().setColor(TextFormatting.YELLOW)),
new TextComponentTranslation(GTValues.VN[GTUtility.getTierByVoltage(energyContainer.getOutputVoltage())]).setStyle(new Style().setColor(TextFormatting.YELLOW))
));
list.add(new TextComponentTranslation("behavior.tricorder.multiblock_energy_output",
new TextComponentTranslation(TextFormattingUtil.formatNumbers(energyContainer.getOutputVoltage())).setStyle(new Style().setColor(TextFormatting.YELLOW)),
new TextComponentTranslation(GTValues.VN[GTUtility.getTierByVoltage(energyContainer.getOutputVoltage())]).setStyle(new Style().setColor(TextFormatting.YELLOW))
));
}

if (ConfigHolder.machines.enableMaintenance && hasMaintenanceMechanics()) {
list.add(new TextComponentTranslation("behavior.tricorder.multiblock_maintenance",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected NBTTagCompound getNBTData(AbstractRecipeLogic capability, NBTTagCompou
NBTTagCompound subTag = new NBTTagCompound();
subTag.setBoolean("Working", capability.isWorking());
if (capability.isWorking()) {
subTag.setInteger("RecipeEUt", capability.getRecipeEUt());
subTag.setInteger("RecipeEUt", capability.getInfoProviderEUt());
}
tag.setTag("gregtech.AbstractRecipeLogic", subTag);
return tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void addProbeInfo(@Nonnull AbstractRecipeLogic capability, @Nonnull IP
if (capability instanceof PrimitiveRecipeLogic) {
return; // do not show info for primitive machines, as they are supposed to appear powerless
}
int EUt = capability.getRecipeEUt();
int EUt = capability.getInfoProviderEUt();
int absEUt = Math.abs(EUt);
String text = null;

Expand Down

0 comments on commit 68f67e4

Please sign in to comment.