Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import binnie.botany.api.BotanyAPI;
import binnie.botany.api.IBotanyColored;
import net.minecraft.util.IStringSerializable;

import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;

public enum EnumFlowerColor implements IBotanyColored {
Aquamarine("aquamarine", new Color(8388564)),
Expand Down
4 changes: 2 additions & 2 deletions botany/src/main/java/binnie/botany/blocks/BlockFlower.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, Entity
IFlowerRoot flowerRoot = BotanyCore.getFlowerRoot();
TileEntity flower = world.getTileEntity(pos);
if (world.isRemote) {
if (flower != null && flower instanceof TileEntityFlower) {
if (flower instanceof TileEntityFlower) {
IFlower f = flowerRoot.getMember(stack);
if (f != null) {
((TileEntityFlower) flower).setRender(new FlowerRenderInfo(f, (TileEntityFlower) flower));
Expand All @@ -165,7 +165,7 @@ public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, Entity
}

TileEntity below = world.getTileEntity(pos.down());
if (flower != null && flower instanceof TileEntityFlower) {
if (flower instanceof TileEntityFlower) {
if (below instanceof TileEntityFlower) {
((TileEntityFlower) flower).setSection(((TileEntityFlower) below).getSection());
} else {
Expand Down
6 changes: 3 additions & 3 deletions botany/src/main/java/binnie/botany/genetics/FlowerRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public boolean plant(World world, BlockPos pos, IFlower flower, GameProfile owne

TileEntity tile = world.getTileEntity(pos);
TileEntity below = world.getTileEntity(pos.down());
if (tile != null && tile instanceof TileEntityFlower) {
if (tile instanceof TileEntityFlower) {
TileEntityFlower tileFlower = (TileEntityFlower) tile;
if (below instanceof TileEntityFlower) {
tileFlower.setSection(((TileEntityFlower) below).getSection());
Expand All @@ -325,7 +325,7 @@ public void tryGrowSection(World world, BlockPos pos) {
}

TileEntity tileFlower = world.getTileEntity(pos);
if (tileFlower == null || !(tileFlower instanceof TileEntityFlower)) {
if (!(tileFlower instanceof TileEntityFlower)) {
return;
}

Expand All @@ -340,7 +340,7 @@ public void tryGrowSection(World world, BlockPos pos) {
if (blockAbove.getBlock().isReplaceable(world, up)) {
world.setBlockState(up, ModuleFlowers.flower.getDefaultState());
TileEntity flowerAbove = world.getTileEntity(up);
if (flowerAbove != null && flowerAbove instanceof TileEntityFlower) {
if (flowerAbove instanceof TileEntityFlower) {
((TileEntityFlower) flowerAbove).setSection(section + 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static class FlowerIconDisplay extends ControlIconDisplay {
private final IFlowerType type;

public FlowerIconDisplay(AnalystPageAppearance analystPageAppearance, int width, int y, int sections, IFlower flower, IFlowerType type) {
super(analystPageAppearance, (analystPageAppearance.getWidth() - width) / 2, y - ((sections == 1) ? 0 : 0));
super(analystPageAppearance, (analystPageAppearance.getWidth() - width) / 2, y );
this.width = width;
this.sections = sections;
this.flower = flower;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public SPacketUpdateTileEntity getUpdatePacket() {
public void updateRender(boolean update) {
if (update && getFlower() != null && getFlower().getGenome() != null) {
FlowerRenderInfo newInfo = new FlowerRenderInfo(getFlower(), this);
if (renderInfo == null || !newInfo.equals(renderInfo)) {
if (!newInfo.equals(renderInfo)) {
setRender(newInfo);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import javax.annotation.Nullable;

import binnie.core.api.gui.IPoint;
import binnie.core.api.gui.IWidget;

public interface ITopLevelWidget extends IWidget {
IPoint getAbsoluteMousePosition();

Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/binnie/core/Binnie.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import binnie.core.ManagerBase;
import binnie.core.genetics.ManagerGenetics;
import binnie.core.liquid.ManagerLiquid;
import binnie.core.machines.ManagerMachine;
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/binnie/core/genetics/AlleleHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package binnie.core.genetics;

import java.util.Locale;
import java.util.regex.Pattern;

import binnie.core.util.EmptyHelper;
import org.apache.commons.lang3.text.WordUtils;

import forestry.api.core.EnumHumidity;
Expand All @@ -13,6 +15,8 @@

import binnie.core.util.I18N;

import javax.annotation.Nullable;

public class AlleleHelper extends forestry.core.genetics.alleles.AlleleHelper {
public static IAllele getAllele(EnumTemperature temperature) {
return getAllele(getUid(temperature));
Expand Down Expand Up @@ -195,16 +199,18 @@ protected static String getUid(String key, String valueName) {
return getUid(key, valueName, true);
}

private static final Pattern PATTERN_REPLACEMENT = Pattern.compile("_");

private static String getUid(String key, String valueName, boolean needCapitalize) {
if (needCapitalize) {
valueName = WordUtils.capitalize(valueName.toLowerCase(Locale.ENGLISH));
}
valueName = valueName.replace("_", "");
valueName = PATTERN_REPLACEMENT.matcher(valueName).replaceAll(EmptyHelper.EMPTY_STRING);
return "forestry." + key + valueName;
}

private static String toAlleleDisplay(String key, String valueName) {
String name = valueName.toLowerCase().replace("_", "");
private static String toAlleleDisplay(@Nullable String key, String valueName) {
String name = PATTERN_REPLACEMENT.matcher(valueName.toLowerCase()).replaceAll(EmptyHelper.EMPTY_STRING);
if (key == null) {
return I18N.localise("forestry.allele." + name);
}
Expand Down
10 changes: 7 additions & 3 deletions core/src/main/java/binnie/core/gui/minecraft/GuiCraftGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import binnie.core.api.gui.IPoint;
import binnie.core.gui.KeyBindings;
import binnie.core.gui.geometry.Point;
import binnie.core.util.Log;
import binnie.core.util.EmptyHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
Expand Down Expand Up @@ -129,6 +131,8 @@ public void drawScreen(final int mouseX, final int mouseY, final float partialTi
GlStateManager.enableDepth();
}

private static final Pattern PATTERN_NBT_CONTENT = Pattern.compile(Tooltip.NBT_SEPARATOR + "(.*?)" + Tooltip.NBT_SEPARATOR);

public void renderTooltip(final Point mousePosition, final MinecraftTooltip tooltip) {
final int mouseX = mousePosition.xPos();
final int mouseY = mousePosition.yPos();
Expand All @@ -152,7 +156,7 @@ public void renderTooltip(final Point mousePosition, final MinecraftTooltip tool
for (String textLine : textLines) {
int textLineWidth = font.getStringWidth(textLine);
if (textLine.contains(Tooltip.NBT_SEPARATOR)) {
textLineWidth = 12 + font.getStringWidth(textLine.replaceAll(Tooltip.NBT_SEPARATOR + "(.*?)" + Tooltip.NBT_SEPARATOR, ""));
textLineWidth = 12 + font.getStringWidth(PATTERN_NBT_CONTENT.matcher(textLine).replaceAll(EmptyHelper.EMPTY_STRING));
}
if (textLineWidth > tooltipTextWidth) {
tooltipTextWidth = textLineWidth;
Expand Down Expand Up @@ -207,7 +211,7 @@ private void drawHoveringText(@Nonnull ItemStack itemStack, List<String> textLin
for (String line : wrappedLine) {
int lineWidth = font.getStringWidth(line);
if (textLine.contains(Tooltip.NBT_SEPARATOR)) {
lineWidth = 12 + font.getStringWidth(textLine.replaceAll(Tooltip.NBT_SEPARATOR + "(.*?)" + Tooltip.NBT_SEPARATOR, ""));
lineWidth = 12 + font.getStringWidth(PATTERN_NBT_CONTENT.matcher(textLine).replaceAll(EmptyHelper.EMPTY_STRING));
}
if (lineWidth > wrappedTooltipWidth) {
wrappedTooltipWidth = lineWidth;
Expand Down Expand Up @@ -262,7 +266,7 @@ private void drawHoveringText(@Nonnull ItemStack itemStack, List<String> textLin
}
if (line.contains(Tooltip.NBT_SEPARATOR)) {
drawItem(line, tooltipX, tooltipY);
line = " " + line.replaceAll(Tooltip.NBT_SEPARATOR + "(.*?)" + Tooltip.NBT_SEPARATOR, "");
line = " " + PATTERN_NBT_CONTENT.matcher(line).replaceAll(EmptyHelper.EMPTY_STRING);
}
font.drawStringWithShadow(line, tooltipX, tooltipY, -1);
if (lineNumber + 1 == titleLinesCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void onMessage(final MessageBinnie message, final MessageContext context)
final TileEntity tile = packet4.getTarget(BinnieCore.getBinnieProxy().getWorld());
if (tile != null && packet4.getTagCompound() != null) {
final IMachine machine = Machine.getMachine(tile);
if (machine != null && machine instanceof INetwork.TilePacketSync) {
if (machine instanceof INetwork.TilePacketSync) {
((INetwork.TilePacketSync) machine).syncFromNBT(packet4.getTagCompound());
}
}
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/binnie/core/proxy/I18NClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.IllegalFormatException;

@SideOnly(Side.CLIENT)
public class I18NClient implements I18NProxy {

Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/binnie/core/util/EmptyHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package binnie.core.util;

public final class EmptyHelper {
private EmptyHelper() {}

public static final String EMPTY_STRING = "";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably overkill, I'd be surprised if the JVM does not have some kind of optimization for the empty string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Probably you are right.
But now I used StringUtils.Empty (as you can see in #504)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good.

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ControlRecipeSlot(final IWidget parent, final int x, final int y) {
super(parent, x, y, 50);
this.addSelfEventHandler(EventMouse.Down.class, event -> {
final TileEntity tile = (TileEntity) Window.get(ControlRecipeSlot.this.getWidget()).getInventory();
if (tile == null || !(tile instanceof TileEntityMachine)) {
if (!(tile instanceof TileEntityMachine)) {
return;
}
final NBTTagCompound nbt = new NBTTagCompound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean matches(final InventoryCrafting inv, final World world) {
if (!a.isEmpty() && !b.isEmpty() && !c.isEmpty()) {
FenceType type = WoodManager.getFenceType(a);
FenceType typeSecond = WoodManager.getFenceType(c);
if (type != null && typeSecond != null && type.equals(typeSecond)) {
if (type != null && type.equals(typeSecond)) {
FenceDescription fenceDescription = WoodManager.getFenceDescription(a);
if (fenceDescription != null) {
IPlankType descPlankType = fenceDescription.getPlankType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean matches(final InventoryCrafting inv, final World world) {
FenceType type = WoodManager.getFenceType(a);
FenceType type2 = WoodManager.getFenceType(b);
FenceType type3 = WoodManager.getFenceType(c);
if (type != null && type2 != null && type3 != null && type.equals(type2) && type.equals(type3)) {
if (type != null && type.equals(type2) && type.equals(type3)) {
FenceDescription fenceDescription = WoodManager.getFenceDescription(a);
if (fenceDescription != null) {
FenceType fenceType = new FenceType(type.getSize(), true, type.isSolid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public IFruitFamily getFamily() {

@Override
public int getRipeningPeriod() {
return this.RIPENING_PERIOD;
return RIPENING_PERIOD;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import binnie.core.machines.IMachineType;
import binnie.core.machines.MachinePackage;
import binnie.genetics.Genetics;
import binnie.genetics.machine.splicer.PackageSplicer;

public enum AdvGeneticMachine implements IMachineType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package binnie.genetics.machine;

import javax.annotation.Resource;
import java.util.function.Supplier;

import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

import binnie.core.Constants;
import binnie.core.machines.IMachineType;
import binnie.core.machines.MachinePackage;
import binnie.core.machines.TileEntityMachine;
import binnie.genetics.Genetics;
import binnie.genetics.machine.inoculator.PackageInoculator;
import binnie.genetics.machine.isolator.PackageIsolator;
import binnie.genetics.machine.polymeriser.PackagePolymeriser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ErrorState canProgress() {

@Override
protected void onTickTask() {
if (this.rand.nextInt(20) == 0 && this.recipe != null && this.rand.nextFloat() < this.recipe.getChance()) {
if (this.recipe != null && this.rand.nextInt(20) == 0 && this.rand.nextFloat() < this.recipe.getChance()) {
this.recipe.doTask(this.getUtil());
}
}
Expand Down