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,12 +7,10 @@ import java.util.List;
import binnie.extrabees.genetics.requirements.DummyMutationCondition;
import binnie.extrabees.genetics.requirements.IMutationRequirement;
import binnie.extrabees.genetics.requirements.RequirementPerson;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeMutationCustom;
import forestry.api.apiculture.IBeeRoot;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IMutation;
import forestry.apiculture.genetics.BeeMutation;
@@ -21,7 +19,7 @@ public class ExtraBeeMutation extends BeeMutation implements IBeeMutationCustom
public static List<IMutation> mutations = new ArrayList<>();
private List<IMutationRequirement> requirements;
private final List<IMutationRequirement> requirements;
public ExtraBeeMutation(IAlleleBeeSpecies bee0, IAlleleBeeSpecies bee1, IAllele[] result, int chance) {
super(bee0, bee1, result, chance);
@@ -29,11 +27,6 @@ public class ExtraBeeMutation extends BeeMutation implements IBeeMutationCustom
mutations.add(this);
}
@Override
public IBeeRoot getRoot() {
return BeeManager.beeRoot;
}
@Override
public float getChance(IBeeHousing housing, IAlleleBeeSpecies allele0, IAlleleBeeSpecies allele1,
IBeeGenome genome0, IBeeGenome genome1) {
@@ -45,7 +45,7 @@ public enum ExtraBeesFlowers implements IFlowerProvider, IAlleleFlowers, IChromo
MYSTICAL,
BEDROCK;
protected boolean dominant;
private final boolean dominant;
ExtraBeesFlowers() {
dominant = true;
@@ -87,41 +87,20 @@ public enum ExtraBeesFlowers implements IFlowerProvider, IAlleleFlowers, IChromo
}
public ItemStack[] getItemStacks() {
switch (this) {
case WATER:
return new ItemStack[] { new ItemStack(Blocks.waterlily) };
case SUGAR:
return new ItemStack[] { new ItemStack(Blocks.reeds) };
case ROCK:
return new ItemStack[] { new ItemStack(Blocks.cobblestone) };
case BOOK:
return new ItemStack[] { new ItemStack(Blocks.bookshelf) };
case REDSTONE:
return new ItemStack[] { new ItemStack(Blocks.redstone_torch) };
case DEAD:
return new ItemStack[] { new ItemStack(Blocks.deadbush) };
case FRUIT:
return new ItemStack[] { new ItemStack(Items.apple) };
case LEAVES:
return new ItemStack[] { new ItemStack(Blocks.leaves) };
case SAPLING:
return new ItemStack[] { new ItemStack(Blocks.sapling) };
case WOOD:
return new ItemStack[] { new ItemStack(Blocks.log) };
case BEDROCK:
return new ItemStack[] { new ItemStack(Blocks.bedrock) };
}
return new ItemStack[0];
return switch (this) {
case WATER -> new ItemStack[] { new ItemStack(Blocks.waterlily) };
case SUGAR -> new ItemStack[] { new ItemStack(Blocks.reeds) };
case ROCK -> new ItemStack[] { new ItemStack(Blocks.cobblestone) };
case BOOK -> new ItemStack[] { new ItemStack(Blocks.bookshelf) };
case REDSTONE -> new ItemStack[] { new ItemStack(Blocks.redstone_torch) };
case DEAD -> new ItemStack[] { new ItemStack(Blocks.deadbush) };
case FRUIT -> new ItemStack[] { new ItemStack(Items.apple) };
case LEAVES -> new ItemStack[] { new ItemStack(Blocks.leaves) };
case SAPLING -> new ItemStack[] { new ItemStack(Blocks.sapling) };
case WOOD -> new ItemStack[] { new ItemStack(Blocks.log) };
case BEDROCK -> new ItemStack[] { new ItemStack(Blocks.bedrock) };
default -> new ItemStack[0];
};
}
@Override
@@ -136,57 +115,31 @@ public enum ExtraBeesFlowers implements IFlowerProvider, IAlleleFlowers, IChromo
return false;
}
switch (this) {
case WATER:
return block == Blocks.waterlily;
case ROCK:
return block.getMaterial() == Material.rock;
case SUGAR:
return block == Blocks.reeds;
case BOOK:
return block == Blocks.bookshelf;
case REDSTONE:
return block == Blocks.redstone_torch;
case DEAD:
return block == Blocks.deadbush;
case WOOD:
return block.isWood(world, x, y, z);
case FRUIT:
return world.getTileEntity(x, y, z) instanceof IFruitBearer;
case LEAVES:
return block.isLeaves(world, x, y, z);
case SAPLING:
return block.getClass().getName().toLowerCase().contains("sapling");
case MYSTICAL:
return block == Mods.botania.block("flower");
case BEDROCK:
return block == Blocks.bedrock;
}
return false;
return switch (this) {
case WATER -> block == Blocks.waterlily;
case ROCK -> block.getMaterial() == Material.rock;
case SUGAR -> block == Blocks.reeds;
case BOOK -> block == Blocks.bookshelf;
case REDSTONE -> block == Blocks.redstone_torch;
case DEAD -> block == Blocks.deadbush;
case WOOD -> block.isWood(world, x, y, z);
case FRUIT -> world.getTileEntity(x, y, z) instanceof IFruitBearer;
case LEAVES -> block.isLeaves(world, x, y, z);
case SAPLING -> block.getClass().getName().toLowerCase().contains("sapling");
case MYSTICAL -> block == Mods.botania.block("flower");
case BEDROCK -> block == Blocks.bedrock;
};
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
switch (this) {
case WATER:
return world.isAirBlock(x, y, z) && world.getBlock(x, y - 1, z) == Blocks.water
&& world.setBlock(x, y, z, Blocks.waterlily, 0, 2);
case SUGAR:
return world.getBlock(x, y - 1, z) == Blocks.reeds && world.isAirBlock(x, y, z)
&& world.setBlock(x, y, z, Blocks.reeds, 0, 0);
}
return false;
return switch (this) {
case WATER -> world.isAirBlock(x, y, z) && world.getBlock(x, y - 1, z) == Blocks.water
&& world.setBlock(x, y, z, Blocks.waterlily, 0, 2);
case SUGAR -> world.getBlock(x, y - 1, z) == Blocks.reeds && world.isAirBlock(x, y, z)
&& world.setBlock(x, y, z, Blocks.reeds, 0, 0);
default -> false;
};
}
@Override
@@ -26,6 +26,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
import binnie.Binnie;
import binnie.core.Mods;
import binnie.core.util.I18N;
import binnie.extrabees.ExtraBees;
import binnie.extrabees.genetics.ExtraBeesFlowers;
@@ -67,18 +68,25 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
BONEMEAL_MUSHROOM,
POWER;
protected static List<Birthday> birthdays;
private static final List<Birthday> birthdays = new ArrayList<>();
static {
birthdays = new ArrayList<>();
birthdays.add(new Birthday(3, 10, "Binnie"));
// At the time Binnie abandoned this, the month was bumped by one, the day by two, and the order flipped.
// That resulted in the actual date being Apr. 11th instead of Oct. 3rd. I fixed this, but the old behavior is
// preserved outside NH, in case someone wasn't expecting that.
if (Mods.dreamcraft.active()) {
birthdays.add(new Birthday(3, 10, "Binnie"));
} else {
birthdays.add(new Birthday(11, 4, "Binnie"));
}
}
public boolean combinable;
public boolean dominant;
public final boolean combinable;
public final boolean dominant;
public int id;
String fx;
private String uid;
private final String uid;
ExtraBeesEffect() {
fx = "";
@@ -382,8 +390,7 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
private void onFoodEffect(IBeeGenome genome, IBeeHousing housing) {
for (EntityLivingBase entity : getEntities(EntityLivingBase.class, genome, housing)) {
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (entity instanceof EntityPlayer player) {
player.getFoodStats().addStats(2, 0.2f);
}
}
@@ -391,8 +398,7 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
private void onHungerEffect(IBeeGenome genome, IBeeHousing housing, World world) {
for (EntityLivingBase entity : getEntities(EntityLivingBase.class, genome, housing)) {
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (entity instanceof EntityPlayer player) {
if (world.rand.nextInt(4) < wearsItems(player)) {
continue;
}
@@ -405,8 +411,7 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
private void onPotionEffect(IBeeGenome genome, IBeeHousing housing, World world, PotionEffect potion) {
for (EntityLivingBase entity : getEntities(EntityLivingBase.class, genome, housing)) {
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (entity instanceof EntityPlayer player) {
if (world.rand.nextInt(4) < wearsItems(player)) {
continue;
}
@@ -493,12 +498,12 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
}
List<Entity> entities = getEntities(Entity.class, genome, housing);
if (entities.size() == 0) {
if (entities.isEmpty()) {
return;
}
Entity entity = entities.get(world.rand.nextInt(entities.size()));
if (!(entity instanceof EntityLiving)) {
if (!(entity instanceof EntityLiving living)) {
return;
}
@@ -509,7 +514,6 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
return;
}
EntityLiving living = (EntityLiving) entity;
living.setPositionAndUpdate(x, y, z);
living.addPotionEffect(new PotionEffect(Potion.confusion.id, 160, 10));
}
@@ -562,21 +566,19 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
}
}
protected int[] getModifiedArea(IBeeGenome genome, IBeeHousing housing) {
private int[] getModifiedArea(IBeeGenome genome, IBeeHousing housing) {
int[] territory;
int[] area = territory = genome.getTerritory();
int n = 0;
territory[n] *= (int) (BeeManager.beeRoot.createBeeHousingModifier(housing).getTerritoryModifier(genome, 1.0f)
* 3.0f);
int[] array = area;
int n2 = 1;
array[n2] *= (int) (BeeManager.beeRoot.createBeeHousingModifier(housing).getTerritoryModifier(genome, 1.0f)
area[n2] *= (int) (BeeManager.beeRoot.createBeeHousingModifier(housing).getTerritoryModifier(genome, 1.0f)
* 3.0f);
int[] array2 = area;
int n3 = 2;
array2[n3] *= (int) (BeeManager.beeRoot.createBeeHousingModifier(housing).getTerritoryModifier(genome, 1.0f)
area[n3] *= (int) (BeeManager.beeRoot.createBeeHousingModifier(housing).getTerritoryModifier(genome, 1.0f)
* 3.0f);
if (area[0] < 1) {
@@ -609,7 +611,7 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
public <T extends Entity> List<T> getEntities(Class<T> eClass, IBeeGenome genome, IBeeHousing housing) {
int[] area = genome.getTerritory();
int[] offset = { -Math.round(area[0] / 2), -Math.round(area[1] / 2), -Math.round(area[2] / 2) };
int[] offset = { -Math.round(area[0] / 2f), -Math.round(area[1] / 2f), -Math.round(area[2] / 2f) };
int[] min = { housing.getCoordinates().posX + offset[0], housing.getCoordinates().posY + offset[1],
housing.getCoordinates().posZ + offset[2] };
int[] max = { housing.getCoordinates().posX + offset[0] + area[0],
@@ -632,12 +634,13 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
private Birthday(int day, int month, String name) {
this.day = day;
this.month = month + 1;
this.month = month - 1;
this.name = name;
}
public boolean isToday() {
return Calendar.getInstance().get(5) == month && Calendar.getInstance().get(2) == day;
return Calendar.getInstance().get(Calendar.MONTH) == month
&& Calendar.getInstance().get(Calendar.DATE) == day;
}
public String getName() {
@@ -53,7 +53,7 @@ public class FireworkCreator {
nbt.setBoolean("Trail", true);
}
if (colors.size() == 0) {
if (colors.isEmpty()) {
addColor(0xffffff);
}
@@ -42,7 +42,7 @@ public class ItemDictionary extends Item {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) {
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (stack.getItemDamage() > 0) {
tooltip.add(I18N.localise("extrabees.item.database.tooltip"));
@@ -51,7 +51,7 @@ public class ItemDictionary extends Item {
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List list) {
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list) {
super.getSubItems(item, tab, list);
list.add(new ItemStack(item, 1, 1));
}