Skip to content

Commit

Permalink
Consolidate some duplicate methods
Browse files Browse the repository at this point in the history
Allow 8 energy hatches on the quacker like the other quads
  • Loading branch information
Zorbatron committed Oct 16, 2024
1 parent e5bd988 commit bca6bcb
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.jetbrains.annotations.Nullable;

import com.zorbatron.zbgt.api.pattern.TraceabilityPredicates;
import com.zorbatron.zbgt.common.ZBGTConfig;

import gregicality.multiblocks.api.metatileentity.GCYMRecipeMapMultiblockController;
Expand Down Expand Up @@ -70,36 +71,21 @@ public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkM
checkFluidIn, checkFluidOut, checkMuffler);

if (checkEnergyIn) {
predicate = predicate.or(autoEnergyInputs());
predicate = predicate.or(autoEnergyInputsMega());
}

return predicate;
}

public TraceabilityPredicate autoEnergyInputs(int min, int max, int previewCount) {
if (allowsSubstationHatches()) {
return new TraceabilityPredicate(abilities(MultiblockAbility.INPUT_ENERGY, MultiblockAbility.INPUT_LASER,
MultiblockAbility.SUBSTATION_INPUT_ENERGY)
.setMinGlobalLimited(min).setMaxGlobalLimited(max).setPreviewCount(previewCount));
} else {
return new TraceabilityPredicate(abilities(MultiblockAbility.INPUT_ENERGY, MultiblockAbility.INPUT_LASER)
.setMinGlobalLimited(min).setMaxGlobalLimited(max).setPreviewCount(previewCount));
}
}

public TraceabilityPredicate autoEnergyInputs(int min, int max) {
return autoEnergyInputs(min, max, 2);
}

public TraceabilityPredicate autoEnergyInputs() {
return autoEnergyInputs(1, 3);
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
tooltip.add(I18n.format(I18n.format("zbgt.laser_enabled.1") +
TooltipHelper.RAINBOW + I18n.format("zbgt.laser_enabled.2")) +
(allowsSubstationHatches() ? I18n.format("zbgt.substation_enabled") : ""));
}

protected TraceabilityPredicate autoEnergyInputsMega() {
return TraceabilityPredicates.autoEnergyInputs(1, 8, 2, true, allowsSubstationHatches(), true);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zorbatron.zbgt.api.metatileentity;

import static com.zorbatron.zbgt.api.pattern.TraceabilityPredicates.autoEnergyInputs;

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

Expand Down Expand Up @@ -60,31 +62,12 @@ public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkM
checkFluidIn, checkFluidOut, checkMuffler);

if (checkEnergyIn) {
predicate = predicate.or(autoEnergyInputs());
predicate = predicate.or(autoEnergyInputs(1, 3, true, false, true));
}

return predicate;
}

public TraceabilityPredicate autoEnergyInputs(int min, int max, int previewCount) {
if (allowsSubstationHatches()) {
return new TraceabilityPredicate(abilities(MultiblockAbility.INPUT_ENERGY, MultiblockAbility.INPUT_LASER,
MultiblockAbility.SUBSTATION_INPUT_ENERGY)
.setMinGlobalLimited(min).setMaxGlobalLimited(max).setPreviewCount(previewCount));
} else {
return new TraceabilityPredicate(abilities(MultiblockAbility.INPUT_ENERGY, MultiblockAbility.INPUT_LASER)
.setMinGlobalLimited(min).setMaxGlobalLimited(max).setPreviewCount(previewCount));
}
}

public TraceabilityPredicate autoEnergyInputs(int min, int max) {
return autoEnergyInputs(min, max, 2);
}

public TraceabilityPredicate autoEnergyInputs() {
return autoEnergyInputs(1, 3);
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zorbatron.zbgt.api.metatileentity;

import static com.zorbatron.zbgt.api.pattern.TraceabilityPredicates.autoEnergyInputs;

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

Expand Down Expand Up @@ -61,31 +63,12 @@ public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkM
checkFluidIn, checkFluidOut, checkMuffler);

if (checkEnergyIn) {
predicate = predicate.or(autoEnergyInputs());
predicate = predicate.or(autoEnergyInputs(1, 3, 2, true, false, true));
}

return predicate;
}

public TraceabilityPredicate autoEnergyInputs(int min, int max, int previewCount) {
if (allowsSubstationHatches()) {
return new TraceabilityPredicate(abilities(MultiblockAbility.INPUT_ENERGY, MultiblockAbility.INPUT_LASER,
MultiblockAbility.SUBSTATION_INPUT_ENERGY)
.setMinGlobalLimited(min).setMaxGlobalLimited(max).setPreviewCount(previewCount));
} else {
return new TraceabilityPredicate(abilities(MultiblockAbility.INPUT_ENERGY, MultiblockAbility.INPUT_LASER)
.setMinGlobalLimited(min).setMaxGlobalLimited(max).setPreviewCount(previewCount));
}
}

