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

Primitive Multi Rewrite #85

Merged
merged 6 commits into from
Aug 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
6 changes: 5 additions & 1 deletion CHANGELOG-GTCEU.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
### CraftTweaker
- Materials can now automatically generate IDs
- Be careful, as changing the order of this will cause items in-world to disappear

- Coke Oven and PBF have normal RecipeMaps now, instead of using custom ones

### Removals
- Potion Fluids placeable in-world were removed
Expand Down Expand Up @@ -210,3 +210,7 @@
- OrePrefix is no longer an Enum, and can easily be added to by addons
- Shaped and Shapeless Recipe methods in `ModHandler` can now accept more types
- `debug` config will now log failed recipe removals and additions
- There is now a "PrimitiveMultiblockController" base class, which uses a normal RecipeMap. When paired with the `PrimitiveRecipeBuilder`, it will:
- Allow recipes to be run without power
- (by default) Initialize inventory for items and fluids to the Controller instead of Multiblock Parts (overridable)
- Hide the EU/t and Total EU info from the JEI page
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package gregtech.api.capability.impl;

import gregtech.api.GTValues;
import gregtech.api.metatileentity.multiblock.RecipeMapPrimitiveMultiblockController;
import gregtech.api.recipes.RecipeMap;

/**
* Recipe Logic for a Multiblock that does not require power.
*/
public class PrimitiveRecipeLogic extends AbstractRecipeLogic {

public PrimitiveRecipeLogic(RecipeMapPrimitiveMultiblockController tileEntity, RecipeMap<?> recipeMap) {
super(tileEntity, recipeMap);
}

@Override
protected long getEnergyStored() {
return Integer.MAX_VALUE;
}

@Override
protected long getEnergyCapacity() {
return Integer.MAX_VALUE;
}

@Override
protected boolean drawEnergy(int recipeEUt) {
return true; // spoof energy being drawn
}

@Override
protected long getMaxVoltage() {
return GTValues.LV;
}

@Override
protected int[] calculateOverclock(int EUt, long voltage, int duration) {
return new int[]{1, duration};
}

@Override
protected int getOverclockingTier(long voltage) {
return GTValues.LV; // just return something reasonable
}

/**
* Used to reset cached values in the Recipe Logic on structure deform
*/
public void invalidate() {
lastItemInputs = null;
lastFluidInputs = null;
previousRecipe = null;
progressTime = 0;
maxProgressTime = 0;
recipeEUt = 0;
fluidOutputs = null;
itemOutputs = null;
setActive(false); // this marks dirty for us
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gregtech.api.metatileentity.multiblock;

import gregtech.api.capability.impl.*;
import gregtech.api.recipes.RecipeMap;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.items.ItemStackHandler;

import java.util.ArrayList;
import java.util.List;

public abstract class RecipeMapPrimitiveMultiblockController extends MultiblockWithDisplayBase {

protected PrimitiveRecipeLogic recipeMapWorkable;

public RecipeMapPrimitiveMultiblockController(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap) {
super(metaTileEntityId);
this.recipeMapWorkable = new PrimitiveRecipeLogic(this, recipeMap);
initializeAbilities();
}

// just initialize inventories based on RecipeMap values by default
protected void initializeAbilities() {
this.importItems = new ItemStackHandler(recipeMapWorkable.recipeMap.getMaxInputs());
this.importFluids = new FluidTankList(true, makeFluidTanks(recipeMapWorkable.recipeMap.getMaxFluidInputs()));
this.exportItems = new ItemStackHandler(recipeMapWorkable.recipeMap.getMaxOutputs());
this.exportFluids = new FluidTankList(false, makeFluidTanks(recipeMapWorkable.recipeMap.getMaxFluidOutputs()));

this.itemInventory = new ItemHandlerProxy(this.importItems, this.exportItems);
this.fluidInventory = new FluidHandlerProxy(this.importFluids, this.exportFluids);
}

private List<FluidTank> makeFluidTanks(int length) {
List<FluidTank> fluidTankList = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
fluidTankList.add(new FluidTank(32000));
}
return fluidTankList;
}

@Override
protected void updateFormedValid() {
recipeMapWorkable.update();
}

@Override
public void invalidateStructure() {
super.invalidateStructure();
recipeMapWorkable.invalidate();
}
}
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import gregtech.api.gui.widgets.SlotWidget;
import gregtech.api.gui.widgets.TankWidget;
import gregtech.api.recipes.builders.IntCircuitRecipeBuilder;
import gregtech.api.recipes.builders.PrimitiveRecipeBuilder;
import gregtech.api.recipes.crafttweaker.CTRecipe;
import gregtech.api.recipes.crafttweaker.CTRecipeBuilder;
import gregtech.api.unification.material.Material;
Expand Down Expand Up @@ -93,6 +94,7 @@ public static List<RecipeMap<?>> getRecipeMaps() {

public static void sortMaps() {
for (RecipeMap<?> rmap : RECIPE_MAP_REGISTRY.values()) {
if (rmap.recipeBuilder() instanceof PrimitiveRecipeBuilder) continue; // just for cleanliness
rmap.recipeList.sort(Comparator.comparingInt(Recipe::getDuration)
.thenComparingInt(Recipe::getEUt));
}
Expand Down
29 changes: 10 additions & 19 deletions src/main/java/gregtech/api/recipes/RecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,36 +704,27 @@ public class RecipeMaps {
.setProgressBar(GuiTextures.PROGRESS_BAR_BATH, MoveType.HORIZONTAL);

@ZenProperty
public static final FuelRecipeMap COMBUSTION_GENERATOR_FUELS = new FuelRecipeMap("combustion_generator");

public static final RecipeMap<PrimitiveRecipeBuilder> PRIMITIVE_BLAST_FURNACE_RECIPES = new RecipeMap<>("primitive_blast_furnace", 2, 2, 1, 2, 0, 0, 0, 0, new PrimitiveRecipeBuilder(), false);

@ZenProperty
public static final FuelRecipeMap GAS_TURBINE_FUELS = new FuelRecipeMap("gas_turbine");
public static final RecipeMap<PrimitiveRecipeBuilder> COKE_OVEN_RECIPES = new RecipeMap<>("coke_oven", 1, 1, 0, 1, 0, 0, 0, 1, new PrimitiveRecipeBuilder(), false);

//////////////////////////////////////
// Fuel Recipe Maps //
//////////////////////////////////////

@ZenProperty
public static final FuelRecipeMap STEAM_TURBINE_FUELS = new FuelRecipeMap("steam_turbine");
public static final FuelRecipeMap COMBUSTION_GENERATOR_FUELS = new FuelRecipeMap("combustion_generator");

@ZenProperty
public static final FuelRecipeMap SEMI_FLUID_GENERATOR_FUELS = new FuelRecipeMap("semi_fluid_generator");
public static final FuelRecipeMap GAS_TURBINE_FUELS = new FuelRecipeMap("gas_turbine");

@ZenProperty
public static final FuelRecipeMap PLASMA_GENERATOR_FUELS = new FuelRecipeMap("plasma_generator");
public static final FuelRecipeMap STEAM_TURBINE_FUELS = new FuelRecipeMap("steam_turbine");

@ZenProperty
public static final List<PrimitiveBlastFurnaceRecipe> PRIMITIVE_BLAST_FURNACE_RECIPES = new CopyOnWriteArrayList<>();
public static final FuelRecipeMap SEMI_FLUID_GENERATOR_FUELS = new FuelRecipeMap("semi_fluid_generator");

@ZenProperty
public static final List<CokeOvenRecipe> COKE_OVEN_RECIPES = new CopyOnWriteArrayList<>();

@ZenMethod
public static List<PrimitiveBlastFurnaceRecipe> getPrimitiveBlastFurnaceRecipes() {
return PRIMITIVE_BLAST_FURNACE_RECIPES;
}

@ZenMethod
public static List<CokeOvenRecipe> getCokeOvenRecipes() {
return COKE_OVEN_RECIPES;
}

public static final FuelRecipeMap PLASMA_GENERATOR_FUELS = new FuelRecipeMap("plasma_generator");
}

This file was deleted.

Loading