Skip to content

Commit

Permalink
Minor cleanups (#50)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ah-OOG-ah authored Sep 26, 2024
1 parent 6b4f3eb commit f0f14bb
Show file tree
Hide file tree
Showing 325 changed files with 1,203 additions and 1,866 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies {
api('com.github.GTNewHorizons:ForestryMC:4.9.16:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.5.11:dev')

devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.6.36-GTNH:dev')
devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.6.38-GTNH:dev')

compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.39:api')
compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ developmentEnvironmentUserName = Developer

# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true

# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
enableGenericInjection = false
enableGenericInjection = true

# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
# If gradleTokenVersion is empty or missing, the field will not be present in the class.
generateGradleTokenClass =
generateGradleTokenClass = binnie.core.Tags

# Name of the token containing the project's current version to generate/replace.
gradleTokenVersion = GRADLETOKEN_VERSION
gradleTokenVersion = VERSION

# [DEPRECATED] Mod ID replacement token.
gradleTokenModId =
Expand All @@ -70,7 +70,7 @@ gradleTokenGroupName =
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...]).
# Leave these properties empty to skip individual token replacements.
replaceGradleTokenInFile = BinnieCore.java
replaceGradleTokenInFile =

# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
Expand Down
29 changes: 9 additions & 20 deletions src/main/java/binnie/botany/Botany.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import binnie.botany.proxy.Proxy;
import binnie.core.AbstractMod;
import binnie.core.BinnieCore;
import binnie.core.Tags;
import binnie.core.gui.IBinnieGUID;
import binnie.core.item.ItemMisc;
import binnie.core.network.BinniePacketHandler;
Expand All @@ -53,12 +54,7 @@
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