public TraceabilityPredicate autoEnergyInputs(int min, int max) {
return autoEnergyInputs(min, max, 2);
}

public TraceabilityPredicate autoEnergyInputs() {
return autoEnergyInputs(1, 3);
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import static gregtech.api.metatileentity.multiblock.MultiblockControllerBase.abilities;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.*;
import java.util.function.Supplier;

import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -173,4 +172,35 @@ public static TraceabilityPredicate autoBusesAndHatches(RecipeMap<?> recipeMap)
public static Supplier<?> getMaintenanceHatchMTE(IBlockState defaultCasing) {
return () -> ConfigHolder.machines.enableMaintenance ? MetaTileEntities.MAINTENANCE_HATCH : defaultCasing;
}

public static TraceabilityPredicate autoEnergyInputs(int min, int max, int previewCount, boolean allowEnergyHatches,
boolean allowSubstationHatches, boolean allowLaserHatches) {
List<MultiblockAbility<?>> allowedAbilities = new ArrayList<>();

if (allowEnergyHatches) allowedAbilities.add(MultiblockAbility.INPUT_ENERGY);
if (allowSubstationHatches) allowedAbilities.add(MultiblockAbility.SUBSTATION_INPUT_ENERGY);
if (allowLaserHatches) allowedAbilities.add(MultiblockAbility.INPUT_LASER);

return new TraceabilityPredicate(abilities(allowedAbilities.stream().toArray(MultiblockAbility<?>[]::new))
.setMinGlobalLimited(min)
.setMaxGlobalLimited(max)
.setPreviewCount(previewCount));
}

public static TraceabilityPredicate autoEnergyInputs(int min, int max, boolean allowEnergyHatches,
boolean allowSubstationHatches, boolean allowLaserHatches) {
return autoEnergyInputs(min, max, 2, allowEnergyHatches, allowSubstationHatches, allowLaserHatches);
}

public static TraceabilityPredicate autoEnergyInputs(int min, int max, int previewCount) {
return autoEnergyInputs(min, max, previewCount, true, false, false);
}

public static TraceabilityPredicate autoEnergyInputs(int min, int max) {
return autoEnergyInputs(min, max, 2);
}

public static TraceabilityPredicate autoEnergyInputs() {
return autoEnergyInputs(1, 3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
.where('B',
states(getCasingState())
.or(TraceabilityPredicates.autoBusesAndHatches(getAvailableRecipeMaps()))
.or(autoEnergyInputs(1, 8)))
.or(autoEnergyInputsMega()))
.where('X', states(getCasingState()))
.where('V', states(getVentState()))
.where('G', states(getGlassState()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
.where('S', selfPredicate())
.where('X', states(getCasingState()).setMinGlobalLimited(420)
.or(autoAbilities(false, true, true, true, true, true, false))
.or(autoEnergyInputs(1, 8)))
.or(autoEnergyInputsMega()))
.where('G', states(getGlassState()))
.where('M', abilities(MultiblockAbility.MUFFLER_HATCH))
.where('C', heatingCoils())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
.where('G', states(getGlassState()))
.where('F', states(getCoilState()))
.where('E', states(getCasingState())
.or(autoEnergyInputs(1, 8))
.or(autoEnergyInputsMega())
.or(abilities(GCYMMultiblockAbility.PARALLEL_HATCH).setMaxGlobalLimited(1))
.or(maintenancePredicate()))
.where('H', states(getCasingState())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
.where('O', abilities(MultiblockAbility.EXPORT_FLUIDS))
.where('E', states(getCasingState())
.or(autoAbilities(false, true, true, true, false, false, false))
.or(autoEnergyInputs(1, 8)))
.or(autoEnergyInputsMega()))
.where('G', states(getGlassState()))
.where('#', air())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
.where('S', selfPredicate())
.where('X', states(getCasingState()).setMinGlobalLimited(1150)
.or(autoAbilities(false, true, true, true, true, true, false))
.or(autoEnergyInputs(1, 8)))
.or(autoEnergyInputsMega()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.zorbatron.zbgt.common.metatileentities.multi.electric.quad;

import static com.zorbatron.zbgt.api.pattern.TraceabilityPredicates.autoEnergyInputs;

import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.PositionedSoundRecord;
Expand Down Expand Up @@ -79,7 +81,8 @@ private void playQuack() {
.where('S', selfPredicate())
.where('C', heatingCoils())
.where('X', states(getCasingState()).setMinGlobalLimited(25)
.or(autoAbilities()))
.or(autoAbilities(false, true, true, true, true, true, false))
.or(autoEnergyInputs(1, 8)))
.where('T', states(getCasingState()))
.where('#', air())
.build();
Expand Down

0 comments on commit bca6bcb

Please sign in to comment.