Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Coil Bonuses #360

Merged
merged 8 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.logic.IParallelableRecipeLogic;
import gregtech.api.recipes.recipeproperties.RecipePropertyStorage;
import gregtech.api.util.GTUtility;
import gregtech.common.ConfigHolder;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -445,7 +446,7 @@ protected boolean checkCanOverclock(int recipeEUt) {
}

/**
* performs the actual overclocking of voltage and duration
* determines the maximum amount of overclocks for the recipe
*
* @param recipe the recipe to overclock
* @return an int array of {OverclockedEUt, OverclockedDuration}
Expand All @@ -457,15 +458,35 @@ protected int[] performOverclocking(Recipe recipe, boolean negativeEU) {
}

/**
* actually runs the overclocking logic
* converts the recipe's values into ones used for overclocking
* @param recipe the recipe to overclock
* @param maxOverclocks the maximum amount of overclocks to perform
* @return an int array of {OverclockedEUt, OverclockedDuration}
*/
protected int[] runOverclockingLogic(@Nonnull Recipe recipe, boolean negativeEU, int maxOverclocks) {
return standardOverclockingLogic(recipe.getEUt() * (negativeEU ? -1 : 1),
return overclockRecipe(recipe.getRecipePropertyStorage(),
recipe.getEUt(),
negativeEU,
getMaxVoltage(),
recipe.getDuration(),
maxOverclocks
);
}

/**
* actually runs the overclocking logic
* @param propertyStorage the recipe's property storage
* @param recipeEUt the EUt of the recipe
* @param negativeEU whether the EU is negative or not
* @param maxVoltage the maximum voltage the recipe is allowed to be run at
* @param duration the duration of the recipe
* @param maxOverclocks the maximum amount of overclocks to perform
* @return an int array of {OverclockedEUt, OverclockedDuration}
*/
protected int[] overclockRecipe(RecipePropertyStorage propertyStorage, int recipeEUt, boolean negativeEU, long maxVoltage, int duration, int maxOverclocks) {
return standardOverclockingLogic(recipeEUt * (negativeEU ? -1 : 1),
maxVoltage,
duration,
getOverclockingDurationDivisor(),
getOverclockingVoltageMultiplier(),
maxOverclocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import gregtech.api.capability.IHeatingCoil;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.recipeproperties.RecipePropertyStorage;
import gregtech.api.recipes.recipeproperties.TemperatureProperty;

import javax.annotation.Nonnull;
Expand All @@ -18,10 +18,14 @@ public HeatingCoilRecipeLogic(RecipeMapMultiblockController metaTileEntity) {
}

@Override
protected int[] runOverclockingLogic(@Nonnull Recipe recipe, boolean negativeEU, int maxOverclocks) {
return heatingCoilOverclockingLogic(recipe.getEUt(), getMaxVoltage(), recipe.getDuration(), maxOverclocks,
protected int[] overclockRecipe(@Nonnull RecipePropertyStorage propertyStorage, int recipeEUt, boolean negativeEU, long maxVoltage, int duration, int maxOverclocks) {
return heatingCoilOverclockingLogic(recipeEUt * (negativeEU ? -1 : 1),
maxVoltage,
duration,
maxOverclocks,
((IHeatingCoil) metaTileEntity).getCurrentTemperature(),
recipe.getProperty(TemperatureProperty.getInstance(), 0));
propertyStorage.getRecipePropertyValue(TemperatureProperty.getInstance(), 0)
);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gregtech.api.recipes.MatchingMode;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMap;
import net.minecraft.util.Tuple;
import net.minecraftforge.items.IItemHandlerModifiable;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -223,21 +224,38 @@ protected boolean prepareRecipeDistinct(Recipe recipe) {
@Override
protected int[] runOverclockingLogic(@Nonnull Recipe recipe, boolean negativeEU, int maxOverclocks) {
// apply maintenance penalties
MultiblockWithDisplayBase displayBase = this.metaTileEntity instanceof MultiblockWithDisplayBase ? (MultiblockWithDisplayBase) metaTileEntity : null;
int numMaintenanceProblems = displayBase == null ? 0 : displayBase.getNumMaintenanceProblems();
Tuple<Integer, Double> maintenanceValues = getMaintenanceValues();

int[] overclock = null;
if (maintenanceValues.getSecond() != 1.0)
overclock = overclockRecipe(recipe.getRecipePropertyStorage(), recipe.getEUt(), negativeEU, getMaxVoltage(),
(int) Math.round(recipe.getDuration() * maintenanceValues.getSecond()), maxOverclocks);

if (overclock == null)
overclock = overclockRecipe(recipe.getRecipePropertyStorage(), recipe.getEUt(), negativeEU, getMaxVoltage(), recipe.getDuration(), maxOverclocks);

if (maintenanceValues.getFirst() > 0)
overclock[1] = (int) (overclock[1] * (1 + 0.1 * maintenanceValues.getFirst()));

return overclock;
}

@Override
protected int[] performOverclocking(Recipe recipe, boolean negativeEU) {
int maxOverclocks = getOverclockingTier(getMaxVoltage()) - 1; // exclude ULV overclocking

return runOverclockingLogic(recipe, negativeEU, maxOverclocks);
}

protected Tuple<Integer, Double> getMaintenanceValues() {
MultiblockWithDisplayBase displayBase = this.metaTileEntity instanceof MultiblockWithDisplayBase ? (MultiblockWithDisplayBase) metaTileEntity : null;
int numMaintenanceProblems = displayBase == null ? 0 : displayBase.getNumMaintenanceProblems();
double durationMultiplier = 1.0D;
if (displayBase != null && displayBase.hasMaintenanceMechanics()) {
IMaintenanceHatch hatch = displayBase.getAbilities(MultiblockAbility.MAINTENANCE_HATCH).get(0);
double durationMultiplier = hatch.getDurationMultiplier();
if (durationMultiplier != 1.0) {
overclock = standardOverclockingLogic(recipe.getEUt() * (negativeEU ? -1 : 1), getMaxVoltage(), (int) Math.round(recipe.getDuration() * durationMultiplier), getOverclockingDurationDivisor(), getOverclockingVoltageMultiplier(), maxOverclocks);
}
durationMultiplier = hatch.getDurationMultiplier();
}
if (overclock == null) overclock = super.runOverclockingLogic(recipe, negativeEU, maxOverclocks);
overclock[1] = (int) (overclock[1] * (1 + 0.1 * numMaintenanceProblems));

return overclock;
return new Tuple<>(numMaintenanceProblems, durationMultiplier);
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/recipes/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ public int getPropertyCount() {
return recipePropertyStorage.getSize();
}

public RecipePropertyStorage getRecipePropertyStorage() {
return recipePropertyStorage;
}

///////////////////////////////////////////////////////////
// Chanced Output //
///////////////////////////////////////////////////////////
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/gregtech/common/blocks/BlockWireCoil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -36,16 +37,25 @@ public BlockWireCoil() {
public void addInformation(@Nonnull ItemStack itemStack, @Nullable World worldIn, List<String> lines, @Nonnull ITooltipFlag tooltipFlag) {
super.addInformation(itemStack, worldIn, lines, tooltipFlag);

// noinspection rawtypes, unchecked
VariantItemBlock itemBlock = (VariantItemBlock<CoilType, BlockWireCoil>) itemStack.getItem();
IBlockState stackState = itemBlock.getBlockState(itemStack);
CoilType coilType = getState(stackState);

lines.add(I18n.format("tile.wire_coil.tooltip_ebf"));
lines.add(I18n.format("tile.wire_coil.tooltip_heat", coilType.coilTemperature));
lines.add("");
lines.add(I18n.format("tile.wire_coil.tooltip_smelter"));
lines.add(I18n.format("tile.wire_coil.tooltip_level", coilType.level));
lines.add(I18n.format("tile.wire_coil.tooltip_discount", coilType.energyDiscount));

if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
int coilTier = coilType.ordinal();
lines.add(I18n.format("tile.wire_coil.tooltip_smelter"));
lines.add(I18n.format("tile.wire_coil.tooltip_parallel_smelter", coilType.level * 32));
lines.add(I18n.format("tile.wire_coil.tooltip_energy_smelter", Math.max(1, 16 / coilType.energyDiscount)));
lines.add(I18n.format("tile.wire_coil.tooltip_pyro"));
lines.add(I18n.format("tile.wire_coil.tooltip_speed_pyro", coilTier == 0 ? 75 : 50 * (coilTier + 1)));
lines.add(I18n.format("tile.wire_coil.tooltip_cracking"));
lines.add(I18n.format("tile.wire_coil.tooltip_energy_cracking", 100 - 5 * coilTier));
} else {
lines.add(I18n.format("gregtech.tooltip.hold_shift"));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
package gregtech.common.metatileentities.multi.electric;

import gregtech.api.capability.impl.MultiblockRecipeLogic;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntityHolder;
import gregtech.api.metatileentity.multiblock.IMultiblockPart;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.pattern.BlockPattern;
import gregtech.api.pattern.FactoryBlockPattern;
import gregtech.api.pattern.PatternMatchContext;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMaps;
import gregtech.client.renderer.ICubeRenderer;
import gregtech.client.renderer.texture.Textures;
import gregtech.common.blocks.BlockMetalCasing;
import gregtech.common.blocks.BlockWireCoil.CoilType;
import gregtech.common.blocks.MetaBlocks;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;

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

public class MetaTileEntityCrackingUnit extends RecipeMapMultiblockController {

private int coilTier;

public MetaTileEntityCrackingUnit(ResourceLocation metaTileEntityId) {
super(metaTileEntityId, RecipeMaps.CRACKING_RECIPES);
this.recipeMapWorkable = new CrackingUnitWorkableHandler(this);
}

@Override
Expand All @@ -35,9 +48,9 @@ protected BlockPattern createStructurePattern() {
.aisle("HCHCH", "H###H", "HCHCH")
.aisle("HCHCH", "HCOCH", "HCHCH")
.where('O', selfPredicate())
.where('H', states(getCasingState()).setMinGlobalLimited(20).or(autoAbilities()))
.where('H', states(getCasingState()).setMinGlobalLimited(12).or(autoAbilities()))
.where('#', air())
.where('C', states(getCoilState()))
.where('C', heatingCoils())
.build();
}

Expand All @@ -46,17 +59,68 @@ public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) {
return Textures.CLEAN_STAINLESS_STEEL_CASING;
}

protected IBlockState getCoilState() {
return MetaBlocks.WIRE_COIL.getState(CoilType.CUPRONICKEL);
}

protected IBlockState getCasingState() {
return MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.STAINLESS_CLEAN);
}

@Override
protected void addDisplayText(List<ITextComponent> textList) {
super.addDisplayText(textList);
if (isStructureFormed())
textList.add(new TextComponentTranslation("gregtech.multiblock.cracking_unit.energy", 100 - 5 * coilTier));
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
tooltip.add(I18n.format("gregtech.machine.cracker.tooltip.1"));
}

@Nonnull
@Override
protected ICubeRenderer getFrontOverlay() {
return Textures.CRACKING_UNIT_OVERLAY;
}

@Override
protected void formStructure(PatternMatchContext context) {
super.formStructure(context);
Object type = context.get("CoilType");
if (type instanceof CoilType)
this.coilTier = ((CoilType) type).ordinal();
else
this.coilTier = 0;
}

@Override
public void invalidateStructure() {
super.invalidateStructure();
this.coilTier = -1;
}

protected int getCoilTier() {
return this.coilTier;
}

@SuppressWarnings("InnerClassMayBeStatic")
private class CrackingUnitWorkableHandler extends MultiblockRecipeLogic {

public CrackingUnitWorkableHandler(RecipeMapMultiblockController tileEntity) {
super(tileEntity);
}

@Override
protected int[] performOverclocking(Recipe recipe, boolean negativeEU) {
int[] overclock = super.performOverclocking(recipe, negativeEU);

int coilTier = ((MetaTileEntityCrackingUnit) metaTileEntity).getCoilTier();
if (coilTier == -1)
return overclock;

overclock[0] *= 1.0f - coilTier / 20; // each coil above cupronickel (coilTier = 0) uses 5% less energy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coilTier / 20 is always 0 because it's an int. coilTier / 20.0 works.
I think we can even make it 10% discount per coil tier. That will be good for Gregicality.

overclock[0] = Math.max(1, overclock[0]);

return overclock;
}
}
}
Loading