@Mod(
modid = "Botany",
name = "Botany",
version = BinnieCore.VERSION,
useMetadata = true,
dependencies = "after:BinnieCore")
@Mod(modid = "Botany", name = "Botany", version = Tags.VERSION, useMetadata = true, dependencies = "after:BinnieCore")
public class Botany extends AbstractMod {

@Mod.Instance("Botany")
Expand Down Expand Up @@ -121,11 +117,6 @@ public IBinnieGUID[] getGUIDs() {
return BotanyGUI.values();
}

@Override
public Class<?>[] getConfigs() {
return new Class[0];
}

@Override
public IPacketID[] getPacketIDs() {
return PacketID.values();
Expand Down Expand Up @@ -160,21 +151,19 @@ public void onShearFlower(PlayerInteractEvent event) {
if (event.entityPlayer != null && event.entityPlayer.getHeldItem() != null
&& event.entityPlayer.getHeldItem().getItem() == Items.shears) {
TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
if (tile instanceof TileEntityFlower) {
TileEntityFlower flower = (TileEntityFlower) tile;
flower.onShear();
if (tile instanceof TileEntityFlower tileFlower) {
tileFlower.onShear();
event.entityPlayer.getHeldItem().damageItem(1, event.entityPlayer);
}
}

if (event.entityPlayer != null && event.entityPlayer.getHeldItem() != null
&& event.entityPlayer.getHeldItem().getItem() == Botany.pollen) {
TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
if (tile instanceof TileEntityFlower) {
TileEntityFlower flower = (TileEntityFlower) tile;
if (tile instanceof TileEntityFlower tileFlower) {
IFlower pollen = BotanyCore.getFlowerRoot().getMember(event.entityPlayer.getHeldItem());
if (pollen != null && flower.canMateWith(pollen)) {
flower.mateWith(pollen);
if (pollen != null && tileFlower.canMateWith(pollen)) {
tileFlower.mateWith(pollen);
if (!event.entityPlayer.capabilities.isCreativeMode) {
ItemStack heldItem = event.entityPlayer.getHeldItem();
heldItem.stackSize--;
Expand All @@ -196,10 +185,10 @@ public void onFertiliseSoil(PlayerInteractEvent event) {

int y = event.y;
Block block = event.world.getBlock(event.x, y, event.z);
if (block == null || !Gardening.isSoil(block)) {
if (!Gardening.isSoil(block)) {
block = event.world.getBlock(event.x, --y, event.z);
}
if (block == null || !Gardening.isSoil(block)) {
if (!Gardening.isSoil(block)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/binnie/botany/api/EnumFlowerChromosome.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum EnumFlowerChromosome implements IChromosomeType {
SAPPINESS(IAlleleFloat.class),
STEM(IAlleleInteger.class);

private Class<? extends IAllele> cls;
private final Class<? extends IAllele> cls;

EnumFlowerChromosome(Class<? extends IAllele> cls) {
this.cls = cls;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/binnie/botany/api/EnumFlowerStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public enum EnumFlowerStage {
POLLEN("Pollen"),
NONE("NONE");

protected String name;
private final String name;

EnumFlowerStage(String name) {
this.name = name;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/binnie/botany/ceramic/BlockCeramic.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public String getBlockName(ItemStack itemStack) {
}

@Override
public void addBlockTooltip(ItemStack stack, List tooltip) {
public void addBlockTooltip(ItemStack stack, List<String> tooltip) {
int meta = TileEntityMetadata.getItemDamage(stack);
tooltip.add(EnumChatFormatting.GRAY + EnumFlowerColor.get(meta).getName());
}
Expand All @@ -92,7 +92,7 @@ public void dropAsStack(World world, int x, int y, int z, ItemStack itemStack) {
}

@Override
public void getSubBlocks(Item item, CreativeTabs tabs, List itemList) {
public void getSubBlocks(Item item, CreativeTabs tabs, List<ItemStack> itemList) {
for (EnumFlowerColor c : EnumFlowerColor.values()) {
itemList.add(TileEntityMetadata.getItemStack(this, c.ordinal()));
}
Expand Down
47 changes: 15 additions & 32 deletions src/main/java/binnie/botany/ceramic/BlockCeramicBrick.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public String getBlockName(ItemStack itemStack) {
}

@Override
public void addBlockTooltip(ItemStack itemStack, List tooltip) {
public void addBlockTooltip(ItemStack itemStack, List<String> tooltip) {
int meta = TileEntityMetadata.getItemDamage(itemStack);
getType(meta).addTooltip(tooltip);
}
Expand All @@ -101,7 +101,7 @@ public void dropAsStack(World world, int x, int y, int z, ItemStack itemStack) {
}

@Override
public void getSubBlocks(Item item, CreativeTabs tab, List itemList) {
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> itemList) {
for (EnumFlowerColor c : EnumFlowerColor.values()) {
BlockType type = new BlockType(c, c, TileType.Tile);
itemList.add(TileEntityMetadata.getItemStack(this, type.ordinal()));
Expand Down Expand Up @@ -205,9 +205,9 @@ public enum TileType {
VerticalStripeBrick("verticalbrickstripe", "verticalStripedCeramicBricks"),
VerticalLargeBrick("verticalbricklarge", "largeVerticalCeramicBricks");

protected String id;
protected String name;
protected IIcon[] icons;
private final String id;
private final String name;
private final IIcon[] icons;

TileType(String id, String name) {
icons = new IIcon[3];
Expand All @@ -224,32 +224,15 @@ public boolean canDouble() {
}

public ItemStack getRecipe(List<ItemStack> stacks) {
switch (this) {
case Tile:
return getTileRecipe(stacks);

case Split:
return getSplitRecipe(stacks);

case Chequered:
return getChequeredRecipe(stacks);

case Mixed:
return getMixedRecipe(stacks);

case LargeBrick:
return getLargeBrickRecipe(stacks);

case Brick:
case StripeBrick:
return getBrickRecipe(stacks);

case VerticalLargeBrick:
case VerticalBrick:
case VerticalStripeBrick:
return getVerticalBrickRecipe(stacks);
}
return null;
return switch (this) {
case Tile -> getTileRecipe(stacks);
case Split -> getSplitRecipe(stacks);
case Chequered -> getChequeredRecipe(stacks);
case Mixed -> getMixedRecipe(stacks);
case LargeBrick -> getLargeBrickRecipe(stacks);
case Brick, StripeBrick -> getBrickRecipe(stacks);
case VerticalLargeBrick, VerticalBrick, VerticalStripeBrick -> getVerticalBrickRecipe(stacks);
};
}

private ItemStack getTileRecipe(List<ItemStack> stacks) {
Expand Down Expand Up @@ -541,7 +524,7 @@ public String getName() {
return I18N.localise("botany." + type.name);
}

public void addTooltip(List tooltip) {
public void addTooltip(List<String> tooltip) {
String name = color1.getName();
if (type.canDouble() && color2 != color1) {
name = I18N.localise("botany.colour.double", name, color2.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getBlockName(DesignBlock design) {
}

@Override
public void addBlockTooltip(ItemStack stack, List tooltip) {
public void addBlockTooltip(ItemStack stack, List<String> tooltip) {
super.addBlockTooltip(stack, tooltip);
DesignBlock block = ModuleCarpentry.getDesignBlock(getDesignSystem(), TileEntityMetadata.getItemDamage(stack));
tooltip.add(EnumChatFormatting.GRAY + block.getDesign().getName());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/binnie/botany/ceramic/BlockStained.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public String getBlockName(ItemStack itemStack) {
}

@Override
public void addBlockTooltip(ItemStack itemStack, List tooltip) {
public void addBlockTooltip(ItemStack itemStack, List<String> tooltip) {
int meta = TileEntityMetadata.getItemDamage(itemStack);
tooltip.add(EnumChatFormatting.GRAY + EnumFlowerColor.get(meta).getName());
}
Expand All @@ -122,7 +122,7 @@ public void dropAsStack(World world, int x, int y, int z, ItemStack stack) {
}

@Override
public void getSubBlocks(Item item, CreativeTabs tab, List itemList) {
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> itemList) {
for (EnumFlowerColor c : EnumFlowerColor.values()) {
itemList.add(TileEntityMetadata.getItemStack(this, c.ordinal()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/binnie/botany/ceramic/PigmentRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PigmentRecipe implements IRecipe {

protected ItemStack cached;

private ItemStack unknown;
private final ItemStack unknown;

public PigmentRecipe() {
unknown = null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/binnie/botany/craftgui/ControlColorMixBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class ControlColorMixBox extends ControlListBox<IColourMix> {

private Type type;
private final Type type;

public ControlColorMixBox(IWidget parent, int x, int y, int width, int height, Type type) {
super(parent, x, y, width, height, 12.0f);
Expand All @@ -18,7 +18,7 @@ public IWidget createOption(IColourMix value, int y) {
return new ControlColorMixItem(getContent(), value, y);
}

enum Type {
public enum Type {
Resultant,
Further
}
Expand Down
22 changes: 9 additions & 13 deletions src/main/java/binnie/botany/farm/CircuitGarden.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

public class CircuitGarden extends BinnieCircuit {

private boolean isManual;
private boolean isFertilised;
private ItemStack icon;
private EnumMoisture moisture;
private EnumAcidity acidity;
private final boolean isManual;
private final boolean isFertilised;
private final ItemStack icon;
private final EnumMoisture moisture;
private final EnumAcidity acidity;

public CircuitGarden(EnumMoisture moisture, EnumAcidity ph, boolean manual, boolean fertilised, ItemStack recipe,
ItemStack icon) {
Expand Down Expand Up @@ -46,27 +46,27 @@ public CircuitGarden(EnumMoisture moisture, EnumAcidity ph, boolean manual, bool
}

if (acidity == EnumAcidity.ACID) {
if (info.length() > 0) {
if (!info.isEmpty()) {
info += ", ";
}
info += EnumChatFormatting.RED + I18N.localise("botany.ph.acid") + EnumChatFormatting.RESET;
}

if (acidity == EnumAcidity.NEUTRAL) {
if (info.length() > 0) {
if (!info.isEmpty()) {
info += ", ";
}
info += EnumChatFormatting.GREEN + I18N.localise("botany.ph.neutral") + EnumChatFormatting.RESET;
}

if (acidity == EnumAcidity.ALKALINE) {
if (info.length() > 0) {
if (!info.isEmpty()) {
info += ", ";
}
info += EnumChatFormatting.AQUA + I18N.localise("botany.ph.alkaline") + EnumChatFormatting.RESET;
}

if (info.length() > 0) {
if (!info.isEmpty()) {
info = " (" + info + EnumChatFormatting.RESET + ")";
}
addTooltipString(I18N.localise("botany.circuit.flowers") + info);
Expand Down Expand Up @@ -101,8 +101,4 @@ public void onRemoval(int slot, Object tile) {
((IFarmHousing) tile).resetFarmLogic(FarmDirection.values()[slot]);
}

@Override
public void onTick(int arg0, Object arg1) {
// ignored
}
}
3 changes: 1 addition & 2 deletions src/main/java/binnie/botany/farm/GardenLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ private boolean trySetCrop(Vect position) {

try {
IOwnable housing2 = (IOwnable) housing;
GameProfile prof = (GameProfile) IOwnable.class.getMethod("getOwnerProfile", new Class[0])
.invoke(housing2);
GameProfile prof = (GameProfile) IOwnable.class.getMethod("getOwnerProfile").invoke(housing2);
((TileEntityFlower) tile).setOwner(prof);
} catch (Exception ex) {
// ignored
Expand Down
Loading

0 comments on commit f0f14bb

Please sign in to comment.