diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyClimatiser.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyClimatiser.java index c96786273..150d83ff3 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyClimatiser.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyClimatiser.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.apiculture.gadgets; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index b66661701..32487babe 100755 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -726,8 +726,10 @@ public class Bee extends IndividualLiving implements IBee { IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwnerName(), world, posBlock.x, posBlock.y, posBlock.z); - realPollinatable.mateWith(pollen); - return true; + if (realPollinatable != null) { + realPollinatable.mateWith(pollen); + return true; + } } return false; diff --git a/src/main/java/forestry/apiculture/genetics/BeeHelper.java b/src/main/java/forestry/apiculture/genetics/BeeHelper.java index 3188b8f5e..02e574d5b 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeHelper.java +++ b/src/main/java/forestry/apiculture/genetics/BeeHelper.java @@ -228,7 +228,7 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot { /** * List of possible mutations on species alleles. */ - private static ArrayList beeMutations = new ArrayList(); + private static final ArrayList beeMutations = new ArrayList(); @Override public Collection getMutations(boolean shuffle) { diff --git a/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java b/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java index bf2bc301f..318c13379 100755 --- a/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java +++ b/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java @@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack; import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.EnumBeeType; +import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.api.apiculture.IBee; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleArea; @@ -41,7 +42,10 @@ public class GuiBeealyzer extends GuiAlyzer { ArrayList beeList = new ArrayList(); ((ItemBeeGE) ForestryItem.beeDroneGE.item()).addCreativeItems(beeList, false); for (ItemStack beeStack : beeList) { - iconStacks.put(BeeGenome.getSpecies(beeStack).getUID(), beeStack); + IAlleleBeeSpecies species = BeeGenome.getSpecies(beeStack); + if (species != null) { + iconStacks.put(species.getUID(), beeStack); + } } } diff --git a/src/main/java/forestry/apiculture/gui/GuiImprinter.java b/src/main/java/forestry/apiculture/gui/GuiImprinter.java index c58a3b7fc..7ec6b3acb 100755 --- a/src/main/java/forestry/apiculture/gui/GuiImprinter.java +++ b/src/main/java/forestry/apiculture/gui/GuiImprinter.java @@ -45,9 +45,11 @@ public class GuiImprinter extends GuiForestry beeList = new ArrayList(); ((ItemBeeGE) ForestryItem.beeDroneGE.item()).addCreativeItems(beeList, false); for (ItemStack beeStack : beeList) { - iconStacks.put(BeeGenome.getSpecies(beeStack).getUID(), beeStack); + IAlleleBeeSpecies species = BeeGenome.getSpecies(beeStack); + if (species != null) { + iconStacks.put(species.getUID(), beeStack); + } } - } @Override diff --git a/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java b/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java index 6ba5634fb..f3ce6a87e 100644 --- a/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java +++ b/src/main/java/forestry/apiculture/items/ItemHabitatLocator.java @@ -61,14 +61,14 @@ public class ItemHabitatLocator extends ItemInventoried { private static final short SLOT_ANALYZED = 1; public Set biomesToSearch = new HashSet(); - private ItemHabitatLocator habitatLocator; + private final ItemHabitatLocator habitatLocator; public HabitatLocatorInventory(ItemStack itemstack) { super(ItemHabitatLocator.class, 3, itemstack); this.habitatLocator = (ItemHabitatLocator) itemstack.getItem(); } - private boolean isEnergy(ItemStack itemstack) { + private static boolean isEnergy(ItemStack itemstack) { if (itemstack == null || itemstack.stackSize <= 0) { return false; } diff --git a/src/main/java/forestry/apiculture/render/TextureHabitatLocator.java b/src/main/java/forestry/apiculture/render/TextureHabitatLocator.java index 01df78f82..0017c644c 100644 --- a/src/main/java/forestry/apiculture/render/TextureHabitatLocator.java +++ b/src/main/java/forestry/apiculture/render/TextureHabitatLocator.java @@ -45,13 +45,13 @@ public class TextureHabitatLocator extends TextureAtlasSprite { Minecraft minecraft = Minecraft.getMinecraft(); if (minecraft.theWorld != null && minecraft.thePlayer != null) { - updateCompass(minecraft.theWorld, minecraft.thePlayer.posX, minecraft.thePlayer.posZ, minecraft.thePlayer.rotationYaw, false, true); + updateCompass(minecraft.theWorld, minecraft.thePlayer.posX, minecraft.thePlayer.posZ, minecraft.thePlayer.rotationYaw); } else { - updateCompass(null, 0.0d, 0.0d, 0.0d, true, true); + updateCompass(null, 0.0d, 0.0d, 0.0d); } } - public void updateCompass(World world, double playerX, double playerZ, double playerYaw, boolean par8, boolean hasSpin) { + public void updateCompass(World world, double playerX, double playerZ, double playerYaw) { double targetAngle; @@ -72,31 +72,27 @@ public class TextureHabitatLocator extends TextureAtlasSprite { } } - if (!hasSpin) { - currentAngle = targetAngle; - } else { - double angleChange = targetAngle - currentAngle; - while (angleChange < -Math.PI) { - angleChange += (Math.PI * 2D); - } - - while (angleChange >= Math.PI) { - angleChange -= (Math.PI * 2D); - } - - if (angleChange < -1.0D) { - angleChange = -1.0D; - } - - if (angleChange > 1.0D) { - angleChange = 1.0D; - } - - this.angleDelta += angleChange * 0.1D; - this.angleDelta *= 0.8D; - this.currentAngle += this.angleDelta; + double angleChange = targetAngle - currentAngle; + while (angleChange < -Math.PI) { + angleChange += (Math.PI * 2D); } + while (angleChange >= Math.PI) { + angleChange -= (Math.PI * 2D); + } + + if (angleChange < -1.0D) { + angleChange = -1.0D; + } + + if (angleChange > 1.0D) { + angleChange = 1.0D; + } + + this.angleDelta += angleChange * 0.1D; + this.angleDelta *= 0.8D; + this.currentAngle += this.angleDelta; + int i = (int) ((this.currentAngle / (Math.PI * 2D) + 1.0d) * this.framesTextureData.size()) % this.framesTextureData.size(); while (i < 0) { i = (i + this.framesTextureData.size()) % this.framesTextureData.size(); diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDescription.java b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java index e44a9a1ed..358eb9a00 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveDescription.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java @@ -58,7 +58,7 @@ public enum HiveDescription implements IHiveDescription { private final IBeeGenome beeGenome; private final IHiveGen hiveGen; - private HiveDescription(int meta, float genChance, IAllele[] beeTemplate, IHiveGen hiveGen) { + HiveDescription(int meta, float genChance, IAllele[] beeTemplate, IHiveGen hiveGen) { this.meta = meta; this.genChance = genChance; this.beeGenome = PluginApiculture.beeInterface.templateAsGenome(beeTemplate); diff --git a/src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java b/src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java index 27f0fe03d..a253b3950 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java @@ -17,7 +17,7 @@ import forestry.api.apiculture.hives.IHiveGenHelper; public class HiveGenHelper implements IHiveGenHelper { - private static IHiveGen treeGen = new HiveGenTree(); + private static final IHiveGen treeGen = new HiveGenTree(); @Override public IHiveGen ground(Block... validGroundBlocks) { diff --git a/src/main/java/forestry/arboriculture/FruitProviderNone.java b/src/main/java/forestry/arboriculture/FruitProviderNone.java index 5cfc10f52..da5aafd61 100755 --- a/src/main/java/forestry/arboriculture/FruitProviderNone.java +++ b/src/main/java/forestry/arboriculture/FruitProviderNone.java @@ -37,7 +37,7 @@ public class FruitProviderNone implements IFruitProvider { } } - private static HashMap overlayTypes = new HashMap(); + private static final HashMap overlayTypes = new HashMap(); static { overlayTypes.put("berries", new OverlayType("berries", (short) 1000)); diff --git a/src/main/java/forestry/arboriculture/FruitProviderPod.java b/src/main/java/forestry/arboriculture/FruitProviderPod.java index e2931637f..8918788f5 100755 --- a/src/main/java/forestry/arboriculture/FruitProviderPod.java +++ b/src/main/java/forestry/arboriculture/FruitProviderPod.java @@ -31,13 +31,13 @@ import forestry.plugins.PluginArboriculture; public class FruitProviderPod extends FruitProviderNone { - public static enum EnumPodType { + public enum EnumPodType { COCOA((short) 2000, (short) 2001, (short) 2002), DATES((short) 2010, (short) 2011, (short) 2012), PAPAYA((short) 2013, (short) 2014, (short) 2015);//, COCONUT((short)2016, (short)2017, (short)2018); public final short[] uids; - private EnumPodType(short stage1, short stage2, short stage3) { + EnumPodType(short stage1, short stage2, short stage3) { uids = new short[]{stage1, stage2, stage3}; } } diff --git a/src/main/java/forestry/arboriculture/WoodType.java b/src/main/java/forestry/arboriculture/WoodType.java index 3270119ab..43a927a5c 100755 --- a/src/main/java/forestry/arboriculture/WoodType.java +++ b/src/main/java/forestry/arboriculture/WoodType.java @@ -34,11 +34,11 @@ public enum WoodType { public static final WoodType[] VALUES = values(); private final float hardness; - private WoodType() { + WoodType() { this(2.0f); } - private WoodType(float hardness) { + WoodType(float hardness) { this.hardness = hardness; } diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockArbFence.java b/src/main/java/forestry/arboriculture/gadgets/BlockArbFence.java index c3ce6cc39..a66b41b83 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockArbFence.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockArbFence.java @@ -36,7 +36,7 @@ import forestry.plugins.PluginArboriculture; public class BlockArbFence extends BlockFence implements IWoodTyped { - public static enum FenceCat { + public enum FenceCat { CAT0, CAT1 } diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockPlanks.java b/src/main/java/forestry/arboriculture/gadgets/BlockPlanks.java index d738f9388..df5b3c584 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockPlanks.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockPlanks.java @@ -33,7 +33,7 @@ import forestry.arboriculture.WoodType; public class BlockPlanks extends Block implements IWoodTyped { - public static enum PlankCat { + public enum PlankCat { CAT0, CAT1 } diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockSlab.java b/src/main/java/forestry/arboriculture/gadgets/BlockSlab.java index 4668d0029..00ae9eecf 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockSlab.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockSlab.java @@ -34,7 +34,7 @@ import forestry.arboriculture.WoodType; public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyped { - public static enum SlabCat { + public enum SlabCat { CAT0, CAT1, CAT2, CAT3 } diff --git a/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java b/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java index 42640a364..669668234 100644 --- a/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java +++ b/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java @@ -72,6 +72,9 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv private static NBTTagCompound getTagCompoundForLeaves(IBlockAccess world, int x, int y, int z) { TileLeaves leaves = getLeafTile(world, x, y, z); NBTTagCompound nbttagcompound = new NBTTagCompound(); + if (leaves == null) { + return nbttagcompound; + } leaves.writeToNBT(nbttagcompound); return nbttagcompound; } diff --git a/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java b/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java index 15159a512..eb0f714d6 100755 --- a/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java +++ b/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java @@ -25,6 +25,7 @@ import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleFruit; import forestry.api.arboriculture.IAlleleGrowth; +import forestry.api.arboriculture.IAlleleTreeSpecies; import forestry.api.arboriculture.ITree; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleInteger; @@ -49,7 +50,10 @@ public class GuiTreealyzer extends GuiAlyzer { ArrayList treeList = new ArrayList(); ((ItemGermlingGE) ForestryItem.sapling.item()).addCreativeItems(treeList, false); for (ItemStack treeStack : treeList) { - iconStacks.put(TreeGenome.getSpecies(treeStack).getUID(), treeStack); + IAlleleTreeSpecies species = TreeGenome.getSpecies(treeStack); + if (species != null) { + iconStacks.put(species.getUID(), treeStack); + } } } diff --git a/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java b/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java index c1e2572e7..4c93a1397 100755 --- a/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java +++ b/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java @@ -148,7 +148,7 @@ public class LeavesRenderingHandler extends OverlayRenderingHandler implements I Tessellator tessellator = Tessellator.instance; Block block = StackUtils.getBlock(itemStack); - if (!(itemStack.getItem() instanceof ItemLeavesBlock)) { + if (!(itemStack.getItem() instanceof ItemLeavesBlock) || block == null) { return; } diff --git a/src/main/java/forestry/core/EnumErrorCode.java b/src/main/java/forestry/core/EnumErrorCode.java index b2131311a..cbf201bcf 100644 --- a/src/main/java/forestry/core/EnumErrorCode.java +++ b/src/main/java/forestry/core/EnumErrorCode.java @@ -64,11 +64,11 @@ public enum EnumErrorCode implements IErrorState { @SideOnly(Side.CLIENT) private IIcon icon; - private EnumErrorCode(String name) { + EnumErrorCode(String name) { this(name, name); } - private EnumErrorCode(String name, String iconName) { + EnumErrorCode(String name, String iconName) { this.name = name; this.iconName = iconName; } diff --git a/src/main/java/forestry/core/IItemTyped.java b/src/main/java/forestry/core/IItemTyped.java index 46f01ca15..c64e5258f 100644 --- a/src/main/java/forestry/core/IItemTyped.java +++ b/src/main/java/forestry/core/IItemTyped.java @@ -1,6 +1,5 @@ -package forestry.core; - -public interface IItemTyped { - @SuppressWarnings("rawtypes") - public Enum getTypeFromMeta(int meta); -} +package forestry.core; + +public interface IItemTyped { + Enum getTypeFromMeta(int meta); +} diff --git a/src/main/java/forestry/core/circuits/EnumCircuitBoardType.java b/src/main/java/forestry/core/circuits/EnumCircuitBoardType.java index 28aaa3386..763e304ea 100755 --- a/src/main/java/forestry/core/circuits/EnumCircuitBoardType.java +++ b/src/main/java/forestry/core/circuits/EnumCircuitBoardType.java @@ -18,7 +18,7 @@ public enum EnumCircuitBoardType { final int primaryColor; final int secondaryColor; - private EnumCircuitBoardType(short sockets, int primaryColor, int secondaryColor) { + EnumCircuitBoardType(short sockets, int primaryColor, int secondaryColor) { this.sockets = sockets; this.primaryColor = primaryColor; this.secondaryColor = secondaryColor; diff --git a/src/main/java/forestry/core/commands/SubCommand.java b/src/main/java/forestry/core/commands/SubCommand.java index afda59129..75b7e662d 100644 --- a/src/main/java/forestry/core/commands/SubCommand.java +++ b/src/main/java/forestry/core/commands/SubCommand.java @@ -29,7 +29,7 @@ public abstract class SubCommand implements IForestryCommand { EVERYONE(0), ADMIN(2); public final int permLevel; - private PermLevel(int permLevel) { + PermLevel(int permLevel) { this.permLevel = permLevel; } diff --git a/src/main/java/forestry/core/fluids/Fluids.java b/src/main/java/forestry/core/fluids/Fluids.java index 49c2b8d7f..e9d99c0d1 100644 --- a/src/main/java/forestry/core/fluids/Fluids.java +++ b/src/main/java/forestry/core/fluids/Fluids.java @@ -325,15 +325,15 @@ public enum Fluids { private final int density, viscosity; private final Color color; - private Fluids() { + Fluids() { this(null); } - private Fluids(Color color) { + Fluids(Color color) { this(color, 1000, 1000); } - private Fluids(Color color, int density, int viscosity) { + Fluids(Color color, int density, int viscosity) { this.tag = name().toLowerCase(Locale.ENGLISH); this.color = color; this.density = density; diff --git a/src/main/java/forestry/core/gadgets/TileAnalyzer.java b/src/main/java/forestry/core/gadgets/TileAnalyzer.java index 6611d3147..f51d62c59 100755 --- a/src/main/java/forestry/core/gadgets/TileAnalyzer.java +++ b/src/main/java/forestry/core/gadgets/TileAnalyzer.java @@ -39,11 +39,8 @@ import forestry.core.inventory.TileInventoryAdapter; import forestry.core.inventory.wrappers.IInvSlot; import forestry.core.inventory.wrappers.InventoryIterator; import forestry.core.inventory.wrappers.InventoryMapper; -import forestry.core.network.ForestryPacket; import forestry.core.network.GuiId; import forestry.core.network.PacketPayload; -import forestry.core.network.PacketTileUpdate; -import forestry.core.proxy.Proxies; import forestry.core.utils.GuiUtil; import forestry.plugins.PluginApiculture; @@ -215,8 +212,8 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui payload.stringPayload = new String[1]; payload.shortPayload = new short[2]; payload.stringPayload[0] = displayIndividual.getIdent(); - payload.shortPayload[0] = (short)type; - payload.shortPayload[1] = (short)displayStack.stackSize; + payload.shortPayload[0] = (short) type; + payload.shortPayload[1] = (short) displayStack.stackSize; return payload; } diff --git a/src/main/java/forestry/core/gadgets/TileForestry.java b/src/main/java/forestry/core/gadgets/TileForestry.java index 7d64186d9..4f3cd8828 100755 --- a/src/main/java/forestry/core/gadgets/TileForestry.java +++ b/src/main/java/forestry/core/gadgets/TileForestry.java @@ -49,7 +49,6 @@ import forestry.core.utils.AdjacentTileCache; import forestry.core.utils.EnumAccess; import forestry.core.utils.PlayerUtil; import forestry.core.utils.Utils; -import forestry.core.vect.Vect; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.ITriggerExternal; @@ -59,7 +58,7 @@ import buildcraft.api.statements.ITriggerProvider; @Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements") public abstract class TileForestry extends TileEntity implements INetworkedEntity, IRestrictedAccess, IErrorSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate { - private static Random rand = new Random(); + private static final Random rand = new Random(); protected final AdjacentTileCache tileCache = new AdjacentTileCache(this); protected boolean isInited = false; diff --git a/src/main/java/forestry/core/genetics/EnumMutateChance.java b/src/main/java/forestry/core/genetics/EnumMutateChance.java index be39d83d3..a5a05117e 100755 --- a/src/main/java/forestry/core/genetics/EnumMutateChance.java +++ b/src/main/java/forestry/core/genetics/EnumMutateChance.java @@ -15,7 +15,7 @@ public enum EnumMutateChance { public final int colour; - private EnumMutateChance(int colour) { + EnumMutateChance(int colour) { this.colour = colour; } diff --git a/src/main/java/forestry/core/genetics/FruitFamily.java b/src/main/java/forestry/core/genetics/FruitFamily.java index 4c6861421..1a437dce2 100755 --- a/src/main/java/forestry/core/genetics/FruitFamily.java +++ b/src/main/java/forestry/core/genetics/FruitFamily.java @@ -16,8 +16,8 @@ import forestry.core.utils.StringUtil; public class FruitFamily implements IFruitFamily { - private String uid; - private String scientific; + private final String uid; + private final String scientific; public FruitFamily(String uid, String scientific) { this.uid = uid; diff --git a/src/main/java/forestry/core/genetics/ItemResearchNote.java b/src/main/java/forestry/core/genetics/ItemResearchNote.java index dc45db751..88b0f5f32 100755 --- a/src/main/java/forestry/core/genetics/ItemResearchNote.java +++ b/src/main/java/forestry/core/genetics/ItemResearchNote.java @@ -43,7 +43,7 @@ import forestry.core.utils.StringUtil; public class ItemResearchNote extends ItemForestry { - public static enum EnumNoteType { + public enum EnumNoteType { NONE, MUTATION, SPECIES; public static final EnumNoteType[] VALUES = values(); diff --git a/src/main/java/forestry/core/interfaces/IBlockRenderer.java b/src/main/java/forestry/core/interfaces/IBlockRenderer.java index e953a6666..ad2fbbf74 100755 --- a/src/main/java/forestry/core/interfaces/IBlockRenderer.java +++ b/src/main/java/forestry/core/interfaces/IBlockRenderer.java @@ -13,7 +13,7 @@ package forestry.core.interfaces; import net.minecraft.tileentity.TileEntity; public interface IBlockRenderer { - public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f); + void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f); - public void inventoryRender(double x, double y, double z, float f, float f1); + void inventoryRender(double x, double y, double z, float f, float f1); } diff --git a/src/main/java/forestry/core/inventory/IInventoryAdapter.java b/src/main/java/forestry/core/inventory/IInventoryAdapter.java index 218257b03..17f1e123d 100644 --- a/src/main/java/forestry/core/inventory/IInventoryAdapter.java +++ b/src/main/java/forestry/core/inventory/IInventoryAdapter.java @@ -8,5 +8,5 @@ import forestry.core.interfaces.IFilterSlotDelegate; public interface IInventoryAdapter extends ISidedInventory, IFilterSlotDelegate, INBTTagable { /* Sided */ - public IInventoryAdapter configureSided(int[] sides, int[] slots); + IInventoryAdapter configureSided(int[] sides, int[] slots); } diff --git a/src/main/java/forestry/core/inventory/ITileFilter.java b/src/main/java/forestry/core/inventory/ITileFilter.java index d12f3e646..06ee9ada6 100755 --- a/src/main/java/forestry/core/inventory/ITileFilter.java +++ b/src/main/java/forestry/core/inventory/ITileFilter.java @@ -17,6 +17,6 @@ import net.minecraft.tileentity.TileEntity; */ public interface ITileFilter { - public boolean matches(TileEntity tile); + boolean matches(TileEntity tile); } diff --git a/src/main/java/forestry/core/inventory/ItemStackSet.java b/src/main/java/forestry/core/inventory/ItemStackSet.java deleted file mode 100755 index dd8143f3b..000000000 --- a/src/main/java/forestry/core/inventory/ItemStackSet.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.inventory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import net.minecraft.item.ItemStack; - -/** - * This is a custom data structure designed specifically for using ItemStacks as - * elements of a Set. - * - * Its backed by an ArrayList, so as expected, most operations result in - * traversing the list one or more times. - * - * @author CovertJaguar - */ -public class ItemStackSet implements Set { - - private final List set = new ArrayList(); - - @Override - public int size() { - return set.size(); - } - - @Override - public boolean isEmpty() { - return set.isEmpty(); - } - - @Override - public boolean contains(Object obj) { - if (!(obj instanceof ItemStack)) { - return false; - } - ItemStack check = (ItemStack) obj; - for (ItemStack stack : set) { - if (InvTools.isItemEqual(stack, check)) { - return true; - } - } - return false; - } - - @Override - public Iterator iterator() { - return set.iterator(); - } - - @Override - public Object[] toArray() { - return set.toArray(); - } - - @Override - public T[] toArray(T[] a) { - return set.toArray(a); - } - - @Override - public boolean add(ItemStack e) { - if (contains(e)) { - return false; - } - set.add(e); - return true; - } - - @Override - public boolean remove(Object obj) { - if (!(obj instanceof ItemStack)) { - return false; - } - boolean changed = false; - ItemStack check = (ItemStack) obj; - Iterator it = set.iterator(); - while (it.hasNext()) { - ItemStack stack = it.next(); - if (InvTools.isItemEqual(stack, check)) { - it.remove(); - changed = true; - } - } - return changed; - } - - @Override - public boolean containsAll(Collection c) { - for (Object obj : c) { - if (!(obj instanceof ItemStack)) { - return false; - } - if (!contains(obj)) { - return false; - } - } - return true; - } - - @Override - public boolean addAll(Collection c) { - boolean changed = false; - for (ItemStack stack : c) { - changed |= add(stack); - } - return changed; - } - - @Override - public boolean retainAll(Collection c) { - boolean changed = false; - Iterator it = set.iterator(); - while (it.hasNext()) { - ItemStack stack = it.next(); - if (!c.contains(stack)) { - it.remove(); - changed = true; - } - } - return changed; - } - - @Override - public boolean removeAll(Collection c) { - boolean changed = false; - Iterator it = set.iterator(); - while (it.hasNext()) { - ItemStack stack = it.next(); - if (c.contains(stack)) { - it.remove(); - changed = true; - } - } - return changed; - } - - @Override - public void clear() { - set.clear(); - } -} diff --git a/src/main/java/forestry/core/inventory/filters/IStackFilter.java b/src/main/java/forestry/core/inventory/filters/IStackFilter.java index df40c9d17..82ddf56f1 100755 --- a/src/main/java/forestry/core/inventory/filters/IStackFilter.java +++ b/src/main/java/forestry/core/inventory/filters/IStackFilter.java @@ -21,5 +21,5 @@ import net.minecraft.item.ItemStack; */ public interface IStackFilter { - public boolean matches(ItemStack stack); + boolean matches(ItemStack stack); } diff --git a/src/main/java/forestry/core/network/INetworkedEntity.java b/src/main/java/forestry/core/network/INetworkedEntity.java index 7f7a52467..5d9f37b86 100755 --- a/src/main/java/forestry/core/network/INetworkedEntity.java +++ b/src/main/java/forestry/core/network/INetworkedEntity.java @@ -12,8 +12,8 @@ package forestry.core.network; public interface INetworkedEntity { - public void sendNetworkUpdate(); + void sendNetworkUpdate(); - public void fromPacket(ForestryPacket packet); + void fromPacket(ForestryPacket packet); } diff --git a/src/main/java/forestry/core/network/PacketFXSignal.java b/src/main/java/forestry/core/network/PacketFXSignal.java index 835bee89c..c2103118a 100755 --- a/src/main/java/forestry/core/network/PacketFXSignal.java +++ b/src/main/java/forestry/core/network/PacketFXSignal.java @@ -22,18 +22,18 @@ import forestry.core.proxy.Proxies; public class PacketFXSignal extends ForestryPacket { - public static enum VisualFXType { + public enum VisualFXType { NONE, BLOCK_DESTROY, SAPLING_PLACE } - public static enum SoundFXType { + public enum SoundFXType { NONE(""), BLOCK_DESTROY(""), BLOCK_PLACE(""), LEAF("step.grass"), LOG("dig.wood"), DIRT("dig.gravel"); public final String soundFile; public final float volume = 1.0f; public final float pitch = 1.0f; - private SoundFXType(String soundFile) { + SoundFXType(String soundFile) { this.soundFile = soundFile; } } diff --git a/src/main/java/forestry/core/render/RenderAnalyzer.java b/src/main/java/forestry/core/render/RenderAnalyzer.java index fc036d8d8..9078db829 100755 --- a/src/main/java/forestry/core/render/RenderAnalyzer.java +++ b/src/main/java/forestry/core/render/RenderAnalyzer.java @@ -28,7 +28,7 @@ import forestry.core.interfaces.IBlockRenderer; public class RenderAnalyzer extends TileEntitySpecialRenderer implements IBlockRenderer { - private ModelAnalyzer model; + private final ModelAnalyzer model; private final EntityItem dummyEntityItem = new EntityItem(null); private final RenderItem customRenderItem; private long lastTick; diff --git a/src/main/java/forestry/core/render/RenderMachine.java b/src/main/java/forestry/core/render/RenderMachine.java index d5d52dca2..e0ed9a457 100755 --- a/src/main/java/forestry/core/render/RenderMachine.java +++ b/src/main/java/forestry/core/render/RenderMachine.java @@ -36,7 +36,7 @@ public class RenderMachine extends TileEntitySpecialRenderer implements IBlockRe private final ModelRenderer resourceTank; private final ModelRenderer productTank; - private static enum Textures { + private enum Textures { BASE, TANK_R_EMPTY, TANK_R_LOW, TANK_R_MEDIUM, TANK_R_HIGH, TANK_R_MAXIMUM, TANK_P_EMPTY, TANK_P_LOW, TANK_P_MEDIUM, TANK_P_HIGH, TANK_P_MAXIMUM @@ -115,46 +115,35 @@ public class RenderMachine extends TileEntitySpecialRenderer implements IBlockRe EnumTankLevel melangeLevel = EnumTankLevel.values()[melangeLevelInt]; GL11.glPushMatrix(); - // GL11.glDisable(2896 /* GL_LIGHTING */); GL11.glDisable(GL11.GL_LIGHTING); - GL11.glTranslatef((float) x, (float) y, (float) z); float[] angle = {0, 0, 0}; - float[] translate = {0, 0, 0}; if (orientation == null) { orientation = ForgeDirection.WEST; } switch (orientation) { case EAST: - // angle [2] = (float) Math.PI / 2; angle[1] = (float) Math.PI; angle[2] = (float) -Math.PI / 2; - translate[0] = 1; break; case WEST: - // 2, -PI/2 angle[2] = (float) Math.PI / 2; - translate[0] = -1; break; case UP: - translate[1] = 1; break; case DOWN: angle[2] = (float) Math.PI; - translate[1] = -1; break; case SOUTH: angle[0] = (float) Math.PI / 2; angle[2] = (float) Math.PI / 2; - translate[2] = 1; break; case NORTH: default: angle[0] = (float) -Math.PI / 2; angle[2] = (float) Math.PI / 2; - translate[2] = -1; break; } @@ -226,7 +215,6 @@ public class RenderMachine extends TileEntitySpecialRenderer implements IBlockRe Proxies.common.bindTexture(texture); productTank.render(factor); - // GL11.glEnable(2896 /* GL_LIGHTING */); GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); } diff --git a/src/main/java/forestry/core/render/RenderMill.java b/src/main/java/forestry/core/render/RenderMill.java index 656b173c7..dec40df06 100755 --- a/src/main/java/forestry/core/render/RenderMill.java +++ b/src/main/java/forestry/core/render/RenderMill.java @@ -30,7 +30,7 @@ public class RenderMill extends TileEntitySpecialRenderer implements IBlockRende private final ModelBase model = new ModelBase() { }; - private static enum Textures {PEDESTAL, EXTENSION, BLADE_1, BLADE_2, CHARGE} + private enum Textures {PEDESTAL, EXTENSION, BLADE_1, BLADE_2, CHARGE} private ResourceLocation[] textures; diff --git a/src/main/java/forestry/core/utils/AdjacentTileCache.java b/src/main/java/forestry/core/utils/AdjacentTileCache.java index fec69b60e..dfa0bbae7 100644 --- a/src/main/java/forestry/core/utils/AdjacentTileCache.java +++ b/src/main/java/forestry/core/utils/AdjacentTileCache.java @@ -34,7 +34,7 @@ public final class AdjacentTileCache { private final TileEntity source; private final Set listeners = new LinkedHashSet(); - public static interface ICacheListener { + public interface ICacheListener { void changed(); diff --git a/src/main/java/forestry/core/utils/EnumAccess.java b/src/main/java/forestry/core/utils/EnumAccess.java index 15a74461e..43176834b 100755 --- a/src/main/java/forestry/core/utils/EnumAccess.java +++ b/src/main/java/forestry/core/utils/EnumAccess.java @@ -23,7 +23,7 @@ public enum EnumAccess { @SideOnly(Side.CLIENT) private IIcon icon; - private EnumAccess(String name) { + EnumAccess(String name) { this.name = name; } diff --git a/src/main/java/forestry/core/utils/Utils.java b/src/main/java/forestry/core/utils/Utils.java index ad6902f19..093a9fd37 100755 --- a/src/main/java/forestry/core/utils/Utils.java +++ b/src/main/java/forestry/core/utils/Utils.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.core.utils; -import java.security.MessageDigest; -import java.security.cert.Certificate; import java.util.Arrays; import java.util.Random; @@ -23,10 +21,8 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryLargeChest; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; @@ -37,7 +33,6 @@ import forestry.api.core.ForestryAPI; import forestry.api.core.ITileStructure; import forestry.core.gadgets.TileForestry; import forestry.core.proxy.Proxies; -import forestry.core.vect.Vect; import buildcraft.api.tools.IToolWrench; @@ -109,26 +104,6 @@ public class Utils { } - public static IInventory getChest(IInventory inventory) { - if (!(inventory instanceof TileEntityChest)) { - return inventory; - } - - TileEntityChest chest = (TileEntityChest) inventory; - - Vect[] adjacent = new Vect[]{new Vect(chest.xCoord + 1, chest.yCoord, chest.zCoord), new Vect(chest.xCoord - 1, chest.yCoord, chest.zCoord), - new Vect(chest.xCoord, chest.yCoord, chest.zCoord + 1), new Vect(chest.xCoord, chest.yCoord, chest.zCoord - 1)}; - - for (Vect pos : adjacent) { - TileEntity otherchest = chest.getWorldObj().getTileEntity(pos.x, pos.y, pos.z); - if (otherchest instanceof TileEntityChest) { - return new InventoryLargeChest("", chest, (TileEntityChest) otherchest); - } - } - - return inventory; - } - public static T[] concat(T[] first, T[] second) { T[] result = Arrays.copyOf(first, first.length + second.length); System.arraycopy(second, 0, result, first.length, second.length); @@ -165,11 +140,7 @@ public class Utils { } IToolWrench wrench = (IToolWrench) itemstack.getItem(); - if (!wrench.canWrench(player, x, y, z)) { - return false; - } - - return true; + return wrench.canWrench(player, x, y, z); } public static void useWrench(EntityPlayer player, int x, int y, int z) { @@ -212,14 +183,6 @@ public class Utils { || block.getMaterial().isReplaceable(); } - public static boolean isLiquidBlock(World world, int x, int y, int z) { - return isLiquidBlock(world.getBlock(x, y, z)); - } - - public static boolean isLiquidBlock(Block block) { - return block == Blocks.water || block == Blocks.flowing_water || block == Blocks.lava || block == Blocks.flowing_lava; - } - public static boolean isUseableByPlayer(EntityPlayer player, TileEntity tile) { int x = tile.xCoord; int y = tile.yCoord; @@ -242,28 +205,45 @@ public class Utils { return world.getBiomeGenForCoordsBody(x, z); } - public static Entity spawnEntity(World world, Class entityClass, double x, double y, double z) { + private static E createEntity(World world, Class entityClass) { if (!EntityList.classToStringMapping.containsKey(entityClass)) { return null; } - return spawnEntity(world, EntityList.createEntityByName((String) EntityList.classToStringMapping.get(entityClass), world), x, y, z); - } - - public static Entity spawnEntity(World world, Entity spawn, double x, double y, double z) { - - if (spawn != null && spawn instanceof EntityLiving) { - - EntityLiving living = (EntityLiving) spawn; - spawn.setLocationAndAngles(x, y, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0f), 0.0f); - living.rotationYawHead = living.rotationYaw; - living.renderYawOffset = living.rotationYaw; - living.onSpawnWithEgg(null); - world.spawnEntityInWorld(spawn); - living.playLivingSound(); + String entityString = (String) EntityList.classToStringMapping.get(entityClass); + if (entityString == null) { + return null; } - return spawn; + Entity entity = EntityList.createEntityByName(entityString, world); + if (entity == null) { + return null; + } + + //noinspection unchecked + return (E) entity; + } + + public static E spawnEntity(World world, Class entityClass, double x, double y, double z) { + E entityLiving = createEntity(world, entityClass); + if (entityLiving == null) { + return null; + } + return spawnEntity(world, entityLiving, x, y, z); + } + + public static E spawnEntity(World world, E living, double x, double y, double z) { + if (living == null) { + return null; + } + + living.setLocationAndAngles(x, y, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0f), 0.0f); + living.rotationYawHead = living.rotationYaw; + living.renderYawOffset = living.rotationYaw; + living.onSpawnWithEgg(null); + world.spawnEntityInWorld(living); + living.playLivingSound(); + return living; } public static void registerEntity(Class entityClass, String ident, int id, int eggForeground, int eggBackground, int trackingRange, int updateFrequency, boolean sendVelocity) { @@ -294,31 +274,4 @@ public class Utils { return ((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff); } - - public static String getFingerprint(Certificate certificate) { - if (certificate == null) { - return "Certificate invalid"; - } - - try { - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] der = certificate.getEncoded(); - md.update(der); - byte[] digest = md.digest(); - return tohex(digest); - } catch (Exception ex) { - return null; - } - } - - private static final String HEX = "0123456789abcdef"; - - private static String tohex(byte[] checksum) { - - final StringBuilder hex = new StringBuilder(2 * checksum.length); - for (byte bty : checksum) { - hex.append(HEX.charAt((bty & 0xf0) >> 4)).append(HEX.charAt((bty & 0x0f))); - } - return hex.toString(); - } } diff --git a/src/main/java/forestry/energy/render/RenderEngine.java b/src/main/java/forestry/energy/render/RenderEngine.java index 5ff114729..57d455edd 100755 --- a/src/main/java/forestry/energy/render/RenderEngine.java +++ b/src/main/java/forestry/energy/render/RenderEngine.java @@ -36,7 +36,7 @@ public class RenderEngine extends TileEntitySpecialRenderer implements IBlockRen private final ModelRenderer piston; private final ModelRenderer extension; - private static enum Textures { + private enum Textures { BASE, PISTON, EXTENSION, TRUNK_HIGHEST, TRUNK_HIGHER, TRUNK_HIGH, TRUNK_MEDIUM, TRUNK_LOW } diff --git a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java index 4a902e3e8..34459285b 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java @@ -446,7 +446,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL // Need at least one matched set ItemStack[] set = InvTools.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); ItemStack[] stock = InvTools.getStacks(accessibleInventory, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); - ; + return StackUtils.containsSets(set, stock, true, false) > 0; } diff --git a/src/main/java/forestry/factory/gadgets/MachineFermenter.java b/src/main/java/forestry/factory/gadgets/MachineFermenter.java index 2690e3272..9a189f457 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFermenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineFermenter.java @@ -108,11 +108,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL return false; } - // No liquid required - if (liquid == null) { - return true; - } - // Liquid required but none given if (liqu == null) { return false; diff --git a/src/main/java/forestry/farming/gadgets/BlockFarm.java b/src/main/java/forestry/farming/gadgets/BlockFarm.java index e3a8c7068..423ba8287 100755 --- a/src/main/java/forestry/farming/gadgets/BlockFarm.java +++ b/src/main/java/forestry/farming/gadgets/BlockFarm.java @@ -13,6 +13,7 @@ package forestry.farming.gadgets; import java.util.ArrayList; import java.util.List; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.particle.EffectRenderer; import net.minecraft.client.particle.EntityDiggingFX; @@ -200,7 +201,12 @@ public class BlockFarm extends BlockStructure { @SideOnly(Side.CLIENT) public IIcon getBlockTextureFromSideAndMetadata(EnumFarmBlock type, int side, int metadata) { - return StackUtils.getBlock(type.getBase()).getIcon(side, type.getBase().getItemDamage()); + Block block = StackUtils.getBlock(type.getBase()); + if (block == null) { + return null; + } + int damage = type.getBase().getItemDamage(); + return block.getIcon(side, damage); } @SideOnly(Side.CLIENT) @@ -244,6 +250,11 @@ public class BlockFarm extends BlockStructure { base = ((TileFarm) tile).farmBlock.getBase(); } - return StackUtils.getBlock(base).getIcon(side, base.getItemDamage()); + Block block = StackUtils.getBlock(base); + if (block == null) { + return null; + } + + return block.getIcon(side, base.getItemDamage()); } } diff --git a/src/main/java/forestry/farming/gadgets/EnumFarmBlock.java b/src/main/java/forestry/farming/gadgets/EnumFarmBlock.java index 2d0bfa6ce..82c782398 100644 --- a/src/main/java/forestry/farming/gadgets/EnumFarmBlock.java +++ b/src/main/java/forestry/farming/gadgets/EnumFarmBlock.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.farming.gadgets; +import javax.annotation.Nonnull; import java.util.Arrays; import java.util.List; @@ -57,7 +58,7 @@ public enum EnumFarmBlock { private final ItemStack base; - private EnumFarmBlock(ItemStack base) { + EnumFarmBlock(ItemStack base) { this.base = base; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java index f777d1060..1c6c1ea2e 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java @@ -45,15 +45,12 @@ import forestry.core.vect.VectUtil; public class FarmLogicArboreal extends FarmLogicHomogeneous { - public FarmLogicArboreal(IFarmHousing housing, ItemStack[] resource, ItemStack ground, IFarmable[] germlings) { + public FarmLogicArboreal(IFarmHousing housing, ItemStack resource, ItemStack ground, Iterable germlings) { super(housing, resource, ground, germlings); } public FarmLogicArboreal(IFarmHousing housing) { - super(housing, - new ItemStack[]{new ItemStack(Blocks.dirt)}, - ForestryBlock.soil.getItemStack(1, 0), - Farmables.farmables.get("farmArboreal").toArray(new IFarmable[0])); + super(housing, new ItemStack(Blocks.dirt), ForestryBlock.soil.getItemStack(1, 0), Farmables.farmables.get("farmArboreal")); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicCereal.java b/src/main/java/forestry/farming/logic/FarmLogicCereal.java index 2630cecad..1d8c1c1bf 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCereal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCereal.java @@ -23,7 +23,7 @@ import forestry.api.farming.IFarmable; public class FarmLogicCereal extends FarmLogicCrops { public FarmLogicCereal(IFarmHousing housing) { - super(housing, Farmables.farmables.get("farmWheat").toArray(new IFarmable[0])); + super(housing, Farmables.farmables.get("farmWheat")); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicCrops.java b/src/main/java/forestry/farming/logic/FarmLogicCrops.java index 6d70b4bee..b2ede7c18 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCrops.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCrops.java @@ -36,13 +36,11 @@ import forestry.core.vect.VectUtil; public abstract class FarmLogicCrops extends FarmLogicWatered { - private final IFarmable[] seeds; + private final Iterable seeds; private static final ItemStack farmland = new ItemStack(Blocks.farmland, 1, Defaults.WILDCARD); - public FarmLogicCrops(IFarmHousing housing, IFarmable[] seeds) { - super(housing, - new ItemStack[]{new ItemStack(Blocks.dirt)}, - new ItemStack(Blocks.farmland)); + public FarmLogicCrops(IFarmHousing housing, Iterable seeds) { + super(housing, new ItemStack(Blocks.dirt), new ItemStack(Blocks.farmland)); this.seeds = seeds; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicEnder.java b/src/main/java/forestry/farming/logic/FarmLogicEnder.java index 2e1e14e2f..922c51c6d 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicEnder.java +++ b/src/main/java/forestry/farming/logic/FarmLogicEnder.java @@ -35,11 +35,7 @@ import forestry.core.vect.VectUtil; public class FarmLogicEnder extends FarmLogicHomogeneous { public FarmLogicEnder(IFarmHousing housing) { - super(housing, - new ItemStack[]{new ItemStack(Blocks.end_stone)}, - new ItemStack(Blocks.end_stone), - Farmables.farmables.get("farmEnder").toArray(new IFarmable[0])); - + super(housing, new ItemStack(Blocks.end_stone), new ItemStack(Blocks.end_stone), Farmables.farmables.get("farmEnder")); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java b/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java index 17bb3cc76..b48440e8f 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java +++ b/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java @@ -28,13 +28,13 @@ import forestry.farming.gadgets.StructureLogicFarm; public abstract class FarmLogicHomogeneous extends FarmLogic { - protected final ItemStack[] resource; + protected final ItemStack resource; protected final ItemStack soilBlock; - protected final IFarmable[] germlings; + protected final Iterable germlings; ArrayList produce = new ArrayList(); - public FarmLogicHomogeneous(IFarmHousing housing, ItemStack[] resource, ItemStack soilBlock, IFarmable[] germlings) { + public FarmLogicHomogeneous(IFarmHousing housing, ItemStack resource, ItemStack soilBlock, Iterable germlings) { super(housing); this.resource = resource; this.soilBlock = soilBlock; @@ -47,7 +47,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic { @Override public boolean isAcceptedResource(ItemStack itemstack) { - return resource[0].isItemEqual(itemstack); + return resource.isItemEqual(itemstack); } @Override @@ -84,7 +84,8 @@ public abstract class FarmLogicHomogeneous extends FarmLogic { } private boolean maintainSoil(int x, int yGround, int z, ForgeDirection direction, int extent) { - if (!housing.hasResources(resource)) { + ItemStack[] resources = new ItemStack[]{resource}; + if (!housing.hasResources(resources)) { return false; } @@ -113,7 +114,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic { produce.addAll(BlockUtil.getBlockDrops(world, position)); setBlock(position, StackUtils.getBlock(soilBlock), soilBlock.getItemDamage()); - housing.removeResources(resource); + housing.removeResources(resources); return true; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicInfernal.java b/src/main/java/forestry/farming/logic/FarmLogicInfernal.java index 271c617e8..55e9dd12e 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicInfernal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicInfernal.java @@ -35,10 +35,7 @@ import forestry.core.vect.VectUtil; public class FarmLogicInfernal extends FarmLogicHomogeneous { public FarmLogicInfernal(IFarmHousing housing) { - super(housing, - new ItemStack[]{new ItemStack(Blocks.soul_sand)}, - new ItemStack(Blocks.soul_sand), - Farmables.farmables.get("farmInfernal").toArray(new IFarmable[0])); + super(housing, new ItemStack(Blocks.soul_sand), new ItemStack(Blocks.soul_sand), Farmables.farmables.get("farmInfernal")); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicPeat.java b/src/main/java/forestry/farming/logic/FarmLogicPeat.java index ed56279f7..bd9ddd469 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicPeat.java +++ b/src/main/java/forestry/farming/logic/FarmLogicPeat.java @@ -34,8 +34,7 @@ import forestry.core.vect.VectUtil; public class FarmLogicPeat extends FarmLogicWatered { public FarmLogicPeat(IFarmHousing housing) { - super(housing, new ItemStack[]{ForestryBlock.soil.getItemStack(1, 1)}, - ForestryBlock.soil.getItemStack(1, 1)); + super(housing, ForestryBlock.soil.getItemStack(1, 1), ForestryBlock.soil.getItemStack(1, 1)); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicShroom.java b/src/main/java/forestry/farming/logic/FarmLogicShroom.java index 3c617a5b2..5f6fc8999 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicShroom.java +++ b/src/main/java/forestry/farming/logic/FarmLogicShroom.java @@ -27,10 +27,7 @@ import forestry.api.farming.IFarmable; public class FarmLogicShroom extends FarmLogicArboreal { public FarmLogicShroom(IFarmHousing housing) { - super(housing, - new ItemStack[]{new ItemStack(Blocks.mycelium)}, - new ItemStack(Blocks.mycelium), - Farmables.farmables.get("farmShroom").toArray(new IFarmable[0])); + super(housing, new ItemStack(Blocks.mycelium), new ItemStack(Blocks.mycelium), Farmables.farmables.get("farmShroom")); yOffset = -1; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicVegetable.java b/src/main/java/forestry/farming/logic/FarmLogicVegetable.java index 0e7d7e4be..52f3fcc88 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicVegetable.java +++ b/src/main/java/forestry/farming/logic/FarmLogicVegetable.java @@ -23,7 +23,7 @@ import forestry.api.farming.IFarmable; public class FarmLogicVegetable extends FarmLogicCrops { public FarmLogicVegetable(IFarmHousing housing) { - super(housing, Farmables.farmables.get("farmVegetables").toArray(new IFarmable[0])); + super(housing, Farmables.farmables.get("farmVegetables")); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicWatered.java b/src/main/java/forestry/farming/logic/FarmLogicWatered.java index 444a767de..629582beb 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicWatered.java +++ b/src/main/java/forestry/farming/logic/FarmLogicWatered.java @@ -32,13 +32,13 @@ import forestry.core.vect.VectUtil; public abstract class FarmLogicWatered extends FarmLogic { protected final ItemStack ground; - private final ItemStack[] resource; + private final ItemStack resource; private static final FluidStack STACK_WATER = Fluids.WATER.getFluid(1000); ArrayList produce = new ArrayList(); - public FarmLogicWatered(IFarmHousing housing, ItemStack[] resource, ItemStack ground) { + public FarmLogicWatered(IFarmHousing housing, ItemStack resource, ItemStack ground) { super(housing); this.ground = ground; this.resource = resource; @@ -60,7 +60,7 @@ public abstract class FarmLogicWatered extends FarmLogic { @Override public boolean isAcceptedResource(ItemStack itemstack) { - return resource[0].isItemEqual(itemstack); + return resource.isItemEqual(itemstack); } @Override @@ -91,6 +91,7 @@ public abstract class FarmLogicWatered extends FarmLogic { private boolean maintainSoil(int x, int y, int z, ForgeDirection direction, int extent) { World world = getWorld(); + ItemStack[] resources = new ItemStack[]{resource}; for (int i = 0; i < extent; i++) { Vect position = translateWithOffset(x, y, z, direction, i); @@ -98,7 +99,7 @@ public abstract class FarmLogicWatered extends FarmLogic { if (!isAirBlock(block) && !Utils.isReplaceableBlock(block)) { ItemStack blockStack = VectUtil.getAsItemStack(world, position); - if (!isAcceptedGround(blockStack) && housing.hasResources(resource)) { + if (!isAcceptedGround(blockStack) && housing.hasResources(resources)) { produce.addAll(BlockUtil.getBlockDrops(getWorld(), position)); setBlock(position, Blocks.air, 0); return trySetSoil(position); @@ -140,11 +141,12 @@ public abstract class FarmLogicWatered extends FarmLogic { } private boolean trySetSoil(Vect position) { - if (!housing.hasResources(resource)) { + ItemStack[] resources = new ItemStack[]{resource}; + if (!housing.hasResources(resources)) { return false; } setBlock(position, StackUtils.getBlock(ground), ground.getItemDamage()); - housing.removeResources(resource); + housing.removeResources(resources); return true; } diff --git a/src/main/java/forestry/farming/render/FarmItemRenderer.java b/src/main/java/forestry/farming/render/FarmItemRenderer.java index 105ec968f..e19c82ac0 100755 --- a/src/main/java/forestry/farming/render/FarmItemRenderer.java +++ b/src/main/java/forestry/farming/render/FarmItemRenderer.java @@ -32,6 +32,9 @@ public class FarmItemRenderer implements IItemRenderer { Tessellator tessellator = Tessellator.instance; BlockFarm block = (BlockFarm) StackUtils.getBlock(item); + if (block == null) { + return; + } block.setBlockBoundsForItemRender(); render.setRenderBoundsFromBlock(block); diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java index 41b3ee151..930639e59 100644 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java @@ -47,14 +47,18 @@ public class AIButterflyPollinate extends AIButterflyInteract { public void updateTask() { if (continueExecuting()) { ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(entity.worldObj, rest.posX, rest.posY, rest.posZ); - if (entity.getPollen() == null) { - entity.setPollen(checkPollinatable.getPollen()); - // Proxies.log.finest("A butterfly '%s' grabbed a pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ); - } else if (checkPollinatable.canMateWith(entity.getPollen())) { - IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ); - realPollinatable.mateWith(entity.getPollen()); - // Proxies.log.finest("A butterfly '%s' unloaded pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ); - entity.setPollen(null); + if (checkPollinatable != null) { + if (entity.getPollen() == null) { + entity.setPollen(checkPollinatable.getPollen()); +// Proxies.log.finest("A butterfly '%s' grabbed a pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ); + } else if (checkPollinatable.canMateWith(entity.getPollen())) { + IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ); + if (realPollinatable != null) { + realPollinatable.mateWith(entity.getPollen()); +// Proxies.log.finest("A butterfly '%s' unloaded pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ); + entity.setPollen(null); + } + } } setHasInteracted(); entity.cooldownPollination = EntityButterfly.COOLDOWNS; diff --git a/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java b/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java index b17a4b3cc..13efaab7d 100755 --- a/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java +++ b/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java @@ -60,7 +60,7 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly public final boolean doesMovement; - private EnumButterflyState(boolean doesMovement) { + EnumButterflyState(boolean doesMovement) { this.doesMovement = doesMovement; } diff --git a/src/main/java/forestry/lepidopterology/genetics/ButterflyHelper.java b/src/main/java/forestry/lepidopterology/genetics/ButterflyHelper.java index 19f03da28..e4b4e2be2 100755 --- a/src/main/java/forestry/lepidopterology/genetics/ButterflyHelper.java +++ b/src/main/java/forestry/lepidopterology/genetics/ButterflyHelper.java @@ -15,7 +15,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Map.Entry; -import net.minecraft.entity.EntityLiving; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -148,8 +147,8 @@ public class ButterflyHelper extends SpeciesRoot implements IButterflyRoot { } @Override - public EntityLiving spawnButterflyInWorld(World world, IButterfly butterfly, double x, double y, double z) { - return (EntityButterfly) Utils.spawnEntity(world, new EntityButterfly(world, butterfly), x, y, z); + public EntityButterfly spawnButterflyInWorld(World world, IButterfly butterfly, double x, double y, double z) { + return Utils.spawnEntity(world, new EntityButterfly(world, butterfly), x, y, z); } @Override diff --git a/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java b/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java index 561876553..f1560c6bf 100755 --- a/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java @@ -25,6 +25,7 @@ import forestry.api.genetics.IAlleleInteger; import forestry.api.genetics.IAlleleTolerance; import forestry.api.genetics.IMutation; import forestry.api.lepidopterology.EnumButterflyChromosome; +import forestry.api.lepidopterology.IAlleleButterflySpecies; import forestry.api.lepidopterology.IButterfly; import forestry.core.config.ForestryItem; import forestry.core.genetics.AlleleBoolean; @@ -45,9 +46,11 @@ public class GuiFlutterlyzer extends GuiAlyzer { ArrayList butterflyList = new ArrayList(); ((ItemButterflyGE) ForestryItem.butterflyGE.item()).addCreativeItems(butterflyList, false); for (ItemStack butterflyStack : butterflyList) { - iconStacks.put(ButterflyGenome.getSpecies(butterflyStack).getUID(), butterflyStack); + IAlleleButterflySpecies species = ButterflyGenome.getSpecies(butterflyStack); + if (species != null) { + iconStacks.put(species.getUID(), butterflyStack); + } } - } @Override @@ -263,40 +266,38 @@ public class GuiFlutterlyzer extends GuiAlyzer { newLine(); newLine(); - RenderHelper.enableGUIStandardItemLighting(); - - HashMap combinations = new HashMap(); - - /* - for (IMutation mutation : TreeTemplates.getCombinations(butterfly.getGenome().getPrimary())) - combinations.put(mutation, butterfly.getGenome().getPrimary()); - - for (IMutation mutation : TreeTemplates.getCombinations(butterfly.getGenome().getSecondary())) - combinations.put(mutation, butterfly.getGenome().getSecondary()); - */ - - int columnWidth = 50; - int x = 0; - - for (Map.Entry mutation : combinations.entrySet()) { - - //if (breedingTracker.isDiscovered(mutation.getKey())) - drawMutationInfo(mutation.getKey(), mutation.getValue(), COLUMN_0 + x); - /*else { - // Do not display secret undiscovered mutations. - if (mutation.getKey().isSecret()) - continue; - - drawUnknownMutation(mutation.getKey(), mutation.getValue(), COLUMN_0 + x); - } */ - - x += columnWidth; - if (x > 150) { - x = 0; - newLine(); - newLine(); - } - } +// RenderHelper.enableGUIStandardItemLighting(); +// +// HashMap combinations = new HashMap(); +// +// for (IMutation mutation : TreeTemplates.getCombinations(butterfly.getGenome().getPrimary())) +// combinations.put(mutation, butterfly.getGenome().getPrimary()); +// +// for (IMutation mutation : TreeTemplates.getCombinations(butterfly.getGenome().getSecondary())) +// combinations.put(mutation, butterfly.getGenome().getSecondary()); +// +// int columnWidth = 50; +// int x = 0; +// +// for (Map.Entry mutation : combinations.entrySet()) { +// +// //if (breedingTracker.isDiscovered(mutation.getKey())) +// drawMutationInfo(mutation.getKey(), mutation.getValue(), COLUMN_0 + x); +// /*else { +// // Do not display secret undiscovered mutations. +// if (mutation.getKey().isSecret()) +// continue; +// +// drawUnknownMutation(mutation.getKey(), mutation.getValue(), COLUMN_0 + x); +// } */ +// +// x += columnWidth; +// if (x > 150) { +// x = 0; +// newLine(); +// newLine(); +// } +// } endPage(); diff --git a/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java b/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java index 8e31fc35f..70909298a 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java +++ b/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java @@ -45,7 +45,7 @@ import forestry.plugins.PluginLepidopterology; public class ItemButterflyGE extends ItemGE { - private static Random rand = new Random(); + private static final Random rand = new Random(); private final EnumFlutterType type; diff --git a/src/main/java/forestry/plugins/PluginManager.java b/src/main/java/forestry/plugins/PluginManager.java index 2eedc9b03..5db1bda8d 100755 --- a/src/main/java/forestry/plugins/PluginManager.java +++ b/src/main/java/forestry/plugins/PluginManager.java @@ -96,11 +96,11 @@ public class PluginManager { private final ForestryPlugin instance; private final boolean canBeDisabled; - private Module(ForestryPlugin plugin) { + Module(ForestryPlugin plugin) { this(plugin, true); } - private Module(ForestryPlugin plugin, boolean canBeDisabled) { + Module(ForestryPlugin plugin, boolean canBeDisabled) { this.instance = plugin; this.canBeDisabled = canBeDisabled; } diff --git a/src/main/java/forestry/storage/BackpackDefinition.java b/src/main/java/forestry/storage/BackpackDefinition.java index eca8c8ee4..10ffb5047 100755 --- a/src/main/java/forestry/storage/BackpackDefinition.java +++ b/src/main/java/forestry/storage/BackpackDefinition.java @@ -99,12 +99,7 @@ public class BackpackDefinition implements IBackpackDefinition { // isValidItem can get called multiple times per tick if the player's inventory is full // and they are standing on multiple items. // It is a slow call, so we need a cache to make it fast - private Map isValidItemCache = new LinkedHashMap() { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > 64; - } - }; + private final Map isValidItemCache = new ValidItemCache(); @Override public boolean isValidItem(EntityPlayer player, ItemStack itemstack) { @@ -128,4 +123,11 @@ public class BackpackDefinition implements IBackpackDefinition { isValidItemCache.put(itemstack, false); return false; } + + private static class ValidItemCache extends LinkedHashMap { + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > 64; + } + } }