Skip to content

Commit

Permalink
made MachineFlag just a class with String constants instead of enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Jan 5, 2025
1 parent 4edddd8 commit d1ce1d0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public Tier getPowerLevel() {
return getMachineTier();
}

public boolean has(MachineFlag flag) {
public boolean has(String flag) {
return getMachineType().has(flag);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ public void addFlagsToMaterial(String materialId, String... flags) {
}
}

public MachineFlag machineFlag(String id){
return MachineFlag.valueOf(id);
}

public MaterialType type(String type) {
return AntimatterAPI.get(MaterialType.class, type);
}
Expand Down
40 changes: 17 additions & 23 deletions common/src/main/java/muramasa/antimatter/machine/MachineFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,21 @@
import java.util.Set;
import java.util.stream.Collectors;

public enum MachineFlag {

BASIC, //
STEAM,
MULTI, //Has structure
HATCH,
ITEM, //Can store items
CELL,
FLUID,
EU, //Needs power
RF, //Uses RF instead of EU
HEAT,
RECIPE, //Has a recipe map
GUI,
GENERATOR, //Has a recipe map and converts applicable recipes to power.
COVERABLE,
PARTIAL_AMPS,
UNCULLED;

@Override
public String toString() {
return super.toString().toLowerCase();
}
public final class MachineFlag {
public static final String BASIC = "basic"; //
public static final String STEAM = "steam";
public static final String MULTI = "multi"; //Has structure
public static final String HATCH = "hatch";
public static final String ITEM = "item"; //Can store items
public static final String CELL = "cell";
public static final String FLUID = "fluid";
public static final String EU = "eu"; //Needs power
public static final String RF = "rf"; //Uses RF instead of EU
public static final String HEAT = "heat";
public static final String RECIPE = "recipe"; //Has a recipe map
public static final String GUI = "gui";
public static final String GENERATOR = "generator"; //Has a recipe map and converts applicable recipes to power.
public static final String COVERABLE = "coverable";
public static final String PARTIAL_AMPS = "partial_amps";
public static final String UNCULLED = "unculled";
}
Original file line number Diff line number Diff line change
Expand Up @@ -612,35 +612,21 @@ public IRecipeMap getRecipeMap(Tier tier) {
return tierRecipeMaps.get("");
}

public T addFlags(MachineFlag... flags) {
for (MachineFlag flag : flags) {
FLAG_MAP.computeIfAbsent(flag.toString(), s -> new ObjectOpenHashSet<>()).add(this);
}
return (T) this;
}

public T addFlags(String... flags) {
for (String flag : flags) {
FLAG_MAP.computeIfAbsent(flag, s -> new ObjectOpenHashSet<>()).add(this);
}
return (T) this;
}

public T removeFlags(MachineFlag... flags) {
for (MachineFlag flag : flags) {
FLAG_MAP.computeIfAbsent(flag.toString(), s -> new ObjectOpenHashSet<>()).remove(this);
}
return (T) this;
}

public T removeFlags(String... flags) {
for (String flag : flags) {
FLAG_MAP.computeIfAbsent(flag, s -> new ObjectOpenHashSet<>()).remove(this);
}
return (T) this;
}

public void setFlags(MachineFlag... flags) {
public void setFlags(String... flags) {
FLAG_MAP.forEach((s, m) -> m.remove(this));
addFlags(flags);
}
Expand Down Expand Up @@ -725,16 +711,6 @@ public boolean hasTierSpecificLang(){
return tierSpecificLang;
}

/**
* Whether or not this machine has the given machine flag.
*
* @param flag the flag.
* @return if it has it;.
*/
public boolean has(MachineFlag flag) {
return has(flag.toString());
}

/**
* Whether or not this machine has the given machine flag.
*
Expand Down Expand Up @@ -772,11 +748,11 @@ public static Optional<Machine<?>> get(String name, String domain) {
return Optional.ofNullable(machine);
}

public static Collection<Machine<?>> getTypes(MachineFlag... flags) {
public static Collection<Machine<?>> getTypes(String... flags) {
List<Machine<?>> types = new ObjectArrayList<>();
for (MachineFlag flag : flags) {
if (FLAG_MAP.containsKey(flag.toString())){
types.addAll(FLAG_MAP.get(flag.toString()));
for (var flag : flags) {
if (FLAG_MAP.containsKey(flag)){
types.addAll(FLAG_MAP.get(flag));
}

}
Expand Down

0 comments on commit d1ce1d0

Please sign in to comment.