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

Fix space miner module dupe #67

Merged
merged 1 commit into from
Aug 23, 2024
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
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.123:dev')
api('com.github.GTNewHorizons:Galaxy-Space-GTNH:1.1.89-GTNH:dev')
api('com.github.GTNewHorizons:GTNHLib:0.3.3:dev')
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.5.41:dev") {transitive = false}
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.144:dev')
api('com.github.GTNewHorizons:Galaxy-Space-GTNH:1.1.90-GTNH:dev')
api('com.github.GTNewHorizons:GTNHLib:0.4.2:dev')
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.5.42:dev") {transitive = false}
}
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,6 @@ public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStac
}
// Check if the allowed module amount is exceeded. Motor tier 5 unlocks all module slots
isMachineValid = ElevatorUtil.getModuleSlotsUnlocked(motorTier) >= mProjectModuleHatches.size();
// Fix maintenance issues
fixAllIssues();
if (elevatorCable != null) {
elevatorCable.setShouldRender(isMachineValid);
return isMachineValid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GT_StructureUtility;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.shutdown.ShutDownReasonRegistry;
import micdoodle8.mods.galacticraft.core.util.GCCoreUtil;

/**
Expand Down Expand Up @@ -172,7 +173,7 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (aTick % 20 == 0) energyDisplay.set(getEUVar());
if (mEfficiency < 0) mEfficiency = 0;
if (aBaseMetaTileEntity.getStoredEU() <= 0 && mMaxProgresstime > 0) {
stopMachine();
stopMachine(ShutDownReasonRegistry.POWER_LOSS);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import net.minecraft.client.renderer.texture.IIconRegister;
Expand Down Expand Up @@ -65,6 +67,7 @@
import gregtech.api.recipe.check.SimpleCheckRecipeResult;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_ParallelHelper;
import gregtech.api.util.GT_Utility;
import gregtech.common.misc.spaceprojects.SpaceProjectManager;
import gregtech.common.misc.spaceprojects.enums.SolarSystem;
import gregtech.common.misc.spaceprojects.interfaces.ISpaceProject;
Expand Down Expand Up @@ -124,7 +127,7 @@ public abstract class TileEntityModuleMiner extends TileEntityModuleBase impleme
.translate("gt.blockmachines.multimachine.project.ig.miner.cfgi.1"); // Max parallels
/** Status of the parallel setting */
private static final IStatusFunction<TileEntityModuleMiner> PARALLEL_STATUS = (base, p) -> LedStatus
.fromLimitsInclusiveOuterBoundary(p.get(), 0, 1, 100, base.getParallels());
.fromLimitsInclusiveOuterBoundary(p.get(), 0, 1, 100, base.getMaxParallels());
/** Name of the overdrive setting */
private static final INameFunction<TileEntityModuleMiner> OVERDRIVE_SETTING_NAME = (base, p) -> GCCoreUtil
.translate("gt.blockmachines.multimachine.project.ig.miner.cfgi.2"); // Overdrive
Expand Down Expand Up @@ -240,6 +243,7 @@ public RecipeMap<?> getRecipeMap() {
*/
@Override
public @NotNull CheckRecipeResult checkProcessing_EM() {
if (!overdriveSetting.getStatus(false).isOk) return SimpleCheckRecipeResult.ofFailure("invalid_overdrive");
if (V[tTier] * (long) parallelSetting.get() > getEUVar()) {
return CheckRecipeResultRegistry.insufficientPower(V[tTier] * (long) parallelSetting.get());
}
Expand All @@ -251,18 +255,19 @@ public RecipeMap<?> getRecipeMap() {
mPollution = 0;
mOutputItems = null;
mOutputFluids = null;
if (getStoredFluids().size() <= 0) {
List<FluidStack> inputFluids = getStoredFluids();
if (inputFluids.isEmpty()) {
return SimpleCheckRecipeResult.ofFailure("no_plasma");
}

// Look for a valid plasma to start a mining operation
for (FluidStack fluidStack : getStoredFluids()) {
for (FluidStack fluidStack : inputFluids) {
int availablePlasmaTier = getTierFromPlasma(fluidStack);
if (availablePlasmaTier > 0) {
// Check if valid inputs for a mining operation are present
CheckRecipeResult result = process(
getStoredInputs().toArray(new ItemStack[0]),
getStoredFluids().toArray(new FluidStack[0]),
inputFluids.toArray(new FluidStack[0]),
availablePlasmaTier,
fluidStack,
getParallels(fluidStack, getPlasmaUsageFromTier(availablePlasmaTier)));
Expand All @@ -287,10 +292,10 @@ public CheckRecipeResult process(ItemStack[] inputs, FluidStack[] fluidInputs, i
FluidStack plasma, int maxParallels) {
// Check inputs
if ((inputs == null && fluidInputs == null)) {
return SimpleCheckRecipeResult.ofFailure("no_plasma");
return CheckRecipeResultRegistry.NO_RECIPE;
}
if (plasma == null || availablePlasmaTier <= 0) {
return CheckRecipeResultRegistry.NO_RECIPE;
return SimpleCheckRecipeResult.ofFailure("no_plasma");
}

// Get all asteroid pools that this drone can pull from
Expand Down Expand Up @@ -351,7 +356,7 @@ public CheckRecipeResult process(ItemStack[] inputs, FluidStack[] fluidInputs, i
}

// Randomly generate ore stacks with the given chances, ores and size
ItemStack[] outputs = new ItemStack[tRecipe.maxSize * parallels];
Map<GT_Utility.ItemId, Long> outputs = new HashMap<>();
int totalChance = Arrays.stream(tRecipe.mChances).sum();
try {
for (int i = 0; i < tRecipe.maxSize * parallels; i++) {
Expand All @@ -368,7 +373,10 @@ public CheckRecipeResult process(ItemStack[] inputs, FluidStack[] fluidInputs, i
ItemStack generatedOre = tRecipe.mOutputs[j];
if (configuredOres == null || configuredOres.isEmpty()
|| isWhitelisted == configuredOres.contains(getOreString(generatedOre))) {
outputs[i] = generatedOre.copy();
outputs.merge(
GT_Utility.ItemId.createNoCopy(generatedOre),
(long) generatedOre.stackSize,
Long::sum);
}
break;
}
Expand All @@ -384,7 +392,12 @@ public CheckRecipeResult process(ItemStack[] inputs, FluidStack[] fluidInputs, i
Math.ceil(plasma.amount - parallels * getPlasmaUsageFromTier(availablePlasmaTier) * plasmaModifier));

// Assign recipe parameters
mOutputItems = outputs;
ArrayList<ItemStack> outputItems = new ArrayList<>();
for (Map.Entry<GT_Utility.ItemId, Long> entry : outputs.entrySet()) {
GT_ParallelHelper.addItemsLong(outputItems, entry.getKey().getItemStack(), entry.getValue());
}
mOutputItems = outputItems.toArray(new ItemStack[0]);

lEUt = (long) -tRecipe.mEUt * parallels;
eAmpereFlow = 1;
// TODO: Implement way to get computation from master controller. Or maybe keep it this way so
Expand Down Expand Up @@ -488,7 +501,7 @@ protected String getOreString(ItemStack oreStack) {
*
* @return Number of possible parallels
*/
protected abstract int getParallels();
protected abstract int getMaxParallels();

/**
* Get the number of parallels that this module can handle
Expand All @@ -502,7 +515,9 @@ protected int getParallels(FluidStack plasma, int plasmaUsage) {
return 0;
}
float plasmaModifier = asteroidOutpost != null ? 1f - asteroidOutpost.getPlasmaDiscount() : 1f;
return Math.min((int) parallelSetting.get(), (int) (plasma.amount / (plasmaUsage * plasmaModifier)));
return Math.min(
(int) Math.min(getMaxParallels(), parallelSetting.get()),
(int) (plasma.amount / (plasmaUsage * plasmaModifier)));
}

/**
Expand Down Expand Up @@ -548,7 +563,7 @@ protected void parametersInstantiation_EM() {
Parameters.Group hatch_2 = parametrization.getGroup(2, false);
Parameters.Group hatch_3 = parametrization.getGroup(3, false);
distanceSetting = hatch_0.makeInParameter(0, 1, DISTANCE_SETTING_NAME, DISTANCE_STATUS);
parallelSetting = hatch_0.makeInParameter(1, getParallels(), PARALLEL_SETTING_NAME, PARALLEL_STATUS);
parallelSetting = hatch_0.makeInParameter(1, getMaxParallels(), PARALLEL_SETTING_NAME, PARALLEL_STATUS);
overdriveSetting = hatch_1.makeInParameter(0, 1, OVERDRIVE_SETTING_NAME, OVERDRIVE_STATUS);
modeSetting = hatch_2.makeInParameter(0, 0, MODE_SETTING_NAME, MODE_STATUS);
rangeSetting = hatch_2.makeInParameter(1, 0, RANGE_SETTING_NAME, RANGE_STATUS);
Expand Down Expand Up @@ -791,7 +806,7 @@ public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) {
*
* @return Number of possible parallels
*/
protected int getParallels() {
protected int getMaxParallels() {
return MAXIMUM_PARALLELS;
}

Expand Down Expand Up @@ -884,7 +899,7 @@ public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) {
*
* @return Number of possible parallels
*/
protected int getParallels() {
protected int getMaxParallels() {
return MAXIMUM_PARALLELS;
}

Expand Down Expand Up @@ -977,7 +992,7 @@ public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) {
*
* @return Number of possible parallels
*/
protected int getParallels() {
protected int getMaxParallels() {
return MAXIMUM_PARALLELS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ GT5U.gui.text.no_space_station=§7Not on a space station
GT5U.gui.text.invalid_depth=§7Invalid depth
GT5U.gui.text.missing_project=§7Missing §b%s §7 at §b%s
GT5U.gui.text.no_plasma=§7Not enough plasma
GT5U.gui.text.invalid_overdrive=§7Invalid overdrive settings
GT5U.gui.text.no_project_selected=§7Not working on any project
ig.text.project=Project
ig.text.upgrades=Upgrades
Expand Down