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

Add Maintenance and Mufflers #114

Merged
merged 17 commits into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from 14 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
@@ -0,0 +1,9 @@
package gregtech.api.capability;

public class MultiblockDataCodes {
public static final int IS_TAPED = 550;
public static final int STORE_MAINTENANCE = 551;
public static final int STORE_TAPED = 552;
public static final int RECIPE_MAP_INDEX = 553;
public static final int IS_FRONT_FACE_FREE = 554;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gregtech.api.capability.*;
import gregtech.api.metatileentity.MTETrait;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase;
import gregtech.api.recipes.machines.FuelRecipeMap;
import gregtech.api.recipes.recipes.FuelRecipe;
import gregtech.api.util.GTUtility;
Expand Down Expand Up @@ -139,13 +140,35 @@ protected boolean shouldVoidExcessiveEnergy() {
}

private void tryAcquireNewRecipe() {
if (metaTileEntity instanceof MultiblockWithDisplayBase) {

MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity;

// do not run recipes when there are more than 5 maintenance problems
if (controller.hasMaintenanceMechanics() && controller.getNumMaintenanceProblems() > 5)
return;
}

IMultipleTankHandler fluidTanks = this.fluidTank.get();
for (IFluidTank fluidTank : fluidTanks) {
FluidStack tankContents = fluidTank.getFluid();
if (tankContents != null && tankContents.amount > 0) {
int fuelAmountUsed = tryAcquireNewRecipe(tankContents);
if (fuelAmountUsed > 0) {
fluidTank.drain(fuelAmountUsed, true);

if (metaTileEntity instanceof MultiblockWithDisplayBase) {
MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity;
if (previousRecipe != null) {
// output muffler items
if (controller.hasMufflerMechanics())
controller.outputRecoveryItems();

// increase total on time
controller.calculateMaintenance(previousRecipe.getDuration());
}
}

break; //recipe is found and ready to use
}
}
Expand Down Expand Up @@ -211,7 +234,11 @@ protected int calculateFuelAmount(FuelRecipe currentRecipe) {
}

protected int calculateRecipeDuration(FuelRecipe currentRecipe) {
return currentRecipe.getDuration();
int numMaintenanceProblems = (this.metaTileEntity instanceof MultiblockWithDisplayBase) ?
((MultiblockWithDisplayBase) metaTileEntity).getNumMaintenanceProblems() : 0;

// apply maintenance penalties
return (int) (currentRecipe.getDuration() * (1 - 0.1 * numMaintenanceProblems));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.recipes.Recipe;
import net.minecraftforge.items.IItemHandlerModifiable;
Expand Down Expand Up @@ -67,6 +68,28 @@ protected IMultipleTankHandler getOutputTank() {
return controller.getOutputFluidInventory();
}

@Override
protected void trySearchNewRecipe() {
// do not run recipes when there are more than 5 maintenance problems
MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity;
if (controller.hasMaintenanceMechanics() && controller.getNumMaintenanceProblems() > 5)
return;

super.trySearchNewRecipe();
}

@Override
protected int[] calculateOverclock(int EUt, long voltage, int duration) {
// apply maintenance penalties
int numMaintenanceProblems = (this.metaTileEntity instanceof MultiblockWithDisplayBase) ?
((MultiblockWithDisplayBase) metaTileEntity).getNumMaintenanceProblems() : 0;

int[] overclock = super.calculateOverclock(EUt, voltage, duration);
overclock[1] = (int) (duration * (1 + 0.1 * numMaintenanceProblems));

return overclock;
}

@Override
protected boolean setupAndConsumeRecipeInputs(Recipe recipe) {
RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity;
Expand All @@ -77,6 +100,22 @@ protected boolean setupAndConsumeRecipeInputs(Recipe recipe) {
} else return false;
}

@Override
protected void completeRecipe() {
if (metaTileEntity instanceof MultiblockWithDisplayBase) {
MultiblockWithDisplayBase controller = (MultiblockWithDisplayBase) metaTileEntity;

// output muffler items
if (controller.hasMufflerMechanics())
controller.outputRecoveryItems();

// increase total on time
if (controller.hasMaintenanceMechanics())
controller.calculateMaintenance(this.progressTime);
}
super.completeRecipe();
}

@Override
protected long getEnergyStored() {
return getEnergyContainer().getEnergyStored();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/gui/GuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class GuiTextures {
//WIDGET UI RELATED
public static final TextureArea SLIDER_BACKGROUND = TextureArea.fullImage("textures/gui/widget/slider_background.png");
public static final TextureArea SLIDER_ICON = TextureArea.fullImage("textures/gui/widget/slider.png");
public static final TextureArea MAINTENANCE_ICON = TextureArea.fullImage("textures/gui/widget/button_maintenance.png");

//BRONZE
public static final TextureArea BRONZE_BACKGROUND = TextureArea.fullImage("textures/gui/steam/bronze/bronze_gui.png");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package gregtech.api.metatileentity.multiblock;

import gregtech.api.capability.IEnergyContainer;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityMaintenanceHatch;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityMufflerHatch;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityRotorHolder;
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.items.IItemHandlerModifiable;

Expand All @@ -16,9 +19,14 @@ public class MultiblockAbility<T> {
public static final MultiblockAbility<IEnergyContainer> INPUT_ENERGY = new MultiblockAbility<>();
public static final MultiblockAbility<IEnergyContainer> OUTPUT_ENERGY = new MultiblockAbility<>();

public static final MultiblockAbility<MetaTileEntityRotorHolder> ABILITY_ROTOR_HOLDER = new MultiblockAbility<>();

public static final MultiblockAbility<IFluidTank> PUMP_FLUID_HATCH = new MultiblockAbility<>();

public static final MultiblockAbility<IFluidTank> STEAM = new MultiblockAbility<>();
public static final MultiblockAbility<IItemHandlerModifiable> STEAM_IMPORT_ITEMS = new MultiblockAbility<>();
public static final MultiblockAbility<IItemHandlerModifiable> STEAM_EXPORT_ITEMS = new MultiblockAbility<>();

public static final MultiblockAbility<MetaTileEntityMaintenanceHatch> MAINTENANCE_HATCH = new MultiblockAbility<>();
TechLord22 marked this conversation as resolved.
Show resolved Hide resolved
public static final MultiblockAbility<MetaTileEntityMufflerHatch> MUFFLER_HATCH = new MultiblockAbility<>();
}
Loading