Minor cleanups (#50)

* Finalize, minor alloc reduction

Also enable Jabel and generic injection

* Update dependencies.gradle

* Clean up Machine a bit

* spotless

more enhanced instanceof

* Update ModuleMachine.java

* More clen

* WARN: Removed exception catching

* Many, many tiny patches + birthday fix

* Spotless

* Spotless again

* Fix getLow and clamp tolerance value

* Revert event -> ignored on unused event parameters

* Rename instanceof variables

* Update Machine.java

* Use StringBuilder

* Cache getStack()

* Oops, Jabel can't handle that

* Spotless

* Spotless again

My IDE was fighting with it

* Remove unused elements + scream test success
This commit is contained in:
ah-OOG-ah authored and GitHub committed 2024-09-26 16:59:20 +02:00
1 parent 6b4f3eb1c7
commit f0f14bb278
325 files changed
+1205 -1868

No files matched your search

@@ -7,8 +7,8 @@ import java.util.Map;
public class BeeModifierLogic {
private Map<EnumBeeModifier, Float[]> modifiers;
private List<EnumBeeBooleanModifier> booleanModifiers;
private final Map<EnumBeeModifier, Float[]> modifiers;
private final List<EnumBeeBooleanModifier> booleanModifiers;
public BeeModifierLogic() {
modifiers = new HashMap<>();
@@ -131,6 +131,7 @@ public abstract class BreedingSystem implements IItemStackRepresentative {
for (IAlleleSpecies species2 : branch.getMemberSpecies()) {
if (allActiveSpecies.contains(species2)) {
possible = true;
break;
}
}
if (!possible) {
@@ -18,7 +18,7 @@ public class ForestryAllele {
Longest;
public IAllele getAllele() {
return AlleleManager.alleleRegistry.getAllele("forestry.lifespan" + toString());
return AlleleManager.alleleRegistry.getAllele("forestry.lifespan" + this);
}
}
@@ -33,7 +33,7 @@ public class ForestryAllele {
Fastest;
public IAllele getAllele() {
return AlleleManager.alleleRegistry.getAllele("forestry.speed" + toString());
return AlleleManager.alleleRegistry.getAllele("forestry.speed" + this);
}
}
@@ -45,7 +45,7 @@ public class ForestryAllele {
Maximum;
public IAllele getAllele() {
return AlleleManager.alleleRegistry.getAllele("forestry.fertility" + toString());
return AlleleManager.alleleRegistry.getAllele("forestry.fertility" + this);
}
}
@@ -57,7 +57,7 @@ public class ForestryAllele {
Largest;
public IAllele getAllele() {
return AlleleManager.alleleRegistry.getAllele("forestry.territory" + toString());
return AlleleManager.alleleRegistry.getAllele("forestry.territory" + this);
}
}
@@ -72,7 +72,7 @@ public class ForestryAllele {
Largest;
public IAllele getAllele() {
return AlleleManager.alleleRegistry.getAllele("forestry.size" + toString());
return AlleleManager.alleleRegistry.getAllele("forestry.size" + this);
}
}
@@ -82,7 +82,7 @@ public class ForestryAllele {
False;
public IAllele getAllele() {
return AlleleManager.alleleRegistry.getAllele("forestry.bool" + toString());
return AlleleManager.alleleRegistry.getAllele("forestry.bool" + this);
}
public static IAllele get(boolean bool) {
+2 -3
View File
@@ -95,12 +95,11 @@ public class Gene implements INBTTagable, IGene {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Gene)) {
if (!(obj instanceof Gene gene)) {
return false;
}
Gene g = (Gene) obj;
return allele == g.allele && chromosome.ordinal() == g.chromosome.ordinal() && root == g.root;
return allele == gene.allele && chromosome.ordinal() == gene.chromosome.ordinal() && root == gene.root;
}
public String getAlleleName() {
@@ -37,9 +37,9 @@ public class ManagerGenetics extends ManagerBase {
public BreedingSystem treeBreedingSystem;
public BreedingSystem mothBreedingSystem;
public BreedingSystem flowerBreedingSystem;
private Map<ISpeciesRoot, BreedingSystem> breedingSystems;
private List<IChromosomeType> invalidChromosomeTypes;
private Map<ISpeciesRoot, Map<IChromosomeType, List<IAllele>>> chromosomeArray;
private final Map<ISpeciesRoot, BreedingSystem> breedingSystems;
private final List<IChromosomeType> invalidChromosomeTypes;
private final Map<ISpeciesRoot, Map<IChromosomeType, List<IAllele>>> chromosomeArray;
public ManagerGenetics() {
breedingSystems = new LinkedHashMap<>();
@@ -178,11 +178,10 @@ public class ManagerGenetics extends ManagerBase {
}
system.addExtraAlleles(chromosome, alleles);
if (alleles.size() == 0) {
if (alleles.isEmpty()) {
invalidChromosomeTypes.add(chromosome);
} else {
List<IAllele> alleleList = new ArrayList<>();
alleleList.addAll(alleles);
List<IAllele> alleleList = new ArrayList<>(alleles);
chromosomeMap.put(chromosome, alleleList);
}
}
@@ -209,11 +208,11 @@ public class ManagerGenetics extends ManagerBase {
if (o1 == null || o2 == null) {
throw new NullPointerException("Allele is null!");
}
if (o1 instanceof IAlleleFloat && o2 instanceof IAlleleFloat) {
return Float.valueOf(((IAlleleFloat) o1).getValue()).compareTo(((IAlleleFloat) o2).getValue());
if (o1 instanceof IAlleleFloat af1 && o2 instanceof IAlleleFloat af2) {
return Float.compare(af1.getValue(), af2.getValue());
}
if (o1 instanceof IAlleleInteger && o2 instanceof IAlleleInteger && !(o1 instanceof AlleleColor)) {
return Integer.valueOf(((IAlleleInteger) o1).getValue()).compareTo(((IAlleleInteger) o2).getValue());
if (o1 instanceof IAlleleInteger ai1 && o2 instanceof IAlleleInteger ai2 && !(o1 instanceof AlleleColor)) {
return Integer.compare(ai1.getValue(), ai2.getValue());
}
// if (o1.getName() != null && o2.getName() != null) {
// return o1.getName().compareTo(o2.getName());
@@ -1,5 +1,7 @@
package binnie.core.genetics;
import net.minecraft.util.MathHelper;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.EnumTolerance;
import forestry.api.genetics.IAllele;
@@ -23,14 +25,15 @@ public enum Tolerance {
Down4(-4, 0),
Down5(-5, 0);
private int[] bounds;
private final int[] bounds;
private static final Tolerance[] VALUES = values();
Tolerance(int a, int b) {
bounds = new int[] { a, b };
}
public String getUID() {
return "forestry.tolerance" + toString();
return "forestry.tolerance" + this;
}
public int[] getBounds() {
@@ -38,7 +41,40 @@ public enum Tolerance {
}
public static Tolerance get(EnumTolerance tol) {
return values()[tol.ordinal()];
return VALUES[tol.ordinal()];
}
public static Tolerance getHigh(int i) {
return switch (MathHelper.clamp_int(i, 0, 5)) {
case 0 -> None;
case 1 -> Up1;
case 2 -> Up2;
case 3 -> Up3;
case 4 -> Up4;
default -> Up5;
};
}
public static Tolerance getLow(int i) {
return switch (MathHelper.clamp_int(i, -5, 0)) {
case -0 -> None;
case -1 -> Down1;
case -2 -> Down2;
case -3 -> Down3;
case -4 -> Down4;
default -> Down5;
};
}
public static Tolerance getBoth(int i) {
return switch (MathHelper.clamp_int(i, 0, 5)) {
case 0 -> None;
case 1 -> Both1;
case 2 -> Both2;
case 3 -> Both3;
case 4 -> Both4;
default -> Both5;
};
}
public IAllele getAllele() {
@@ -52,8 +52,8 @@ public class TreeBreedingSystem extends BreedingSystem {
public UniqueItemStackSet allFruits = new UniqueItemStackSet();
public UniqueItemStackSet allWoods = new UniqueItemStackSet();
private UniqueItemStackSet discoveredFruits = new UniqueItemStackSet();
private UniqueItemStackSet discoveredWoods = new UniqueItemStackSet();
private final UniqueItemStackSet discoveredFruits = new UniqueItemStackSet();
private final UniqueItemStackSet discoveredWoods = new UniqueItemStackSet();
public TreeBreedingSystem() {
iconUndiscovered = Binnie.Resource.getItemIcon(ExtraTrees.instance, "icon/undiscoveredTree");
@@ -142,7 +142,6 @@ public class TreeBreedingSystem extends BreedingSystem {
// this.discoveredWoods.add(wood);
// }
discoveredFruits.addAll(Arrays.asList(genome.getFruitProvider().getProducts()));
for (ItemStack wood2 : discoveredWoods) {}
}
}
@@ -24,7 +24,7 @@ import forestry.core.access.FakeAccessHandler;
public class VirtualBeeHousing extends VirtualHousing implements IBeeHousing, IBeeModifier {
ArrayList<IBeeModifier> beeModifier = new ArrayList<>();
private InventoryBeeHousing beeInventory;
private final InventoryBeeHousing beeInventory;
public VirtualBeeHousing(EntityPlayer player) {
super(player);
@@ -70,11 +70,6 @@ public class VirtualBeeHousing extends VirtualHousing implements IBeeHousing, IB
return true;
}
@Override
public boolean addProduct(ItemStack product, boolean all) {
return false;
}
public void wearOutEquipment(int amount) {}
public void onQueenChange(ItemStack queen) {}
@@ -17,7 +17,7 @@ import forestry.api.genetics.IHousing;
class VirtualHousing implements IHousing {
private EntityPlayer player;
private final EntityPlayer player;
public VirtualHousing(EntityPlayer player) {
this.player = player;