Skip to content

Commit

Permalink
Add Maintenance and Mufflers (#114)
Browse files Browse the repository at this point in the history
* add maintenance hatches

* fix crash

* add internal maintenance system into controllers

* add maintenance hatches to multiblocks

* fix tape overlay

* add maintenance and duct tape recipes

* start work on mufflers

* fix large gas turbine not forming

* turbine work

* shift clipboard TE id

* add maintenance and muffler functionality to workables

* add muffler recipes and tooltips

* fix muffler outputting to one slot

* use interfaces for mufflers and maintenance in api code

* fix bad lce structure

* clean up maintenance hatch handling

Co-authored-by: DStrand1 <dane@strandboge.com>
  • Loading branch information
TechLord22 and serenibyss authored Aug 29, 2021
1 parent cbc2ea4 commit 62cc800
Show file tree
Hide file tree
Showing 65 changed files with 1,484 additions and 146 deletions.
37 changes: 37 additions & 0 deletions src/main/java/gregtech/api/capability/IMaintenanceHatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gregtech.api.capability;

import net.minecraft.util.Tuple;

public interface IMaintenanceHatch {

/**
*
* @return int corresponding to maintenance hatch type, bounded [0,3)
*/
int getType();

/**
* Sets this Maintenance Hatch as being duct taped
* @param isTaped is the state of the hatch being taped or not
*/
void setTaped(boolean isTaped);

/**
* Stores maintenance data to this MetaTileEntity
* @param maintenanceProblems is the byte value representing the problems
* @param timeActive is the int value representing the total time the parent multiblock has been active
*/
void storeMaintenanceData(byte maintenanceProblems, int timeActive);

/**
*
* @return whether this maintenance hatch has maintenance data
*/
boolean hasMaintenanceData();

/**
* reads this MetaTileEntity's maintenance data
* @return Tuple of Byte, Integer corresponding to the maintenance problems, and total time active
*/
Tuple<Byte, Integer> readMaintenanceData();
}
15 changes: 15 additions & 0 deletions src/main/java/gregtech/api/capability/IMufflerHatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gregtech.api.capability;

import net.minecraft.item.ItemStack;

import java.util.List;

public interface IMufflerHatch {

void recoverItemsTable(List<ItemStack> recoveryItems);

/**
* @return true if front face is free and contains only air blocks in 1x1 area
*/
boolean isFrontFaceFree();
}
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;
}
29 changes: 28 additions & 1 deletion src/main/java/gregtech/api/capability/impl/FuelRecipeLogic.java
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.api.capability.IMaintenanceHatch;
import gregtech.api.capability.IMufflerHatch;
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<IMaintenanceHatch> MAINTENANCE_HATCH = new MultiblockAbility<>();
public static final MultiblockAbility<IMufflerHatch> MUFFLER_HATCH = new MultiblockAbility<>();
}
Loading

0 comments on commit 62cc800

Please sign in to comment.