diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 0bbb15f57..538d7a4d5 100644 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -35,7 +35,6 @@ import forestry.core.EventHandlerCore; import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.config.GameMode; -import forestry.core.config.Version; import forestry.core.errors.EnumErrorCode; import forestry.core.errors.ErrorStateRegistry; import forestry.core.gui.GuiHandler; @@ -55,7 +54,7 @@ import forestry.plugins.PluginManager; @Mod( modid = Constants.MOD, name = "Forestry", - version = Version.VERSION, + version = Constants.VERSION, guiFactory = "forestry.core.config.ForestryGuiConfigFactory", dependencies = "required-after:Forge@[10.13.4.1566,);" + "after:Buildcraft|Core@[6.1.7,);" diff --git a/src/main/java/forestry/api/apiculture/EnumBeeChromosome.java b/src/main/java/forestry/api/apiculture/EnumBeeChromosome.java index ba146d225..b92e1fc05 100644 --- a/src/main/java/forestry/api/apiculture/EnumBeeChromosome.java +++ b/src/main/java/forestry/api/apiculture/EnumBeeChromosome.java @@ -44,14 +44,9 @@ public enum EnumBeeChromosome implements IChromosomeType { */ TEMPERATURE_TOLERANCE(IAlleleTolerance.class), /** - * Slightly incorrectly named. If true, a naturally diurnal bee can work during the night. If true, a naturally nocturnal bee can work during the day. + * If true, a naturally diurnal bee can work during the night. If true, a naturally nocturnal bee can work during the day. */ - NOCTURNAL(IAlleleBoolean.class), - /** - * Not used / superseded by fixed values for the species. Probably going to be replaced with a boolean for FIRE_RESIST. - */ - @Deprecated - HUMIDITY(IAllele.class), + NEVER_SLEEPS(IAlleleBoolean.class), /** * Humidity difference to its native supported one the bee can tolerate. */ diff --git a/src/main/java/forestry/api/apiculture/IBeekeepingLogic.java b/src/main/java/forestry/api/apiculture/IBeekeepingLogic.java index 3efb08d85..564ff35e3 100644 --- a/src/main/java/forestry/api/apiculture/IBeekeepingLogic.java +++ b/src/main/java/forestry/api/apiculture/IBeekeepingLogic.java @@ -7,14 +7,15 @@ package forestry.api.apiculture; import net.minecraft.entity.player.EntityPlayerMP; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; /** * Stores beekeeping logic for bee housings. * Get one with BeeManager.beeRoot.createBeekeepingLogic(IBeeHousing housing) - * Save and load it to NBT using the INBTTagable methods. + * Save and load it to NBT using the INbtWritable methods. */ -public interface IBeekeepingLogic extends INBTTagable { +public interface IBeekeepingLogic extends INbtWritable, INbtReadable { /* SERVER */ diff --git a/src/main/java/forestry/api/arboriculture/ITree.java b/src/main/java/forestry/api/arboriculture/ITree.java index 617a44a76..3a693e6ff 100644 --- a/src/main/java/forestry/api/arboriculture/ITree.java +++ b/src/main/java/forestry/api/arboriculture/ITree.java @@ -5,6 +5,7 @@ ******************************************************************************/ package forestry.api.arboriculture; +import javax.annotation.Nonnull; import java.util.EnumSet; import net.minecraft.item.ItemStack; @@ -29,6 +30,7 @@ public interface ITree extends IIndividual, ITreeGenData { IEffectData[] doFX(IEffectData[] storedData, World world, BlockPos pos); + @Nonnull @Override ITreeGenome getGenome(); diff --git a/src/main/java/forestry/api/circuits/ICircuitBoard.java b/src/main/java/forestry/api/circuits/ICircuitBoard.java index 14666f046..751982fc0 100644 --- a/src/main/java/forestry/api/circuits/ICircuitBoard.java +++ b/src/main/java/forestry/api/circuits/ICircuitBoard.java @@ -5,11 +5,12 @@ ******************************************************************************/ package forestry.api.circuits; +import javax.annotation.Nonnull; import java.util.List; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; -public interface ICircuitBoard extends INBTTagable { +public interface ICircuitBoard extends INbtWritable { int getPrimaryColor(); @@ -24,13 +25,14 @@ public interface ICircuitBoard extends INBTTagable { void onRemoval(Object tile); void onTick(Object tile); - + + @Nonnull ICircuit[] getCircuits(); /** * Specifies where a circuit can be used. - * @since Forestry 4.0 */ + @Nonnull ICircuitSocketType getSocketType(); } diff --git a/src/main/java/forestry/api/circuits/ICircuitLayout.java b/src/main/java/forestry/api/circuits/ICircuitLayout.java index 9988b78dd..338c38d51 100644 --- a/src/main/java/forestry/api/circuits/ICircuitLayout.java +++ b/src/main/java/forestry/api/circuits/ICircuitLayout.java @@ -5,21 +5,26 @@ ******************************************************************************/ package forestry.api.circuits; +import javax.annotation.Nonnull; + public interface ICircuitLayout { /** unique ID for this circuit layout */ + @Nonnull String getUID(); /** localized name for this circuit layout */ + @Nonnull String getName(); /** localized string for how this circuit layout is used */ + @Nonnull String getUsage(); /** * Specifies where a circuit layout is used. - * @since Forestry 4.0 */ + @Nonnull ICircuitSocketType getSocketType(); } diff --git a/src/main/java/forestry/api/core/INbtReadable.java b/src/main/java/forestry/api/core/INbtReadable.java new file mode 100644 index 000000000..af6691caf --- /dev/null +++ b/src/main/java/forestry/api/core/INbtReadable.java @@ -0,0 +1,7 @@ +package forestry.api.core; + +import net.minecraft.nbt.NBTTagCompound; + +public interface INbtReadable { + void readFromNBT(NBTTagCompound nbt); +} diff --git a/src/main/java/forestry/api/core/INBTTagable.java b/src/main/java/forestry/api/core/INbtWritable.java similarity index 73% rename from src/main/java/forestry/api/core/INBTTagable.java rename to src/main/java/forestry/api/core/INbtWritable.java index f55cd1c0f..fd8271f2f 100644 --- a/src/main/java/forestry/api/core/INBTTagable.java +++ b/src/main/java/forestry/api/core/INbtWritable.java @@ -7,8 +7,6 @@ package forestry.api.core; import net.minecraft.nbt.NBTTagCompound; -public interface INBTTagable { - void readFromNBT(NBTTagCompound nbttagcompound); - - void writeToNBT(NBTTagCompound nbttagcompound); +public interface INbtWritable { + void writeToNBT(NBTTagCompound nbt); } diff --git a/src/main/java/forestry/api/farming/ICrop.java b/src/main/java/forestry/api/farming/ICrop.java index 6dd967df3..7c5b34985 100644 --- a/src/main/java/forestry/api/farming/ICrop.java +++ b/src/main/java/forestry/api/farming/ICrop.java @@ -5,6 +5,7 @@ ******************************************************************************/ package forestry.api.farming; +import javax.annotation.Nullable; import java.util.Collection; import net.minecraft.item.ItemStack; @@ -16,6 +17,7 @@ public interface ICrop { * * @return Products harvested. */ + @Nullable Collection harvest(); } diff --git a/src/main/java/forestry/api/genetics/IChromosome.java b/src/main/java/forestry/api/genetics/IChromosome.java index 0d2b1c04e..331cc3d19 100644 --- a/src/main/java/forestry/api/genetics/IChromosome.java +++ b/src/main/java/forestry/api/genetics/IChromosome.java @@ -5,14 +5,14 @@ ******************************************************************************/ package forestry.api.genetics; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; /** * Implementations other than Forestry's default one are not supported! * * @author SirSengir */ -public interface IChromosome extends INBTTagable { +public interface IChromosome extends INbtWritable { IAllele getPrimaryAllele(); diff --git a/src/main/java/forestry/api/genetics/IEffectData.java b/src/main/java/forestry/api/genetics/IEffectData.java index a1fe33ba0..d8841dce1 100644 --- a/src/main/java/forestry/api/genetics/IEffectData.java +++ b/src/main/java/forestry/api/genetics/IEffectData.java @@ -5,14 +5,15 @@ ******************************************************************************/ package forestry.api.genetics; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; /** * Container to hold some temporary data for bee, tree and butterfly effects. * * @author SirSengir */ -public interface IEffectData extends INBTTagable { +public interface IEffectData extends INbtWritable, INbtReadable { void setInteger(int index, int val); void setFloat(int index, float val); diff --git a/src/main/java/forestry/api/genetics/IGenome.java b/src/main/java/forestry/api/genetics/IGenome.java index 12fcad835..3ac8bcefb 100644 --- a/src/main/java/forestry/api/genetics/IGenome.java +++ b/src/main/java/forestry/api/genetics/IGenome.java @@ -5,14 +5,14 @@ ******************************************************************************/ package forestry.api.genetics; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; /** * Holds the {@link IChromosome}s which comprise the traits of a given individual. * * Only the default implementation is supported. */ -public interface IGenome extends INBTTagable { +public interface IGenome extends INbtWritable { IAlleleSpecies getPrimary(); diff --git a/src/main/java/forestry/api/genetics/IIndividual.java b/src/main/java/forestry/api/genetics/IIndividual.java index d5a34de48..0e473f157 100644 --- a/src/main/java/forestry/api/genetics/IIndividual.java +++ b/src/main/java/forestry/api/genetics/IIndividual.java @@ -8,14 +8,14 @@ package forestry.api.genetics; import javax.annotation.Nonnull; import java.util.List; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; /** * An actual individual with genetic information. * * Only the default implementation is supported. */ -public interface IIndividual extends INBTTagable { +public interface IIndividual extends INbtWritable { String getIdent(); diff --git a/src/main/java/forestry/api/lepidopterology/EnumButterflyChromosome.java b/src/main/java/forestry/api/lepidopterology/EnumButterflyChromosome.java index 1c8906997..d829a6c36 100644 --- a/src/main/java/forestry/api/lepidopterology/EnumButterflyChromosome.java +++ b/src/main/java/forestry/api/lepidopterology/EnumButterflyChromosome.java @@ -8,7 +8,6 @@ package forestry.api.lepidopterology; import java.util.Locale; import forestry.api.genetics.IAllele; -import forestry.api.genetics.IAlleleArea; import forestry.api.genetics.IAlleleBoolean; import forestry.api.genetics.IAlleleFloat; import forestry.api.genetics.IAlleleFlowers; @@ -69,11 +68,7 @@ public enum EnumButterflyChromosome implements IChromosomeType { /** * Extra effect to surroundings. (?) */ - EFFECT(IAlleleButterflyEffect.class), - /** - * Not used yet - */ - TERRITORY(IAlleleArea.class),; + EFFECT(IAlleleButterflyEffect.class); Class clss; diff --git a/src/main/java/forestry/api/lepidopterology/IButterfly.java b/src/main/java/forestry/api/lepidopterology/IButterfly.java index c19c54f91..61fdbb93a 100644 --- a/src/main/java/forestry/api/lepidopterology/IButterfly.java +++ b/src/main/java/forestry/api/lepidopterology/IButterfly.java @@ -5,6 +5,8 @@ ******************************************************************************/ package forestry.api.lepidopterology; +import javax.annotation.Nonnull; + import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -12,6 +14,7 @@ import forestry.api.genetics.IIndividualLiving; public interface IButterfly extends IIndividualLiving { + @Nonnull @Override IButterflyGenome getGenome(); diff --git a/src/main/java/forestry/api/mail/ILetter.java b/src/main/java/forestry/api/mail/ILetter.java index 0bc4b4748..661ebb5ae 100644 --- a/src/main/java/forestry/api/mail/ILetter.java +++ b/src/main/java/forestry/api/mail/ILetter.java @@ -10,9 +10,9 @@ import java.util.List; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; -public interface ILetter extends IInventory, INBTTagable { +public interface ILetter extends IInventory, INbtWritable { ItemStack[] getPostage(); diff --git a/src/main/java/forestry/api/mail/IMailAddress.java b/src/main/java/forestry/api/mail/IMailAddress.java index d646cd2d5..5c601972f 100644 --- a/src/main/java/forestry/api/mail/IMailAddress.java +++ b/src/main/java/forestry/api/mail/IMailAddress.java @@ -7,9 +7,9 @@ package forestry.api.mail; import com.mojang.authlib.GameProfile; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; -public interface IMailAddress extends INBTTagable { +public interface IMailAddress extends INbtWritable { EnumAddressee getType(); diff --git a/src/main/java/forestry/api/multiblock/IMultiblockLogic.java b/src/main/java/forestry/api/multiblock/IMultiblockLogic.java index cd1f4c531..9e14c2c0b 100644 --- a/src/main/java/forestry/api/multiblock/IMultiblockLogic.java +++ b/src/main/java/forestry/api/multiblock/IMultiblockLogic.java @@ -8,7 +8,7 @@ package forestry.api.multiblock; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; /** * Multiblock Logic implements the basic logic for IMultiblockComponent tile entities. @@ -17,7 +17,7 @@ import forestry.api.core.INBTTagable; * IMultiblockComponent tile entities must wire up the methods in the "Updating and Synchronization" section. * As a starting point, you can use MultiblockTileEntityBase. */ -public interface IMultiblockLogic extends INBTTagable { +public interface IMultiblockLogic extends INbtWritable { /** * @return True if this block is connected to a multiblock controller. False otherwise. @@ -62,7 +62,6 @@ public interface IMultiblockLogic extends INBTTagable { * Read the logic's data from file. * Use this in Tile.readFromNBT() */ - @Override void readFromNBT(NBTTagCompound nbttagcompound); /** diff --git a/src/main/java/forestry/apiculture/HasFlowersCache.java b/src/main/java/forestry/apiculture/HasFlowersCache.java index 92fba244b..2e67b722a 100644 --- a/src/main/java/forestry/apiculture/HasFlowersCache.java +++ b/src/main/java/forestry/apiculture/HasFlowersCache.java @@ -21,12 +21,13 @@ import forestry.api.apiculture.FlowerManager; import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeeModifier; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.api.genetics.IFlowerProvider; import forestry.core.utils.vect.Vect; import forestry.plugins.PluginApiculture; -public class HasFlowersCache implements INBTTagable { +public class HasFlowersCache implements INbtWritable, INbtReadable { private static final String nbtKey = "hasFlowerCache"; private static final Random random = new Random(); private static final int flowerCheckInterval = 128; diff --git a/src/main/java/forestry/apiculture/blocks/BlockAlveary.java b/src/main/java/forestry/apiculture/blocks/BlockAlveary.java index d1f08717f..87abaf4a4 100644 --- a/src/main/java/forestry/apiculture/blocks/BlockAlveary.java +++ b/src/main/java/forestry/apiculture/blocks/BlockAlveary.java @@ -17,7 +17,6 @@ import java.util.LinkedHashMap; import java.util.List; import net.minecraft.block.Block; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; @@ -196,7 +195,7 @@ public class BlockAlveary extends BlockStructure implements IStateMapperRegister @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{TYPE, STATE, LEVEL}); + return new BlockState(this, TYPE, STATE, LEVEL); } @Override diff --git a/src/main/java/forestry/apiculture/blocks/BlockCandle.java b/src/main/java/forestry/apiculture/blocks/BlockCandle.java index 81f97c5db..66b6316a3 100644 --- a/src/main/java/forestry/apiculture/blocks/BlockCandle.java +++ b/src/main/java/forestry/apiculture/blocks/BlockCandle.java @@ -22,7 +22,6 @@ import java.util.Random; import java.util.Set; import net.minecraft.block.BlockTorch; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; @@ -106,7 +105,7 @@ public class BlockCandle extends BlockTorch implements IItemModelRegister { @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{FACING, STATE}); + return new BlockState(this, FACING, STATE); } @Override diff --git a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java index 2faf6431b..6751bd376 100644 --- a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java +++ b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java @@ -96,7 +96,7 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe public void registerAcceptableFlowerRule(IFlowerAcceptableRule acceptableFlower, String... flowerTypes) { for (String flowerType : flowerTypes) { if (defaultFlowerTypes.contains(flowerType)) { - Log.severe("IFlowerAcceptableRules are too slow to be applied to Forestry's built-in flower type: " + flowerType + "."); + Log.error("IFlowerAcceptableRules are too slow to be applied to Forestry's built-in flower type: " + flowerType + "."); } else { registeredRules.put(flowerType, acceptableFlower); } diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index bb2663d27..d38cf8714 100644 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -75,30 +75,30 @@ public class Bee extends IndividualLiving implements IBee { private boolean isNatural = true; @Nonnull - private IBeeGenome genome; + private final IBeeGenome genome; @Nullable private IBeeGenome mate; /* CONSTRUCTOR */ - public Bee(@Nonnull NBTTagCompound nbttagcompound) { - super(nbttagcompound); + public Bee(@Nonnull NBTTagCompound nbt) { + super(nbt); - if (nbttagcompound.hasKey("NA")) { - isNatural = nbttagcompound.getBoolean("NA"); + if (nbt.hasKey("NA")) { + isNatural = nbt.getBoolean("NA"); } - if (nbttagcompound.hasKey("GEN")) { - generation = nbttagcompound.getInteger("GEN"); + if (nbt.hasKey("GEN")) { + generation = nbt.getInteger("GEN"); } - if (nbttagcompound.hasKey("Genome")) { - genome = BeeGenome.fromNBT(nbttagcompound.getCompoundTag("Genome")); + if (nbt.hasKey("Genome")) { + genome = BeeGenome.fromNBT(nbt.getCompoundTag("Genome")); } else { genome = BeeDefinition.FOREST.getGenome(); } - if (nbttagcompound.hasKey("Mate")) { - mate = BeeGenome.fromNBT(nbttagcompound.getCompoundTag("Mate")); + if (nbt.hasKey("Mate")) { + mate = BeeGenome.fromNBT(nbt.getCompoundTag("Mate")); } } @@ -118,37 +118,6 @@ public class Bee extends IndividualLiving implements IBee { this.generation = generation; } - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - - if (nbttagcompound == null) { - genome = BeeDefinition.FOREST.getGenome(); - return; - } - - super.readFromNBT(nbttagcompound); - - if (nbttagcompound.hasKey("NA")) { - isNatural = nbttagcompound.getBoolean("NA"); - } - - if (nbttagcompound.hasKey("GEN")) { - generation = nbttagcompound.getInteger("GEN"); - } - - if (nbttagcompound.hasKey("Genome")) { - genome = BeeGenome.fromNBT(nbttagcompound.getCompoundTag("Genome")); - } else { - genome = BeeDefinition.FOREST.getGenome(); - } - - if (nbttagcompound.hasKey("Mate")) { - mate = BeeGenome.fromNBT(nbttagcompound.getCompoundTag("Mate")); - } - - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { diff --git a/src/main/java/forestry/apiculture/genetics/BeeBranchDefinition.java b/src/main/java/forestry/apiculture/genetics/BeeBranchDefinition.java index d5bda0eb7..0735eb173 100644 --- a/src/main/java/forestry/apiculture/genetics/BeeBranchDefinition.java +++ b/src/main/java/forestry/apiculture/genetics/BeeBranchDefinition.java @@ -21,7 +21,7 @@ public enum BeeBranchDefinition implements IBranchDefinition { @Override protected void setBranchProperties(IAllele[] alleles) { AlleleHelper.instance.set(alleles, EnumBeeChromosome.TEMPERATURE_TOLERANCE, EnumAllele.Tolerance.DOWN_2); - AlleleHelper.instance.set(alleles, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(alleles, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(alleles, EnumBeeChromosome.FLOWER_PROVIDER, EnumAllele.Flowers.NETHER); AlleleHelper.instance.set(alleles, EnumBeeChromosome.FLOWERING, EnumAllele.Flowering.AVERAGE); } @@ -31,7 +31,7 @@ public enum BeeBranchDefinition implements IBranchDefinition { protected void setBranchProperties(IAllele[] alleles) { AlleleHelper.instance.set(alleles, EnumBeeChromosome.TEMPERATURE_TOLERANCE, EnumAllele.Tolerance.BOTH_1); AlleleHelper.instance.set(alleles, EnumBeeChromosome.HUMIDITY_TOLERANCE, EnumAllele.Tolerance.DOWN_1); - AlleleHelper.instance.set(alleles, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(alleles, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(alleles, EnumBeeChromosome.FLOWER_PROVIDER, EnumAllele.Flowers.CACTI); } }, @@ -53,7 +53,7 @@ public enum BeeBranchDefinition implements IBranchDefinition { AlleleHelper.instance.set(alleles, EnumBeeChromosome.TEMPERATURE_TOLERANCE, EnumAllele.Tolerance.UP_1); AlleleHelper.instance.set(alleles, EnumBeeChromosome.TERRITORY, EnumAllele.Territory.LARGE); AlleleHelper.instance.set(alleles, EnumBeeChromosome.FLOWER_PROVIDER, EnumAllele.Flowers.END); - AlleleHelper.instance.set(alleles, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(alleles, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(alleles, EnumBeeChromosome.EFFECT, AlleleEffect.effectMisanthrope); } }, @@ -145,7 +145,7 @@ public enum BeeBranchDefinition implements IBranchDefinition { AlleleHelper.instance.set(defaultTemplate, EnumBeeChromosome.LIFESPAN, EnumAllele.Lifespan.SHORTER); AlleleHelper.instance.set(defaultTemplate, EnumBeeChromosome.FERTILITY, EnumAllele.Fertility.NORMAL); AlleleHelper.instance.set(defaultTemplate, EnumBeeChromosome.TEMPERATURE_TOLERANCE, EnumAllele.Tolerance.NONE); - AlleleHelper.instance.set(defaultTemplate, EnumBeeChromosome.NOCTURNAL, false); + AlleleHelper.instance.set(defaultTemplate, EnumBeeChromosome.NEVER_SLEEPS, false); AlleleHelper.instance.set(defaultTemplate, EnumBeeChromosome.HUMIDITY_TOLERANCE, EnumAllele.Tolerance.NONE); AlleleHelper.instance.set(defaultTemplate, EnumBeeChromosome.TOLERANT_FLYER, false); AlleleHelper.instance.set(defaultTemplate, EnumBeeChromosome.CAVE_DWELLING, false); diff --git a/src/main/java/forestry/apiculture/genetics/BeeDefinition.java b/src/main/java/forestry/apiculture/genetics/BeeDefinition.java index abdd51689..10d9ed884 100644 --- a/src/main/java/forestry/apiculture/genetics/BeeDefinition.java +++ b/src/main/java/forestry/apiculture/genetics/BeeDefinition.java @@ -244,7 +244,7 @@ public enum BeeDefinition implements IBeeDefinition { protected void setAlleles(IAllele[] template) { AlleleHelper.instance.set(template, EnumBeeChromosome.SPEED, EnumAllele.Speed.SLOWER); AlleleHelper.instance.set(template, EnumBeeChromosome.LIFESPAN, EnumAllele.Lifespan.NORMAL); - AlleleHelper.instance.set(template, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(template, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(template, EnumBeeChromosome.CAVE_DWELLING, true); } @@ -264,7 +264,7 @@ public enum BeeDefinition implements IBeeDefinition { protected void setAlleles(IAllele[] template) { AlleleHelper.instance.set(template, EnumBeeChromosome.SPEED, EnumAllele.Speed.SLOW); AlleleHelper.instance.set(template, EnumBeeChromosome.LIFESPAN, EnumAllele.Lifespan.LONG); - AlleleHelper.instance.set(template, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(template, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(template, EnumBeeChromosome.CAVE_DWELLING, true); } @@ -284,7 +284,7 @@ public enum BeeDefinition implements IBeeDefinition { protected void setAlleles(IAllele[] template) { AlleleHelper.instance.set(template, EnumBeeChromosome.SPEED, EnumAllele.Speed.SLOW); AlleleHelper.instance.set(template, EnumBeeChromosome.LIFESPAN, EnumAllele.Lifespan.LONG); - AlleleHelper.instance.set(template, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(template, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(template, EnumBeeChromosome.CAVE_DWELLING, true); AlleleHelper.instance.set(template, EnumBeeChromosome.EFFECT, AlleleEffect.effectHeroic); } @@ -712,7 +712,7 @@ public enum BeeDefinition implements IBeeDefinition { @Override protected void setAlleles(IAllele[] template) { - AlleleHelper.instance.set(template, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(template, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(template, EnumBeeChromosome.EFFECT, AlleleEffect.effectSnowing); } @@ -736,7 +736,7 @@ public enum BeeDefinition implements IBeeDefinition { @Override protected void setAlleles(IAllele[] template) { - AlleleHelper.instance.set(template, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(template, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(template, EnumBeeChromosome.EFFECT, AlleleEffect.effectDrunkard); } @@ -764,7 +764,7 @@ public enum BeeDefinition implements IBeeDefinition { @Override protected void setAlleles(IAllele[] template) { - AlleleHelper.instance.set(template, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(template, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(template, EnumBeeChromosome.TOLERANT_FLYER, true); AlleleHelper.instance.set(template, EnumBeeChromosome.FLOWER_PROVIDER, EnumAllele.Flowers.GOURD); } @@ -865,7 +865,7 @@ public enum BeeDefinition implements IBeeDefinition { protected void setAlleles(IAllele[] template) { AlleleHelper.instance.set(template, EnumBeeChromosome.FERTILITY, EnumAllele.Fertility.MAXIMUM); AlleleHelper.instance.set(template, EnumBeeChromosome.TOLERANT_FLYER, true); - AlleleHelper.instance.set(template, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(template, EnumBeeChromosome.NEVER_SLEEPS, true); } @Override @@ -886,7 +886,7 @@ public enum BeeDefinition implements IBeeDefinition { @Override protected void setAlleles(IAllele[] template) { AlleleHelper.instance.set(template, EnumBeeChromosome.TOLERANT_FLYER, true); - AlleleHelper.instance.set(template, EnumBeeChromosome.NOCTURNAL, true); + AlleleHelper.instance.set(template, EnumBeeChromosome.NEVER_SLEEPS, true); AlleleHelper.instance.set(template, EnumBeeChromosome.EFFECT, AlleleEffect.effectMycophilic); AlleleHelper.instance.set(template, EnumBeeChromosome.TERRITORY, EnumAllele.Territory.LARGER); } diff --git a/src/main/java/forestry/apiculture/genetics/BeeGenome.java b/src/main/java/forestry/apiculture/genetics/BeeGenome.java index 1b9d81750..fe79176db 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeGenome.java +++ b/src/main/java/forestry/apiculture/genetics/BeeGenome.java @@ -131,7 +131,7 @@ public class BeeGenome extends Genome implements IBeeGenome { @Override public boolean getNocturnal() { - return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.NOCTURNAL)).getValue(); + return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.NEVER_SLEEPS)).getValue(); } @Override diff --git a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectPotion.java b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectPotion.java index 1c686f86e..6a9b66089 100644 --- a/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectPotion.java +++ b/src/main/java/forestry/apiculture/genetics/alleles/AlleleEffectPotion.java @@ -22,27 +22,22 @@ import net.minecraft.potion.PotionHelper; import net.minecraft.util.Vec3; import net.minecraft.world.World; -import net.minecraftforge.fml.relauncher.ReflectionHelper; - import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; import forestry.core.proxy.Proxies; -import forestry.core.utils.Log; public class AlleleEffectPotion extends AlleleEffectThrottled { private final Potion potion; private final int potionFXColor; - private final boolean isBadEffect; private final int duration; private final float chance; public AlleleEffectPotion(String name, boolean isDominant, Potion potion, int duration, int throttle, float chance) { super(name, isDominant, throttle, true, false); this.potion = potion; - this.isBadEffect = isBadEffect(potion); this.duration = duration; this.chance = chance; @@ -64,7 +59,7 @@ public class AlleleEffectPotion extends AlleleEffectThrottled { } int dur = this.duration; - if (isBadEffect) { + if (potion.isBadEffect()) { // Entities are not attacked if they wear a full set of apiarist's armor. int count = BeeManager.armorApiaristHelper.wearsItems(entity, getUID(), true); if (count >= 4) { @@ -89,16 +84,6 @@ public class AlleleEffectPotion extends AlleleEffectThrottled { return storedData; } - //FIXME: remove when Potion.isBadEffect() is available server-side - private static boolean isBadEffect(Potion potion) { - try { - return (Boolean) ReflectionHelper.getPrivateValue(Potion.class, potion, "field_76418_K", "isBadEffect"); - } catch (ReflectionHelper.UnableToFindFieldException e) { - Log.severe("Could not access potion field isBadEffect."); - return false; - } - } - @Override public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) { if (housing.getWorld().rand.nextBoolean()) { diff --git a/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java b/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java index c35de22d1..51c495d74 100755 --- a/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java +++ b/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java @@ -184,7 +184,7 @@ public class GuiBeealyzer extends GuiAlyzer { nocturnal0 = bee.getGenome().getPrimary().isNocturnal() ? yes : no; diurnal0 = !bee.getGenome().getPrimary().isNocturnal() ? yes : no; } - if (((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.NOCTURNAL)).getValue()) { + if (((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.NEVER_SLEEPS)).getValue()) { nocturnal1 = diurnal1 = yes; } else { nocturnal1 = bee.getGenome().getSecondary().isNocturnal() ? yes : no; diff --git a/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java b/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java index 7d7261c6a..32320d870 100755 --- a/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java +++ b/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java @@ -105,8 +105,7 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { } } - @SuppressWarnings("rawtypes") - public static ComponentVillageBeeHouse buildComponent(StructureVillagePieces.Start startPiece, List par1List, Random random, int par3, int par4, int par5, EnumFacing par6, int par7) { + public static ComponentVillageBeeHouse buildComponent(StructureVillagePieces.Start startPiece, List par1List, Random random, int par3, int par4, int par5, EnumFacing par6, int par7) { StructureBoundingBox bbox = StructureBoundingBox.getComponentToAddBoundingBox(par3, par4, par5, 0, 0, 0, 10, 9, 11, par6); if (!canVillageGoDeeper(bbox) || StructureComponent.findIntersecting(par1List, bbox) != null) { return null; diff --git a/src/main/java/forestry/arboriculture/blocks/BlockArbStairs.java b/src/main/java/forestry/arboriculture/blocks/BlockArbStairs.java index 6f1355d21..bfb980703 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockArbStairs.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockArbStairs.java @@ -16,7 +16,6 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockStairs; import net.minecraft.block.ITileEntityProvider; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.client.particle.EffectRenderer; @@ -77,7 +76,7 @@ public class BlockArbStairs extends BlockStairs implements IWoodTyped, IItemMode @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{EnumWoodType.WOODTYPE, FACING, HALF, SHAPE}); + return new BlockState(this, EnumWoodType.WOODTYPE, FACING, HALF, SHAPE); } @Override diff --git a/src/main/java/forestry/arboriculture/blocks/BlockSapling.java b/src/main/java/forestry/arboriculture/blocks/BlockSapling.java index 942f50d4a..e2dc073dc 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockSapling.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockSapling.java @@ -17,7 +17,6 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.IGrowable; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -110,7 +109,7 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{TREE}); + return new BlockState(this, TREE); } @Override diff --git a/src/main/java/forestry/arboriculture/blocks/BlockSlab.java b/src/main/java/forestry/arboriculture/blocks/BlockSlab.java index e58c40218..6fad7a8b0 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockSlab.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockSlab.java @@ -85,7 +85,7 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp @Override protected BlockState createBlockState() { - return this.isDouble() ? new BlockState(this, new IProperty[]{EnumWoodType.WOODTYPE}) : new BlockState(this, new IProperty[]{HALF, EnumWoodType.WOODTYPE}); + return this.isDouble() ? new BlockState(this, EnumWoodType.WOODTYPE) : new BlockState(this, HALF, EnumWoodType.WOODTYPE); } @Override diff --git a/src/main/java/forestry/arboriculture/blocks/BlockWood.java b/src/main/java/forestry/arboriculture/blocks/BlockWood.java index 2372d4b7b..257bccdcc 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockWood.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockWood.java @@ -16,7 +16,6 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.client.particle.EffectRenderer; @@ -72,7 +71,7 @@ public abstract class BlockWood extends Block implements ITileEntityProvider, II @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{EnumWoodType.WOODTYPE}); + return new BlockState(this, EnumWoodType.WOODTYPE); } @Override diff --git a/src/main/java/forestry/arboriculture/genetics/Tree.java b/src/main/java/forestry/arboriculture/genetics/Tree.java index d9177a2c1..1ce11b406 100755 --- a/src/main/java/forestry/arboriculture/genetics/Tree.java +++ b/src/main/java/forestry/arboriculture/genetics/Tree.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.arboriculture.genetics; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -59,55 +60,50 @@ import forestry.core.utils.StringUtil; public class Tree extends Individual implements ITree, IPlantable { - private ITreeGenome genome; + @Nonnull + private final ITreeGenome genome; + @Nullable private ITreeGenome mate; - private EnumSet plantTypes; + private final EnumSet plantTypes; private EnumPlantType plantType; - /* CONSTRUCTOR */ - public Tree(NBTTagCompound nbttagcompound) { - readFromNBT(nbttagcompound); + public Tree(@Nonnull ITreeGenome genome) { + this.genome = genome; + plantTypes = genome.getPlantTypes(); + plantTypes.add(genome.getPrimary().getPlantType()); } - public Tree(ITreeGenome genome) { - setGenome(genome); - } - - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - - super.readFromNBT(nbttagcompound); + public Tree(@Nonnull NBTTagCompound nbttagcompound) { + super(nbttagcompound); if (nbttagcompound.hasKey("Genome")) { - setGenome(new TreeGenome(nbttagcompound.getCompoundTag("Genome"))); + this.genome = new TreeGenome(nbttagcompound.getCompoundTag("Genome")); } else { - setGenome(TreeDefinition.Oak.getGenome()); + this.genome = TreeDefinition.Oak.getGenome(); } + this.plantTypes = genome.getPlantTypes(); + this.plantTypes.add(genome.getPrimary().getPlantType()); + if (nbttagcompound.hasKey("Mate")) { mate = new TreeGenome(nbttagcompound.getCompoundTag("Mate")); } - } @Override public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - if (genome != null) { - NBTTagCompound nbtGenome = new NBTTagCompound(); - genome.writeToNBT(nbtGenome); - nbttagcompound.setTag("Genome", nbtGenome); - } + NBTTagCompound nbtGenome = new NBTTagCompound(); + genome.writeToNBT(nbtGenome); + nbttagcompound.setTag("Genome", nbtGenome); + if (mate != null) { NBTTagCompound nbtMate = new NBTTagCompound(); mate.writeToNBT(nbtMate); nbttagcompound.setTag("Mate", nbtMate); } - } /* INTERACTION */ @@ -255,17 +251,12 @@ public class Tree extends Individual implements ITree, IPlantable { } /* INFORMATION */ + @Nonnull @Override public ITreeGenome getGenome() { return genome; } - private void setGenome(ITreeGenome genome) { - this.genome = genome; - plantTypes = genome.getPlantTypes(); - plantTypes.add(genome.getPrimary().getPlantType()); - } - @Override public ITree copy() { NBTTagCompound nbttagcompound = new NBTTagCompound(); @@ -273,6 +264,7 @@ public class Tree extends Individual implements ITree, IPlantable { return new Tree(nbttagcompound); } + @Nullable @Override public ITreeGenome getMate() { return this.mate; diff --git a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java index b46de9356..fd58df1aa 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java @@ -542,7 +542,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru private static void attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) { if (ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), pos.getX(), pos.getY() + 0.1f, pos.getZ()) != null) { - Log.finest("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ()); + Log.trace("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ()); } } diff --git a/src/main/java/forestry/core/access/IAccessHandler.java b/src/main/java/forestry/core/access/IAccessHandler.java index 4b0195f0d..83ff223a2 100644 --- a/src/main/java/forestry/core/access/IAccessHandler.java +++ b/src/main/java/forestry/core/access/IAccessHandler.java @@ -12,10 +12,11 @@ package forestry.core.access; import net.minecraft.entity.player.EntityPlayer; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.core.network.IStreamable; -public interface IAccessHandler extends IOwnable, IStreamable, INBTTagable { +public interface IAccessHandler extends IOwnable, IStreamable, INbtWritable, INbtReadable { boolean switchAccess(EntityPlayer player); diff --git a/src/main/java/forestry/core/blocks/BlockForestry.java b/src/main/java/forestry/core/blocks/BlockForestry.java index e8af10291..7dbcfc89a 100644 --- a/src/main/java/forestry/core/blocks/BlockForestry.java +++ b/src/main/java/forestry/core/blocks/BlockForestry.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.core.blocks; -import org.apache.logging.log4j.Level; - import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; @@ -87,7 +85,7 @@ public abstract class BlockForestry extends BlockContainer implements IItemModel ((TileForestry) tile).onNeighborBlockChange(state.getBlock()); } } catch (StackOverflowError error) { - Log.logThrowable(Level.ERROR, "Stack Overflow Error in BlockMachine.onNeighborBlockChange()", 10, error); + Log.error("Stack Overflow Error in BlockMachine.onNeighborBlockChange()", error); throw error; } } diff --git a/src/main/java/forestry/core/blocks/BlockResourceOre.java b/src/main/java/forestry/core/blocks/BlockResourceOre.java index 2f7b2079c..21fd7ffc7 100644 --- a/src/main/java/forestry/core/blocks/BlockResourceOre.java +++ b/src/main/java/forestry/core/blocks/BlockResourceOre.java @@ -16,7 +16,6 @@ import java.util.Locale; import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; @@ -73,7 +72,7 @@ public class BlockResourceOre extends Block implements IItemModelRegister { @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{RESOURCE}); + return new BlockState(this, RESOURCE); } @Override diff --git a/src/main/java/forestry/core/blocks/BlockResourceStorage.java b/src/main/java/forestry/core/blocks/BlockResourceStorage.java index 6a088c47c..57151599d 100644 --- a/src/main/java/forestry/core/blocks/BlockResourceStorage.java +++ b/src/main/java/forestry/core/blocks/BlockResourceStorage.java @@ -5,7 +5,6 @@ import java.util.Locale; import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; @@ -48,7 +47,7 @@ public class BlockResourceStorage extends Block implements IItemModelRegister { @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{RESOURCE}); + return new BlockState(this, RESOURCE); } @Override diff --git a/src/main/java/forestry/core/blocks/BlockSoil.java b/src/main/java/forestry/core/blocks/BlockSoil.java index 932ae49a5..cab8063b4 100644 --- a/src/main/java/forestry/core/blocks/BlockSoil.java +++ b/src/main/java/forestry/core/blocks/BlockSoil.java @@ -18,7 +18,6 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.IGrowable; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; @@ -82,7 +81,7 @@ public class BlockSoil extends Block implements IItemTyped, IItemModelRegister { @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{SOIL}); + return new BlockState(this, SOIL); } @Override diff --git a/src/main/java/forestry/core/circuits/CircuitBoard.java b/src/main/java/forestry/core/circuits/CircuitBoard.java index 2119ef0d1..229e945ae 100755 --- a/src/main/java/forestry/core/circuits/CircuitBoard.java +++ b/src/main/java/forestry/core/circuits/CircuitBoard.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.circuits; +import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; @@ -26,18 +27,43 @@ import forestry.core.utils.StringUtil; public class CircuitBoard implements ICircuitBoard { - private EnumCircuitBoardType type; - private ICircuitLayout layout; - private ICircuit[] circuits; + @Nonnull + private final EnumCircuitBoardType type; + @Nonnull + private final ICircuitLayout layout; + @Nonnull + private final ICircuit[] circuits; - public CircuitBoard(EnumCircuitBoardType type, ICircuitLayout layout, ICircuit[] circuits) { + public CircuitBoard(@Nonnull EnumCircuitBoardType type, @Nonnull ICircuitLayout layout, @Nonnull ICircuit[] circuits) { this.type = type; this.layout = layout; this.circuits = circuits; } public CircuitBoard(NBTTagCompound nbttagcompound) { - readFromNBT(nbttagcompound); + type = EnumCircuitBoardType.values()[nbttagcompound.getShort("T")]; + + // Layout + ICircuitLayout layout = null; + if (nbttagcompound.hasKey("LY")) { + layout = ChipsetManager.circuitRegistry.getLayout(nbttagcompound.getString("LY")); + } + if (layout == null) { + ChipsetManager.circuitRegistry.getDefaultLayout(); + } + this.layout = layout; + + circuits = new ICircuit[4]; + + for (int i = 0; i < 4; i++) { + if (!nbttagcompound.hasKey("CA.I" + i)) { + continue; + } + ICircuit circuit = ChipsetManager.circuitRegistry.getCircuit(nbttagcompound.getString("CA.I" + i)); + if (circuit != null) { + circuits[i] = circuit; + } + } } @Override @@ -70,32 +96,6 @@ public class CircuitBoard implements ICircuitBoard { } } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - - type = EnumCircuitBoardType.values()[nbttagcompound.getShort("T")]; - - // Layout - if (nbttagcompound.hasKey("LY")) { - layout = ChipsetManager.circuitRegistry.getLayout(nbttagcompound.getString("LY")); - } - if (layout == null) { - ChipsetManager.circuitRegistry.getDefaultLayout(); - } - - circuits = new ICircuit[4]; - - for (int i = 0; i < 4; i++) { - if (!nbttagcompound.hasKey("CA.I" + i)) { - continue; - } - ICircuit circuit = ChipsetManager.circuitRegistry.getCircuit(nbttagcompound.getString("CA.I" + i)); - if (circuit != null) { - circuits[i] = circuit; - } - } - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { @@ -162,11 +162,13 @@ public class CircuitBoard implements ICircuitBoard { } } + @Nonnull @Override public ICircuit[] getCircuits() { return circuits; } + @Nonnull @Override public ICircuitSocketType getSocketType() { return layout.getSocketType(); diff --git a/src/main/java/forestry/core/circuits/CircuitLayout.java b/src/main/java/forestry/core/circuits/CircuitLayout.java index f15cbb7e4..c41a6c94a 100755 --- a/src/main/java/forestry/core/circuits/CircuitLayout.java +++ b/src/main/java/forestry/core/circuits/CircuitLayout.java @@ -10,35 +10,43 @@ ******************************************************************************/ package forestry.core.circuits; +import javax.annotation.Nonnull; + import forestry.api.circuits.ICircuitLayout; import forestry.api.circuits.ICircuitSocketType; import forestry.core.utils.StringUtil; public class CircuitLayout implements ICircuitLayout { + @Nonnull private final String uid; + @Nonnull private final ICircuitSocketType socketType; - public CircuitLayout(String uid, ICircuitSocketType socketType) { + public CircuitLayout(@Nonnull String uid, @Nonnull ICircuitSocketType socketType) { this.uid = uid; this.socketType = socketType; } + @Nonnull @Override public String getUID() { return "forestry." + this.uid; } + @Nonnull @Override public String getName() { return StringUtil.localize("circuit.layout." + this.uid + ".name"); } + @Nonnull @Override public String getUsage() { return StringUtil.localize("circuit.layout." + this.uid + ".usage"); } + @Nonnull @Override public ICircuitSocketType getSocketType() { return socketType; diff --git a/src/main/java/forestry/core/commands/CommandSaveStats.java b/src/main/java/forestry/core/commands/CommandSaveStats.java index ab8c32ee4..1e422bd99 100644 --- a/src/main/java/forestry/core/commands/CommandSaveStats.java +++ b/src/main/java/forestry/core/commands/CommandSaveStats.java @@ -33,7 +33,6 @@ import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IBreedingTracker; import forestry.core.config.Constants; -import forestry.core.config.Version; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; @@ -141,7 +140,7 @@ public final class CommandSaveStats extends SubCommand { FileOutputStream fileout = new FileOutputStream(file); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fileout, "UTF-8")); - writer.write("# " + Constants.MOD + newLine + "# " + Version.getVersion() + newLine); + writer.write("# " + Constants.MOD + newLine + "# " + Constants.VERSION + newLine); for (String line : statistics) { writer.write(line + newLine); diff --git a/src/main/java/forestry/core/commands/CommandVersion.java b/src/main/java/forestry/core/commands/CommandVersion.java deleted file mode 100644 index bbe6362e6..000000000 --- a/src/main/java/forestry/core/commands/CommandVersion.java +++ /dev/null @@ -1,46 +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.commands; - -import net.minecraft.command.ICommandSender; -import net.minecraft.util.ChatStyle; -import net.minecraft.util.EnumChatFormatting; - -import forestry.core.config.Version; -import forestry.core.proxy.Proxies; - -/** - * @author CovertJaguar - */ -public class CommandVersion extends SubCommand { - - public CommandVersion() { - super("version"); - } - - @Override - public void processSubCommand(ICommandSender sender, String[] args) { - ChatStyle style = new ChatStyle(); - if (Version.isOutdated()) { - style.setColor(EnumChatFormatting.RED); - } else { - style.setColor(EnumChatFormatting.GREEN); - } - - CommandHelpers.sendLocalizedChatMessage(sender, style, "for.chat.version", Version.getVersion(), Proxies.common.getMinecraftVersion(), Version.getRecommendedVersion()); - if (Version.isOutdated()) { - for (String updateLine : Version.getChangelog()) { - CommandHelpers.sendChatMessage(sender, EnumChatFormatting.BLUE + updateLine); - } - } - } - -} diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index ee1b292fa..4ae5fb05e 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -240,7 +240,7 @@ public class Config { disabledStructures.addAll(Arrays.asList(disabledStructureArray)); for (String str : disabledStructures) { - Log.finer("Disabled structure '%s'.", str); + Log.debug("Disabled structure '%s'.", str); } isDebug = configCommon.getBooleanLocalized("debug", "enabled", isDebug); diff --git a/src/main/java/forestry/core/config/Constants.java b/src/main/java/forestry/core/config/Constants.java index e5f424f92..e528ddf14 100644 --- a/src/main/java/forestry/core/config/Constants.java +++ b/src/main/java/forestry/core/config/Constants.java @@ -18,6 +18,9 @@ public class Constants implements IForestryConstants { public static final String ID = "forestry"; public static final String URL = "http://forestry.sengir.net/"; + public static final String VERSION = "@VERSION@"; + public static final String BUILD_NUMBER = "@BUILD_NUMBER@"; + public static final int FLAG_BLOCK_UPDATE = 1; public static final int FLAG_BLOCK_SYNCH = 2; public static final int FLAG_BLOCK_SYNCH_AND_UPDATE = FLAG_BLOCK_UPDATE + FLAG_BLOCK_SYNCH; diff --git a/src/main/java/forestry/core/config/Version.java b/src/main/java/forestry/core/config/Version.java deleted file mode 100755 index b7d6437b6..000000000 --- a/src/main/java/forestry/core/config/Version.java +++ /dev/null @@ -1,179 +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.config; - -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.ArrayList; - -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion; - -import forestry.Forestry; -import forestry.core.proxy.Proxies; -import forestry.core.utils.Log; - -/** - * With permission from pahimar. - * - * @author Pahimar - */ -public class Version { - - public enum EnumUpdateState { - - CURRENT, OUTDATED, CONNECTION_ERROR - } - - public static final String VERSION = "@VERSION@"; - public static final String BUILD_NUMBER = "@BUILD_NUMBER@"; - public static final String[] FAILED_CHANGELOG = new String[]{String.format("Unable to retrieve changelog for %s", Constants.MOD)}; - private static final String REMOTE_VERSION_FILE = "http://bit.ly/forestryver"; - private static final String REMOTE_CHANGELOG_ROOT = "https://dl.dropbox.com/u/44760587/forestry/changelog/"; - public static EnumUpdateState currentVersion = EnumUpdateState.CURRENT; - private static String recommendedVersion; - private static String[] cachedChangelog = FAILED_CHANGELOG; - - public static String getVersion() { - return VERSION + " (" + BUILD_NUMBER + ")"; - } - - public static boolean isOutdated() { - return currentVersion == EnumUpdateState.OUTDATED; - } - - public static boolean needsUpdateNoticeAndMarkAsSeen() { - if (!isOutdated()) { - return false; - } - - File versionFile = new File(Forestry.instance.getConfigFolder(), Config.CATEGORY_COMMON + ".cfg"); - Configuration config = new Configuration(versionFile); - Property property = config.get("version", "seen", VERSION); - property.comment = "indicates the last version the user has been informed about and will suppress further notices on it."; - String seenVersion = property.getString(); - - if (recommendedVersion == null || recommendedVersion.equals(seenVersion)) { - return false; - } - - property.set(recommendedVersion); - config.save(); - return true; - } - - public static String getRecommendedVersion() { - return recommendedVersion; - } - - private static class VersionChecker extends Thread { - - @Override - public void run() { - try { - String location = REMOTE_VERSION_FILE; - HttpURLConnection conn = null; - while (location != null && !location.isEmpty()) { - URL url = new URL(location); - conn = (HttpURLConnection) url.openConnection(); - conn.setRequestProperty("User-Agent", - "Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)"); - conn.connect(); - location = conn.getHeaderField("Location"); - } - - BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - - String line; - String mcVersion = Proxies.common.getMinecraftVersion(); - while ((line = reader.readLine()) != null) { - if (line.startsWith(mcVersion) && line.contains(Constants.MOD)) { - String[] tokens = line.split(":"); - recommendedVersion = tokens[2]; - } - } - - if (recommendedVersion == null) { - return; - } - - int result = FMLCommonHandler.instance().findContainerFor(Forestry.instance).getProcessedVersion().compareTo(new DefaultArtifactVersion(recommendedVersion)); - if (result >= 0) { - Log.finer("Using the latest version [" + VERSION + " (build:" + BUILD_NUMBER + ")] for Minecraft " + mcVersion); - currentVersion = EnumUpdateState.CURRENT; - return; - } - - cachedChangelog = grabChangelog(recommendedVersion); - - Log.warning("Using outdated version [" + VERSION + " (build:" + BUILD_NUMBER + ")] for Minecraft " + mcVersion + ". Consider updating."); - currentVersion = EnumUpdateState.OUTDATED; - - } catch (Exception e) { - // e.printStackTrace(); - Log.warning("Unable to read from remote version authority."); - currentVersion = EnumUpdateState.CONNECTION_ERROR; - } - } - } - - public static void versionCheck() { - new VersionChecker().start(); - } - - public static String[] getChangelog() { - return cachedChangelog; - } - - public static String[] grabChangelog(String version) { - - try { - String location = REMOTE_CHANGELOG_ROOT + version; - HttpURLConnection conn; - do { - URL url = new URL(location); - conn = (HttpURLConnection) url.openConnection(); - conn.setRequestProperty("User-Agent", - "Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)"); - conn.connect(); - location = conn.getHeaderField("Location"); - } while (location != null && !location.isEmpty()); - - BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - - String line; - ArrayList changelog = new ArrayList<>(); - while ((line = reader.readLine()) != null) { - if (line.startsWith("#")) { - continue; - } - if (line.isEmpty()) { - continue; - } - - changelog.add(line); - } - - return changelog.toArray(new String[changelog.size()]); - - } catch (Exception ex) { - // ex.printStackTrace(); - Log.warning("Unable to read changelog from remote site."); - } - - return new String[]{String.format("Unable to retrieve changelog for %s %s", Constants.MOD, version)}; - } -} diff --git a/src/main/java/forestry/core/fluids/PipetteContents.java b/src/main/java/forestry/core/fluids/PipetteContents.java index dec494296..147239abd 100644 --- a/src/main/java/forestry/core/fluids/PipetteContents.java +++ b/src/main/java/forestry/core/fluids/PipetteContents.java @@ -14,60 +14,52 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; + +public class PipetteContents implements INbtWritable { + @Nonnull + private final FluidStack contents; -public class PipetteContents implements INBTTagable { @Nullable - private FluidStack contents; - - public PipetteContents(NBTTagCompound nbttagcompound) { - if (nbttagcompound != null) { - readFromNBT(nbttagcompound); + public static PipetteContents create(@Nullable ItemStack itemStack) { + if (itemStack == null) { + return null; } + NBTTagCompound nbt = itemStack.getTagCompound(); + FluidStack contents = FluidStack.loadFluidStackFromNBT(nbt); + if (contents == null) { + return null; + } + return new PipetteContents(contents); } - @Nullable + public PipetteContents(@Nonnull FluidStack contents) { + this.contents = contents; + } + + @Nonnull public FluidStack getContents() { return contents; } - public void setContents(@Nonnull FluidStack contents) { - this.contents = contents; - } - public boolean isFull() { - if (contents == null) { - return false; - } - return contents.amount >= 1000; } public void addTooltip(List list) { - if (contents == null) { - return; - } - String descr = contents.getFluid().getLocalizedName(contents); descr += " (" + contents.amount + " mb)"; list.add(descr); } - /* INBTTagable */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - contents = FluidStack.loadFluidStackFromNBT(nbttagcompound); - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { - if (contents != null) { - contents.writeToNBT(nbttagcompound); - } + contents.writeToNBT(nbttagcompound); } } diff --git a/src/main/java/forestry/core/fluids/TankManager.java b/src/main/java/forestry/core/fluids/TankManager.java index df2edfa68..c067b978d 100644 --- a/src/main/java/forestry/core/fluids/TankManager.java +++ b/src/main/java/forestry/core/fluids/TankManager.java @@ -33,7 +33,8 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidTank; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.core.fluids.tanks.FakeTank; import forestry.core.fluids.tanks.StandardTank; import forestry.core.network.DataInputStreamForestry; @@ -51,7 +52,7 @@ import forestry.core.utils.NBTUtil.NBTList; /** * @author CovertJaguar */ -public class TankManager implements ITankManager, ITankUpdateHandler, IStreamable, INBTTagable { +public class TankManager implements ITankManager, ITankUpdateHandler, IStreamable, INbtWritable, INbtReadable { private final List tanks = new ArrayList<>(); diff --git a/src/main/java/forestry/core/genetics/Chromosome.java b/src/main/java/forestry/core/genetics/Chromosome.java index 950f552ca..22b9941f9 100755 --- a/src/main/java/forestry/core/genetics/Chromosome.java +++ b/src/main/java/forestry/core/genetics/Chromosome.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.genetics; +import javax.annotation.Nonnull; import java.util.Random; import net.minecraft.nbt.NBTTagCompound; @@ -24,27 +25,24 @@ public class Chromosome implements IChromosome { private static final String UID0_TAG = "UID0"; private static final String UID1_TAG = "UID1"; - private IAllele primary; - private IAllele secondary; + @Nonnull + private final IAllele primary; + @Nonnull + private final IAllele secondary; // / CONSTRUCTOR - private Chromosome() { - } - - public Chromosome(IAllele allele) { + public Chromosome(@Nonnull IAllele allele) { primary = secondary = allele; } - public Chromosome(IAllele primary, IAllele secondary) { + public Chromosome(@Nonnull IAllele primary, @Nonnull IAllele secondary) { this.primary = primary; this.secondary = secondary; } - // / SAVING & LOADING - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - primary = AlleleManager.alleleRegistry.getAllele(nbttagcompound.getString(UID0_TAG)); - secondary = AlleleManager.alleleRegistry.getAllele(nbttagcompound.getString(UID1_TAG)); + public Chromosome(@Nonnull NBTTagCompound nbt) { + primary = AlleleManager.alleleRegistry.getAllele(nbt.getString(UID0_TAG)); + secondary = AlleleManager.alleleRegistry.getAllele(nbt.getString(UID1_TAG)); } @Override @@ -97,58 +95,25 @@ public class Chromosome implements IChromosome { return secondary; } } - - public boolean overrideInvalidAlleles(IAllele template, Class chromosomeClass) { - boolean foundInvalidAlleles = false; - - // use the other chromosome instead of the template if it's valid - if (primary != null && chromosomeClass.isInstance(primary)) { - template = primary; - } else if (secondary != null && chromosomeClass.isInstance(secondary)) { - template = secondary; - } - - if (primary == null) { - Log.warning("Missing primary allele: {0}. Setting to: {1}", this, template); - primary = template; - foundInvalidAlleles = true; - } else if (!chromosomeClass.isInstance(primary)) { - Log.warning("Wrong primary allele: {0}. Setting to: {1}", this, template); - primary = template; - foundInvalidAlleles = true; - } - - if (secondary == null) { - Log.warning("Missing secondary allele: {0}. Setting to: {1}", this, template); - secondary = template; - foundInvalidAlleles = true; - } else if (!chromosomeClass.isInstance(secondary)) { - Log.warning("Wrong secondary allele: {0}. Setting to: {1}", this, template); - secondary = template; - foundInvalidAlleles = true; - } - - return foundInvalidAlleles; - } public boolean hasInvalidAlleles(Class chromosomeClass) { if (primary == null) { - Log.severe("Missing primary allele: {0}", this); + Log.warning("Missing primary allele: {}", this); return true; } if (!chromosomeClass.isInstance(primary)) { - Log.severe("Wrong primary allele for: {0}. Should be: {1}", this, chromosomeClass.getSimpleName()); + Log.warning("Wrong primary allele for: {}. Should be: {}", this, chromosomeClass.getSimpleName()); return true; } if (secondary == null) { - Log.severe("Missing secondary allele: {0}", this); + Log.warning("Missing secondary allele: {}", this); return true; } if (!chromosomeClass.isInstance(secondary)) { - Log.severe("Wrong secondary allele for: {0}. Should be: {1}", this, chromosomeClass.getSimpleName()); + Log.warning("Wrong secondary allele for: {}. Should be: {}", this, chromosomeClass.getSimpleName()); return true; } @@ -156,12 +121,6 @@ public class Chromosome implements IChromosome { } /* HELPER FUNCTIONS */ - public static Chromosome loadChromosomeFromNBT(NBTTagCompound compound) { - Chromosome chromosome = new Chromosome(); - chromosome.readFromNBT(compound); - return chromosome; - } - public static IChromosome inheritChromosome(Random rand, IChromosome parent1, IChromosome parent2) { IAllele choice1; diff --git a/src/main/java/forestry/core/genetics/Genome.java b/src/main/java/forestry/core/genetics/Genome.java index 2b8a30960..6069c7302 100755 --- a/src/main/java/forestry/core/genetics/Genome.java +++ b/src/main/java/forestry/core/genetics/Genome.java @@ -12,43 +12,34 @@ package forestry.core.genetics; import com.google.common.base.Objects; +import javax.annotation.Nonnull; import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IChromosome; import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IGenome; import forestry.api.genetics.ISpeciesRoot; -import forestry.api.lepidopterology.EnumButterflyChromosome; import forestry.core.config.Config; +import forestry.core.utils.Log; public abstract class Genome implements IGenome { private static final String SLOT_TAG = "Slot"; - private static final Set unusedChromsomes = new HashSet<>(); - static { - unusedChromsomes.add(EnumBeeChromosome.HUMIDITY); - unusedChromsomes.add(EnumButterflyChromosome.TERRITORY); + @Nonnull + private final IChromosome[] chromosomes; + + protected Genome(@Nonnull NBTTagCompound nbttagcompound) { + this.chromosomes = getChromosomes(nbttagcompound, getSpeciesRoot()); } - private IChromosome[] chromosomes; - - // / CONSTRUCTOR - protected Genome(NBTTagCompound nbttagcompound) { - this.chromosomes = new Chromosome[getDefaultTemplate().length]; - readFromNBT(nbttagcompound); - } - - protected Genome(IChromosome[] chromosomes) { + protected Genome(@Nonnull IChromosome[] chromosomes) { checkChromosomes(chromosomes); this.chromosomes = chromosomes; } @@ -62,10 +53,6 @@ public abstract class Genome implements IGenome { IChromosomeType[] karyotype = getSpeciesRoot().getKaryotype(); for (int i = 0; i < karyotype.length; i++) { IChromosomeType chromosomeType = karyotype[i]; - if (unusedChromsomes.contains(chromosomeType)) { - continue; - } - IChromosome chromosome = chromosomes[i]; if (chromosome == null) { String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + @@ -111,9 +98,6 @@ public abstract class Genome implements IGenome { IChromosomeType[] karyotype = getSpeciesRoot().getKaryotype(); for (int i = 0; i < chromosomes.length; i++) { IChromosomeType chromosomeType = karyotype[i]; - if (unusedChromsomes.contains(chromosomeType)) { - continue; - } IChromosome chromosome = chromosomes[i]; stringBuilder.append(chromosomeType.getName()).append(": ").append(chromosome).append("\n"); } @@ -148,7 +132,7 @@ public abstract class Genome implements IGenome { } NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(0); - Chromosome chromosome = Chromosome.loadChromosomeFromNBT(chromosomeNBT); + Chromosome chromosome = new Chromosome(chromosomeNBT); IAllele activeAllele = chromosome.getActiveAllele(); if (!(activeAllele instanceof IAlleleSpecies)) { @@ -177,7 +161,7 @@ public abstract class Genome implements IGenome { return chromosomes[chromosomeType.ordinal()]; } - private static IChromosome[] getChromosomes(NBTTagCompound genomeNBT, ISpeciesRoot speciesRoot) { + private static IChromosome[] getChromosomes(@Nonnull NBTTagCompound genomeNBT, @Nonnull ISpeciesRoot speciesRoot) { NBTTagList chromosomesNBT = genomeNBT.getTagList("Chromosomes", 10); IChromosome[] chromosomes = new IChromosome[speciesRoot.getDefaultTemplate().length]; @@ -187,33 +171,19 @@ public abstract class Genome implements IGenome { byte chromosomeOrdinal = chromosomeNBT.getByte(SLOT_TAG); if (chromosomeOrdinal >= 0 && chromosomeOrdinal < chromosomes.length) { - Chromosome chromosome = Chromosome.loadChromosomeFromNBT(chromosomeNBT); + Chromosome chromosome = new Chromosome(chromosomeNBT); chromosomes[chromosomeOrdinal] = chromosome; - if (Config.clearInvalidChromosomes) { - IAllele template = speciesRoot.getDefaultTemplate()[chromosomeOrdinal]; - Class chromosomeClass = speciesRoot.getKaryotype()[chromosomeOrdinal].getAlleleClass(); - if (chromosome.overrideInvalidAlleles(template, chromosomeClass)) { - chromosome.writeToNBT(chromosomeNBT); + IChromosomeType chromosomeType = speciesRoot.getKaryotype()[chromosomeOrdinal]; + if (chromosome.hasInvalidAlleles(chromosomeType.getAlleleClass())) { + if (Config.clearInvalidChromosomes) { + Log.warning("Found Chromosome with invalid Alleles. Config is set to clear invalid chromosomes, replacing with the default."); + IAllele[] defaultTemplate = speciesRoot.getDefaultTemplate(); + return speciesRoot.templateAsChromosomes(defaultTemplate); + } else { + throw new RuntimeException("Found Chromosome with invalid Alleles.\nNBTTagCompound: " + chromosomesNBT + "\nSee config option \"genetics.clear.invalid.chromosomes\".\nMissing: " + chromosomeNBT); } } - - if (chromosome.hasInvalidAlleles(speciesRoot.getKaryotype()[chromosomeOrdinal].getAlleleClass())) { - throw new RuntimeException("Found Chromosome with invalid Alleles.\nNBTTagCompound: " + chromosomesNBT + "\nSee config option \"genetics.clear.invalid.chromosomes\".\nMissing: " + chromosomeNBT); - } - } - } - - // handle old saves that have missing chromosomes - IChromosome speciesChromosome = chromosomes[speciesRoot.getKaryotypeKey().ordinal()]; - if (speciesChromosome != null) { - IAlleleSpecies species = (IAlleleSpecies) speciesChromosome.getActiveAllele(); - IAllele[] template = speciesRoot.getTemplate(species.getUID()); - for (int i = 0; i < chromosomes.length; i++) { - IAllele allele = template[i]; - if ((chromosomes[i] == null) && (allele != null)) { - chromosomes[i] = new Chromosome(allele); - } } } @@ -228,12 +198,6 @@ public abstract class Genome implements IGenome { return chromosome.getActiveAllele(); } - // / SAVING & LOADING - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - chromosomes = getChromosomes(nbttagcompound, getSpeciesRoot()); - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { diff --git a/src/main/java/forestry/core/genetics/Individual.java b/src/main/java/forestry/core/genetics/Individual.java index 3ad4d12ae..4a9d5fb8d 100755 --- a/src/main/java/forestry/core/genetics/Individual.java +++ b/src/main/java/forestry/core/genetics/Individual.java @@ -19,10 +19,10 @@ import forestry.api.genetics.IIndividual; public abstract class Individual implements IIndividual { - protected boolean isAnalyzed = false; + protected boolean isAnalyzed; protected Individual() { - + isAnalyzed = false; } protected Individual(@Nonnull NBTTagCompound nbt) { @@ -44,16 +44,6 @@ public abstract class Individual implements IIndividual { return true; } - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - if (nbttagcompound == null) { - return; - } - - isAnalyzed = nbttagcompound.getBoolean("IsAnalyzed"); - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setBoolean("IsAnalyzed", isAnalyzed); diff --git a/src/main/java/forestry/core/genetics/IndividualLiving.java b/src/main/java/forestry/core/genetics/IndividualLiving.java index 20e4e32db..0c077b58e 100755 --- a/src/main/java/forestry/core/genetics/IndividualLiving.java +++ b/src/main/java/forestry/core/genetics/IndividualLiving.java @@ -35,17 +35,6 @@ public abstract class IndividualLiving extends Individual implements IIndividual health = nbt.getInteger("Health"); maxHealth = nbt.getInteger("MaxH"); } - - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - - super.readFromNBT(nbttagcompound); - - health = nbttagcompound.getInteger("Health"); - maxHealth = nbttagcompound.getInteger("MaxH"); - - } @Override public void writeToNBT(NBTTagCompound nbttagcompound) { diff --git a/src/main/java/forestry/core/genetics/alleles/AlleleHelper.java b/src/main/java/forestry/core/genetics/alleles/AlleleHelper.java index d385279d0..e8bb94c22 100644 --- a/src/main/java/forestry/core/genetics/alleles/AlleleHelper.java +++ b/src/main/java/forestry/core/genetics/alleles/AlleleHelper.java @@ -119,7 +119,7 @@ public class AlleleHelper implements IAlleleHelper { booleans.put(false, new AlleleBoolean(modId, "bool", false, false)); for (IAlleleBoolean alleleBoolean : booleans.values()) { AlleleManager.alleleRegistry.registerAllele(alleleBoolean, - EnumBeeChromosome.NOCTURNAL, + EnumBeeChromosome.NEVER_SLEEPS, EnumBeeChromosome.TOLERANT_FLYER, EnumBeeChromosome.CAVE_DWELLING, EnumButterflyChromosome.NOCTURNAL, diff --git a/src/main/java/forestry/core/inventory/IInventoryAdapter.java b/src/main/java/forestry/core/inventory/IInventoryAdapter.java index 33af8dcc2..b313ef583 100644 --- a/src/main/java/forestry/core/inventory/IInventoryAdapter.java +++ b/src/main/java/forestry/core/inventory/IInventoryAdapter.java @@ -1,10 +1,11 @@ package forestry.core.inventory; import net.minecraft.inventory.ISidedInventory; +import net.minecraft.nbt.NBTTagCompound; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; import forestry.core.tiles.IFilterSlotDelegate; -public interface IInventoryAdapter extends ISidedInventory, IFilterSlotDelegate, INBTTagable { - +public interface IInventoryAdapter extends ISidedInventory, IFilterSlotDelegate, INbtWritable { + void readFromNBT(NBTTagCompound nbt); } diff --git a/src/main/java/forestry/core/inventory/InventoryPlain.java b/src/main/java/forestry/core/inventory/InventoryPlain.java index 9272a1b04..e979931c3 100644 --- a/src/main/java/forestry/core/inventory/InventoryPlain.java +++ b/src/main/java/forestry/core/inventory/InventoryPlain.java @@ -17,10 +17,11 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.core.utils.InventoryUtil; -public class InventoryPlain implements IInventory, INBTTagable { +public class InventoryPlain implements IInventory, INbtWritable, INbtReadable { private final ItemStack[] contents; private final String name; diff --git a/src/main/java/forestry/core/items/ItemPipette.java b/src/main/java/forestry/core/items/ItemPipette.java index 54836d297..8bb40a6c2 100755 --- a/src/main/java/forestry/core/items/ItemPipette.java +++ b/src/main/java/forestry/core/items/ItemPipette.java @@ -47,25 +47,25 @@ public class ItemPipette extends ItemForestry implements IToolPipette { @Override public boolean canPipette(ItemStack itemstack) { - PipetteContents contained = new PipetteContents(itemstack.getTagCompound()); - return !contained.isFull(); + PipetteContents contained = PipetteContents.create(itemstack); + return contained != null && !contained.isFull(); } @Override public int fill(ItemStack itemstack, FluidStack liquid, boolean doFill) { - PipetteContents contained = new PipetteContents(itemstack.getTagCompound()); + PipetteContents contained = PipetteContents.create(itemstack); int limit = getCapacity(itemstack); int filled; - if (contained.getContents() == null) { + if (contained == null) { if (liquid.amount > limit) { filled = limit; } else { filled = liquid.amount; } - contained.setContents(new FluidStack(liquid, filled)); + contained = new PipetteContents(new FluidStack(liquid, filled)); filled = liquid.amount; } else { if (contained.getContents().amount >= limit) { @@ -99,8 +99,10 @@ public class ItemPipette extends ItemForestry implements IToolPipette { @SuppressWarnings({"rawtypes", "unchecked"}) @Override public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) { - PipetteContents contained = new PipetteContents(itemstack.getTagCompound()); - contained.addTooltip(list); + PipetteContents contained = PipetteContents.create(itemstack); + if (contained != null) { + contained.addTooltip(list); + } } /* Models */ @@ -132,8 +134,8 @@ public class ItemPipette extends ItemForestry implements IToolPipette { @Override public FluidStack drain(ItemStack pipette, int maxDrain, boolean doDrain) { - PipetteContents contained = new PipetteContents(pipette.getTagCompound()); - if (contained.getContents() == null) { + PipetteContents contained = PipetteContents.create(pipette); + if (contained == null) { return null; } diff --git a/src/main/java/forestry/core/multiblock/IMultiblockControllerInternal.java b/src/main/java/forestry/core/multiblock/IMultiblockControllerInternal.java index 87a8e3953..d3221435c 100644 --- a/src/main/java/forestry/core/multiblock/IMultiblockControllerInternal.java +++ b/src/main/java/forestry/core/multiblock/IMultiblockControllerInternal.java @@ -18,7 +18,8 @@ import net.minecraft.util.BlockPos; import net.minecraft.world.World; import forestry.api.core.IErrorLogicSource; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.api.multiblock.IMultiblockComponent; import forestry.api.multiblock.IMultiblockController; import forestry.core.access.IRestrictedAccess; @@ -26,7 +27,7 @@ import forestry.core.network.IStreamableGui; import forestry.core.tiles.IClimatised; // internal implementation of IMultiblockController -public interface IMultiblockControllerInternal extends IMultiblockController, INBTTagable, IRestrictedAccess, IErrorLogicSource, IClimatised, IStreamableGui { +public interface IMultiblockControllerInternal extends IMultiblockController, INbtWritable, INbtReadable, IRestrictedAccess, IErrorLogicSource, IClimatised, IStreamableGui { /** * Attach a new part to this machine. * @param part The part to add. diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java index 9a0c1e5cc..49f7b1f54 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerBase.java @@ -467,9 +467,7 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI /** * @param level the level of the block on the multiblock, starting at 0 for the bottom. * @param world World object for the world in which this controller is located. - * @param x X coordinate of the block being tested - * @param y Y coordinate of the block being tested - * @param z Z coordinate of the block being tested + * @param pos coordinate of the block being tested * @throws MultiblockValidationException if the tested block is not allowed on the machine's side faces */ protected void isBlockGoodForExteriorLevel(int level, World world, BlockPos pos) throws MultiblockValidationException { @@ -480,9 +478,7 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI /** * The interior is any block that does not touch blocks outside the machine. * @param world World object for the world in which this controller is located. - * @param x X coordinate of the block being tested - * @param y Y coordinate of the block being tested - * @param z Z coordinate of the block being tested + * @param pos coordinate of the block being tested * @throws MultiblockValidationException if the tested block is not allowed in the machine's interior */ protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException { @@ -619,8 +615,8 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI } else if (res > 0) { return false; } else { - Log.severe("My Controller (%d): size (%d), parts: %s", hashCode(), connectedParts.size(), getPartsListString()); - Log.severe("Other Controller (%d): size (%d), coords: %s", otherController.hashCode(), otherController.getComponents().size(), otherController.getPartsListString()); + Log.error("My Controller (%d): size (%d), parts: %s", hashCode(), connectedParts.size(), getPartsListString()); + Log.error("Other Controller (%d): size (%d), coords: %s", otherController.hashCode(), otherController.getComponents().size(), otherController.getPartsListString()); throw new IllegalArgumentException("[" + (worldObj.isRemote ? "CLIENT" : "SERVER") + "] " + "Two controllers with the same reference coord that somehow both have valid parts - this should never happen!"); } diff --git a/src/main/java/forestry/core/multiblock/MultiblockControllerForestry.java b/src/main/java/forestry/core/multiblock/MultiblockControllerForestry.java index 9f6eb82a2..5664e41f5 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockControllerForestry.java +++ b/src/main/java/forestry/core/multiblock/MultiblockControllerForestry.java @@ -86,7 +86,7 @@ public abstract class MultiblockControllerForestry extends MultiblockControllerB getAccessHandler().setOwner(owner); } - /* INBTTagable */ + /* INbtWritable */ @Override public void writeToNBT(NBTTagCompound data) { accessHandler.writeToNBT(data); diff --git a/src/main/java/forestry/core/multiblock/MultiblockWorldRegistry.java b/src/main/java/forestry/core/multiblock/MultiblockWorldRegistry.java index 7f16413be..cdf3b8394 100644 --- a/src/main/java/forestry/core/multiblock/MultiblockWorldRegistry.java +++ b/src/main/java/forestry/core/multiblock/MultiblockWorldRegistry.java @@ -193,7 +193,7 @@ public class MultiblockWorldRegistry { } if (newMaster == null) { - Log.severe("Multiblock system checked a merge pool of size %d, found no master candidates. This should never happen.", mergePool.size()); + Log.error("Multiblock system checked a merge pool of size %d, found no master candidates. This should never happen.", mergePool.size()); } else { // Merge all the other machines into the master machine, then unregister them addDirtyController(newMaster); @@ -244,7 +244,7 @@ public class MultiblockWorldRegistry { // Go through any controllers which have marked themselves as potentially dead. // Validate that they are empty/dead, then unregister them. if (!controller.isEmpty()) { - Log.severe("Found a non-empty controller. Forcing it to shed its blocks and die. This should never happen!"); + Log.error("Found a non-empty controller. Forcing it to shed its blocks and die. This should never happen!"); detachedParts.addAll(controller.detachAllBlocks()); } diff --git a/src/main/java/forestry/core/tiles/EscritoireGame.java b/src/main/java/forestry/core/tiles/EscritoireGame.java index b8c97780d..0fc1a0a7c 100644 --- a/src/main/java/forestry/core/tiles/EscritoireGame.java +++ b/src/main/java/forestry/core/tiles/EscritoireGame.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.tiles; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.Random; @@ -17,7 +18,8 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IIndividual; @@ -25,7 +27,7 @@ import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; -public class EscritoireGame implements INBTTagable, IStreamable { +public class EscritoireGame implements INbtWritable, INbtReadable, IStreamable { private static final Random rand = new Random(); public static final int BOUNTY_MAX = 16; @@ -34,11 +36,16 @@ public class EscritoireGame implements INBTTagable, IStreamable { public static final Status[] VALUES = values(); } - private final EscritoireGameBoard gameBoard = new EscritoireGameBoard(); + @Nonnull + private EscritoireGameBoard gameBoard; private long lastUpdate; private int bountyLevel; private Status status = Status.EMPTY; + public EscritoireGame() { + gameBoard = new EscritoireGameBoard(); + } + public EscritoireGameToken getToken(int index) { return gameBoard.getToken(index); } @@ -51,7 +58,6 @@ public class EscritoireGame implements INBTTagable, IStreamable { return lastUpdate; } - /* SAVING & LOADING */ @Override public void writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("bountyLevel", bountyLevel); @@ -62,13 +68,13 @@ public class EscritoireGame implements INBTTagable, IStreamable { } @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - bountyLevel = nbttagcompound.getInteger("bountyLevel"); - lastUpdate = nbttagcompound.getLong("lastUpdate"); - gameBoard.readFromNBT(nbttagcompound); + public void readFromNBT(NBTTagCompound nbt) { + bountyLevel = nbt.getInteger("bountyLevel"); + lastUpdate = nbt.getLong("lastUpdate"); + gameBoard = new EscritoireGameBoard(nbt); - if (nbttagcompound.hasKey("Status")) { - int statusOrdinal = nbttagcompound.getInteger("Status"); + if (nbt.hasKey("Status")) { + int statusOrdinal = nbt.getInteger("Status"); status = Status.values()[statusOrdinal]; } diff --git a/src/main/java/forestry/core/tiles/EscritoireGameBoard.java b/src/main/java/forestry/core/tiles/EscritoireGameBoard.java index 178ae9280..04fc38479 100644 --- a/src/main/java/forestry/core/tiles/EscritoireGameBoard.java +++ b/src/main/java/forestry/core/tiles/EscritoireGameBoard.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.tiles; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -20,7 +21,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IGenome; @@ -30,7 +31,7 @@ import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; -public class EscritoireGameBoard implements INBTTagable, IStreamable { +public class EscritoireGameBoard implements INbtWritable, IStreamable { private static final Random rand = new Random(); private static final int TOKEN_COUNT_MAX = 22; private static final int TOKEN_COUNT_MIN = 6; @@ -38,6 +39,26 @@ public class EscritoireGameBoard implements INBTTagable, IStreamable { private final List gameTokens = new ArrayList<>(TOKEN_COUNT_MAX); private int tokenCount; + public EscritoireGameBoard() { + + } + + public EscritoireGameBoard(@Nonnull NBTTagCompound nbt) { + tokenCount = nbt.getInteger("TokenCount"); + + if (tokenCount > 0) { + EscritoireGameToken[] tokens = new EscritoireGameToken[tokenCount]; + NBTTagList nbttaglist = nbt.getTagList("GameTokens", 10); + + for (int j = 0; j < nbttaglist.tagCount(); ++j) { + NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j); + int index = nbttagcompound2.getByte("Slot"); + tokens[index] = new EscritoireGameToken(nbttagcompound2); + } + + Collections.addAll(gameTokens, tokens); + } + } public boolean initialize(ItemStack specimen) { IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen); @@ -168,26 +189,6 @@ public class EscritoireGameBoard implements INBTTagable, IStreamable { return tokenCount; } - /* INBTTagable */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - tokenCount = nbttagcompound.getInteger("TokenCount"); - gameTokens.clear(); - - if (tokenCount > 0) { - EscritoireGameToken[] tokens = new EscritoireGameToken[tokenCount]; - NBTTagList nbttaglist = nbttagcompound.getTagList("GameTokens", 10); - - for (int j = 0; j < nbttaglist.tagCount(); ++j) { - NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j); - int index = nbttagcompound2.getByte("Slot"); - tokens[index] = new EscritoireGameToken(nbttagcompound2); - } - - Collections.addAll(gameTokens, tokens); - } - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { if (tokenCount > 0) { diff --git a/src/main/java/forestry/core/tiles/EscritoireGameToken.java b/src/main/java/forestry/core/tiles/EscritoireGameToken.java index 6fe49ac9d..6c75aa2cf 100644 --- a/src/main/java/forestry/core/tiles/EscritoireGameToken.java +++ b/src/main/java/forestry/core/tiles/EscritoireGameToken.java @@ -10,12 +10,14 @@ ******************************************************************************/ package forestry.core.tiles; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.IOException; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; import forestry.core.network.DataInputStreamForestry; @@ -24,7 +26,7 @@ import forestry.core.network.IStreamable; import forestry.core.utils.ColourUtil; import forestry.core.utils.StringUtil; -public class EscritoireGameToken implements INBTTagable, IStreamable { +public class EscritoireGameToken implements INbtWritable, IStreamable { private enum State { UNREVEALED,// face down @@ -39,7 +41,9 @@ public class EscritoireGameToken implements INBTTagable, IStreamable { private static final String[] OVERLAY_FAILED = new String[]{"errors/errored"}; private static final String[] OVERLAY_SELECTED = new String[]{"errors/unknown"}; + @Nullable private ItemStack tokenStack; + @Nonnull private State state = State.UNREVEALED; @SuppressWarnings("unused") @@ -47,14 +51,22 @@ public class EscritoireGameToken implements INBTTagable, IStreamable { // required for IStreamable serialization } - public EscritoireGameToken(ItemStack tokenStack) { + public EscritoireGameToken(@Nullable ItemStack tokenStack) { this.tokenStack = tokenStack; } - public EscritoireGameToken(NBTTagCompound nbttagcompound) { - readFromNBT(nbttagcompound); + public EscritoireGameToken(@Nonnull NBTTagCompound nbttagcompound) { + if (nbttagcompound.hasKey("state")) { + int stateOrdinal = nbttagcompound.getInteger("state"); + state = State.values()[stateOrdinal]; + } + + if (nbttagcompound.hasKey("tokenStack")) { + tokenStack = ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("tokenStack")); + } } + @Nullable public ItemStack getTokenStack() { return tokenStack; } @@ -129,19 +141,6 @@ public class EscritoireGameToken implements INBTTagable, IStreamable { return ItemStack.areItemStacksEqual(tokenStack, other.getTokenStack()); } - /* INBTTagable */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - if (nbttagcompound.hasKey("state")) { - int stateOrdinal = nbttagcompound.getInteger("state"); - state = State.values()[stateOrdinal]; - } - - if (nbttagcompound.hasKey("tokenStack")) { - tokenStack = ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("tokenStack")); - } - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("state", state.ordinal()); diff --git a/src/main/java/forestry/core/utils/EntityUtil.java b/src/main/java/forestry/core/utils/EntityUtil.java index a2c986982..017abad2b 100644 --- a/src/main/java/forestry/core/utils/EntityUtil.java +++ b/src/main/java/forestry/core/utils/EntityUtil.java @@ -49,7 +49,7 @@ public abstract class EntityUtil { public static void registerEntity(Class entityClass, String ident, int id, int eggForeground, int eggBackground, int trackingRange, int updateFrequency, boolean sendVelocity) { EntityRegistry.registerModEntity(entityClass, ident, id, ForestryAPI.instance, trackingRange, updateFrequency, sendVelocity); - Log.finer("Registered entity %s (%s) with id %s.", ident, entityClass.toString(), id); + Log.debug("Registered entity %s (%s) with id %s.", ident, entityClass.toString(), id); } @SuppressWarnings("unchecked") diff --git a/src/main/java/forestry/core/utils/Log.java b/src/main/java/forestry/core/utils/Log.java index d6114e8ac..c65b28489 100644 --- a/src/main/java/forestry/core/utils/Log.java +++ b/src/main/java/forestry/core/utils/Log.java @@ -12,128 +12,33 @@ package forestry.core.utils; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.message.MessageFormatMessage; import forestry.core.config.Constants; -public abstract class Log { +public class Log { - /* FINEST */ - public static void finest(String message) { - log(Level.TRACE, message); - } - - public static void finest(String message, Object param) { - log(Level.TRACE, message, param); - } - - public static void finest(String message, Object... params) { + public static void trace(String message, Object... params) { log(Level.TRACE, message, params); } - /* FINER */ - public static void finer(String message) { - log(Level.TRACE, message); - } - - public static void finer(String message, Object param) { - log(Level.TRACE, message, param); - } - - public static void finer(String message, Object... params) { - log(Level.TRACE, message, params); - } - - /* FINE */ - public static void fine(String message) { - log(Level.DEBUG, message); - } - - public static void fine(String message, Object param) { - log(Level.DEBUG, message, param); - } - - public static void fine(String message, Object... params) { + public static void debug(String message, Object... params) { log(Level.DEBUG, message, params); } - /* INFO */ - public static void info(String message) { - log(Level.INFO, message); - } - - public static void info(String message, Object param) { - log(Level.INFO, message, param); - } - public static void info(String message, Object... params) { log(Level.INFO, message, params); } - /* WARNING */ - public static void warning(String message) { - log(Level.WARN, message); - } - - public static void warning(String message, Object param) { - log(Level.WARN, message, param); - } - public static void warning(String message, Object... params) { log(Level.WARN, message, params); } - /* SEVERE */ - public static void severe(String message) { - log(Level.FATAL, message); - } - - public static void severe(String message, Object param) { - log(Level.FATAL, message, param); - } - - public static void severe(String message, Object... params) { - log(Level.FATAL, message, params); - } - - /* GENERIC */ - private static void log(Level logLevel, String message) { - LogManager.getLogger(Constants.MOD).log(logLevel, message); + public static void error(String message, Object... params) { + log(Level.ERROR, message, params); } private static void log(Level logLevel, String message, Object... params) { - LogManager.getLogger(Constants.MOD).log(logLevel, new MessageFormatMessage(String.format(message, params), params)); - } - - /* EXCEPTIONS */ - public static void logThrowable(String msg, Throwable error, Object... args) { - logThrowable(Level.ERROR, msg, 3, error, args); - } - - public static void logThrowable(String msg, int lines, Throwable error, Object... args) { - logThrowable(Level.ERROR, msg, lines, error, args); - } - - public static void logThrowable(Level level, String msg, int lines, Throwable error, Object... args) { - StackTraceElement[] oldtrace = error.getStackTrace(); - if (lines < oldtrace.length) { - StackTraceElement[] newtrace = new StackTraceElement[lines]; - System.arraycopy(oldtrace, 0, newtrace, 0, newtrace.length); - error.setStackTrace(newtrace); - } - LogManager.getLogger(Constants.MOD).log(level, new MessageFormatMessage(msg, args), error); - } - - public static void logErrorAPI(String mod, Throwable error, Class classFile) { - StringBuilder msg = new StringBuilder(mod); - msg.append(" API error, please update your mods. Error: ").append(error); - logThrowable(Level.ERROR, msg.toString(), 2, error); - - if (classFile != null) { - msg = new StringBuilder(mod); - msg.append(" API error: ").append(classFile.getSimpleName()).append(" is loaded from ").append(classFile.getProtectionDomain().getCodeSource().getLocation()); - log(Level.ERROR, msg.toString()); - } + LogManager.getLogger(Constants.ID).log(logLevel, message, params); } } diff --git a/src/main/java/forestry/energy/render/RenderEngine.java b/src/main/java/forestry/energy/render/RenderEngine.java index 647cc813c..643dc95de 100755 --- a/src/main/java/forestry/energy/render/RenderEngine.java +++ b/src/main/java/forestry/energy/render/RenderEngine.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.energy.render; +import javax.annotation.Nullable; + import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; @@ -23,7 +25,6 @@ import forestry.core.proxy.Proxies; import forestry.core.render.ForestryResource; import forestry.core.tiles.TemperatureState; import forestry.core.tiles.TileEngine; -import forestry.core.utils.Log; public class RenderEngine extends TileEntitySpecialRenderer { @@ -91,14 +92,9 @@ public class RenderEngine extends TileEntitySpecialRenderer { } @Override - public void renderTileEntityAt(TileEngine engine, double x, double y, double z, float partialTicks, int destroyStage) { + public void renderTileEntityAt(@Nullable TileEngine engine, double x, double y, double z, float partialTicks, int destroyStage) { if (engine != null) { - if (engine instanceof TileEngine) { - TileEngine tileEngine = engine; - render(tileEngine.getTemperatureState(), tileEngine.progress, tileEngine.getOrientation(), x, y, z); - } else { - Log.severe("Tried to render a tile entity that is not an engine: " + engine); - } + render(engine.getTemperatureState(), engine.progress, engine.getOrientation(), x, y, z); } else { render(TemperatureState.COOL, 0.25F, EnumFacing.UP, x, y, z); } diff --git a/src/main/java/forestry/factory/recipes/MemorizedRecipe.java b/src/main/java/forestry/factory/recipes/MemorizedRecipe.java index f4c93d63e..9750d56c4 100644 --- a/src/main/java/forestry/factory/recipes/MemorizedRecipe.java +++ b/src/main/java/forestry/factory/recipes/MemorizedRecipe.java @@ -18,7 +18,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; @@ -27,7 +28,7 @@ import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; import forestry.factory.inventory.InventoryCraftingForestry; -public final class MemorizedRecipe implements INBTTagable, IStreamable { +public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStreamable { private final InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry(); private final List recipeOutputs = new ArrayList<>(); private int selectedRecipe; @@ -112,7 +113,7 @@ public final class MemorizedRecipe implements INBTTagable, IStreamable { return locked; } - /* INBTTagable */ + /* INbtWritable */ @Override public final void readFromNBT(NBTTagCompound nbttagcompound) { InventoryUtil.readFromNBT(craftMatrix, nbttagcompound); diff --git a/src/main/java/forestry/factory/recipes/RecipeMemory.java b/src/main/java/forestry/factory/recipes/RecipeMemory.java index d8c267909..80a276a4c 100644 --- a/src/main/java/forestry/factory/recipes/RecipeMemory.java +++ b/src/main/java/forestry/factory/recipes/RecipeMemory.java @@ -10,8 +10,10 @@ ******************************************************************************/ package forestry.factory.recipes; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -22,14 +24,14 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; -public class RecipeMemory implements INBTTagable, IStreamable { +public class RecipeMemory implements INbtWritable, IStreamable { - public static final int capacity = 9; + private static final int capacity = 9; private static final List> memoryBlacklist = new ArrayList<>(); @@ -37,9 +39,28 @@ public class RecipeMemory implements INBTTagable, IStreamable { memoryBlacklist.add(ItemMap.class); // almost every ItemMap is unique } - private LinkedList memorizedRecipes = new LinkedList<>(); + private final LinkedList memorizedRecipes; private long lastUpdate; + public RecipeMemory() { + memorizedRecipes = new LinkedList<>(); + } + + public RecipeMemory(@Nonnull NBTTagCompound nbt) { + memorizedRecipes = new LinkedList<>(); + if (!nbt.hasKey("RecipeMemory")) { + return; + } + + NBTTagList nbttaglist = nbt.getTagList("RecipeMemory", 10); + for (int j = 0; j < nbttaglist.tagCount(); ++j) { + NBTTagCompound recipeNbt = nbttaglist.getCompoundTagAt(j); + MemorizedRecipe recipe = new MemorizedRecipe(); + recipe.readFromNBT(recipeNbt); + memorizedRecipes.add(recipe); + } + } + private static boolean isValid(MemorizedRecipe recipe) { if (recipe == null) { return false; @@ -53,16 +74,16 @@ public class RecipeMemory implements INBTTagable, IStreamable { } public void validate(World world) { - LinkedList validRecipes = new LinkedList<>(); - for (MemorizedRecipe recipe : memorizedRecipes) { + Iterator iterator = memorizedRecipes.iterator(); + while (iterator.hasNext()) { + MemorizedRecipe recipe = iterator.next(); if (recipe != null) { recipe.calculateRecipeOutput(world); - if (isValid(recipe)) { - validRecipes.add(recipe); + if (!isValid(recipe)) { + iterator.remove(); } } } - this.memorizedRecipes = validRecipes; } public long getLastUpdate() { @@ -162,22 +183,6 @@ public class RecipeMemory implements INBTTagable, IStreamable { return null; } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - memorizedRecipes = new LinkedList<>(); - if (!nbttagcompound.hasKey("RecipeMemory")) { - return; - } - - NBTTagList nbttaglist = nbttagcompound.getTagList("RecipeMemory", 10); - for (int j = 0; j < nbttaglist.tagCount(); ++j) { - NBTTagCompound recipeNbt = nbttaglist.getCompoundTagAt(j); - MemorizedRecipe recipe = new MemorizedRecipe(); - recipe.readFromNBT(recipeNbt); - memorizedRecipes.add(recipe); - } - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { NBTTagList nbttaglist = new NBTTagList(); diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/factory/tiles/TileWorktable.java index 9c9924162..0d0c7b6b5 100644 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/factory/tiles/TileWorktable.java @@ -38,7 +38,7 @@ import forestry.factory.recipes.MemorizedRecipe; import forestry.factory.recipes.RecipeMemory; public class TileWorktable extends TileBase implements ICrafterWorktable { - private final RecipeMemory recipeMemory; + private RecipeMemory recipeMemory; private final InventoryAdapterTile craftingDisplay; private MemorizedRecipe currentRecipe; @@ -64,7 +64,7 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { super.readFromNBT(nbttagcompound); craftingDisplay.readFromNBT(nbttagcompound); - recipeMemory.readFromNBT(nbttagcompound); + recipeMemory = new RecipeMemory(nbttagcompound); } /* NETWORK */ diff --git a/src/main/java/forestry/farming/blocks/BlockMushroom.java b/src/main/java/forestry/farming/blocks/BlockMushroom.java index 138d5cdf1..db7ccb929 100644 --- a/src/main/java/forestry/farming/blocks/BlockMushroom.java +++ b/src/main/java/forestry/farming/blocks/BlockMushroom.java @@ -17,7 +17,6 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockBush; import net.minecraft.block.IGrowable; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; @@ -69,7 +68,7 @@ public class BlockMushroom extends BlockBush implements IItemTyped, IItemModelRe @Override protected BlockState createBlockState() { - return new BlockState(this, new IProperty[]{MUSHROOM}); + return new BlockState(this, MUSHROOM); } @Override diff --git a/src/main/java/forestry/farming/logic/Crop.java b/src/main/java/forestry/farming/logic/Crop.java index 45df393b0..797311b4c 100755 --- a/src/main/java/forestry/farming/logic/Crop.java +++ b/src/main/java/forestry/farming/logic/Crop.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.farming.logic; +import javax.annotation.Nullable; import java.util.Collection; import net.minecraft.block.Block; @@ -52,6 +53,7 @@ public abstract class Crop implements ICrop { protected abstract Collection harvestBlock(Vect pos); + @Nullable @Override public Collection harvest() { if (!isCrop(position)) { diff --git a/src/main/java/forestry/farming/multiblock/FarmController.java b/src/main/java/forestry/farming/multiblock/FarmController.java index 9772e0b20..4fb897e4a 100644 --- a/src/main/java/forestry/farming/multiblock/FarmController.java +++ b/src/main/java/forestry/farming/multiblock/FarmController.java @@ -67,7 +67,6 @@ import forestry.core.multiblock.RectangularMultiblockControllerBase; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.tiles.ILiquidTankTile; -import forestry.core.utils.Log; import forestry.core.utils.PlayerUtil; import forestry.core.utils.vect.Vect; import forestry.core.utils.vect.VectUtil; @@ -754,7 +753,6 @@ public class FarmController extends RectangularMultiblockControllerBase implemen Collection harvested = crop.harvest(); if (harvested == null) { - Log.fine("Failed to harvest crop: " + crop); return true; } diff --git a/src/main/java/forestry/farming/multiblock/FarmFertilizerManager.java b/src/main/java/forestry/farming/multiblock/FarmFertilizerManager.java index f14a7c9c9..a35ea124c 100644 --- a/src/main/java/forestry/farming/multiblock/FarmFertilizerManager.java +++ b/src/main/java/forestry/farming/multiblock/FarmFertilizerManager.java @@ -15,19 +15,20 @@ import java.io.IOException; import net.minecraft.nbt.NBTTagCompound; import forestry.api.core.ForestryAPI; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; -public class FarmFertilizerManager implements INBTTagable, IStreamable { +public class FarmFertilizerManager implements INbtWritable, INbtReadable, IStreamable { private static final int BUFFER_FERTILIZER = 200; - private final int fertilizerValue; + private final int fertilizerValue = ForestryAPI.activeMode.getIntegerSetting("farms.fertilizer.value"); private int storedFertilizer; public FarmFertilizerManager() { - this.fertilizerValue = ForestryAPI.activeMode.getIntegerSetting("farms.fertilizer.value"); + storedFertilizer = 0; } public boolean hasFertilizer(int amount) { diff --git a/src/main/java/forestry/farming/multiblock/FarmHydrationManager.java b/src/main/java/forestry/farming/multiblock/FarmHydrationManager.java index 8f0326031..bc439e87a 100644 --- a/src/main/java/forestry/farming/multiblock/FarmHydrationManager.java +++ b/src/main/java/forestry/farming/multiblock/FarmHydrationManager.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.farming.multiblock; +import javax.annotation.Nonnull; import java.io.IOException; import net.minecraft.nbt.NBTTagCompound; @@ -17,23 +18,25 @@ import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import forestry.api.core.BiomeHelper; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.IStreamable; import forestry.core.tiles.IClimatised; import forestry.farming.gui.IFarmLedgerDelegate; -public class FarmHydrationManager implements IFarmLedgerDelegate, INBTTagable, IStreamable { +public class FarmHydrationManager implements IFarmLedgerDelegate, INbtWritable, INbtReadable, IStreamable { private static final int DELAY_HYDRATION = 100; private static final float RAINFALL_MODIFIER_MAX = 15f; private static final float RAINFALL_MODIFIER_MIN = 0.5f; + @Nonnull private final IClimatised climatised; private int hydrationDelay = 0; private int ticksSinceRainfall = 0; - public FarmHydrationManager(IClimatised climatised) { + public FarmHydrationManager(@Nonnull IClimatised climatised) { this.climatised = climatised; } @@ -86,12 +89,6 @@ public class FarmHydrationManager implements IFarmLedgerDelegate, INBTTagable, I return Math.round(((double) ticksSinceRainfall / 24000) * 10) / 10.; } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - hydrationDelay = nbttagcompound.getInteger("HydrationDelay"); - ticksSinceRainfall = nbttagcompound.getInteger("TicksSinceRainfall"); - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("HydrationDelay", hydrationDelay); @@ -109,4 +106,10 @@ public class FarmHydrationManager implements IFarmLedgerDelegate, INBTTagable, I hydrationDelay = data.readVarInt(); ticksSinceRainfall = data.readVarInt(); } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + hydrationDelay = nbt.getInteger("HydrationDelay"); + ticksSinceRainfall = nbt.getInteger("TicksSinceRainfall"); + } } diff --git a/src/main/java/forestry/lepidopterology/ButterflySpawner.java b/src/main/java/forestry/lepidopterology/ButterflySpawner.java index 64d2c59b1..cd967bd17 100755 --- a/src/main/java/forestry/lepidopterology/ButterflySpawner.java +++ b/src/main/java/forestry/lepidopterology/ButterflySpawner.java @@ -58,7 +58,7 @@ public class ButterflySpawner implements ILeafTickHandler { private static void attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) { if (ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), pos.getX(), pos.getY() + 0.1f, pos.getZ()) != null) { - Log.finest("Spawned a butterfly '%s' at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ()); + Log.trace("Spawned a butterfly '%s' at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ()); } } diff --git a/src/main/java/forestry/lepidopterology/genetics/Butterfly.java b/src/main/java/forestry/lepidopterology/genetics/Butterfly.java index 4f8ec3266..4d27031bf 100755 --- a/src/main/java/forestry/lepidopterology/genetics/Butterfly.java +++ b/src/main/java/forestry/lepidopterology/genetics/Butterfly.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.lepidopterology.genetics; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -51,15 +53,27 @@ public class Butterfly extends IndividualLiving implements IButterfly { private static final Random rand = new Random(); - private IButterflyGenome genome; + @Nonnull + private final IButterflyGenome genome; + @Nullable private IButterflyGenome mate; /* CONSTRUCTOR */ - public Butterfly(NBTTagCompound nbttagcompound) { - readFromNBT(nbttagcompound); + public Butterfly(@Nonnull NBTTagCompound nbt) { + super(nbt); + + if (nbt.hasKey("Genome")) { + genome = new ButterflyGenome(nbt.getCompoundTag("Genome")); + } else { + genome = ButterflyManager.butterflyRoot.templateAsGenome(ButterflyManager.butterflyRoot.getDefaultTemplate()); + } + + if (nbt.hasKey("Mate")) { + mate = new ButterflyGenome(nbt.getCompoundTag("Mate")); + } } - public Butterfly(IButterflyGenome genome) { + public Butterfly(@Nonnull IButterflyGenome genome) { super(genome.getLifespan()); this.genome = genome; } @@ -92,29 +106,6 @@ public class Butterfly extends IndividualLiving implements IButterfly { } } - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - - if (nbttagcompound == null) { - this.genome = ButterflyManager.butterflyRoot.templateAsGenome(ButterflyManager.butterflyRoot.getDefaultTemplate()); - return; - } - - super.readFromNBT(nbttagcompound); - - if (nbttagcompound.hasKey("Genome")) { - genome = new ButterflyGenome(nbttagcompound.getCompoundTag("Genome")); - } else { - genome = ButterflyManager.butterflyRoot.templateAsGenome(ButterflyManager.butterflyRoot.getDefaultTemplate()); - } - if (nbttagcompound.hasKey("Mate")) { - mate = new ButterflyGenome(nbttagcompound.getCompoundTag("Mate")); - } - - } - - @Override public IButterfly copy() { NBTTagCompound nbttagcompound = new NBTTagCompound(); @@ -122,11 +113,13 @@ public class Butterfly extends IndividualLiving implements IButterfly { return new Butterfly(nbttagcompound); } + @Nonnull @Override public IButterflyGenome getGenome() { return genome; } + @Nullable @Override public IButterflyGenome getMate() { return mate; diff --git a/src/main/java/forestry/mail/Letter.java b/src/main/java/forestry/mail/Letter.java index 9f57f77d0..1d627bc65 100755 --- a/src/main/java/forestry/mail/Letter.java +++ b/src/main/java/forestry/mail/Letter.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.mail; +import javax.annotation.Nonnull; import java.util.List; import org.apache.commons.lang3.StringUtils; @@ -45,22 +46,14 @@ public class Letter implements ILetter { this.recipient = new IMailAddress[]{recipient}; } - public Letter(NBTTagCompound nbttagcompound) { - if (nbttagcompound != null) { - readFromNBT(nbttagcompound); - } - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - + public Letter(@Nonnull NBTTagCompound nbttagcompound) { this.isProcessed = nbttagcompound.getBoolean("PRC"); - this.sender = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("SDR")); + this.sender = new MailAddress(nbttagcompound.getCompoundTag("SDR")); int recipientCount = nbttagcompound.getShort("CRC"); this.recipient = new MailAddress[recipientCount]; for (int i = 0; i < recipientCount; i++) { - this.recipient[i] = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("RC" + i)); + this.recipient[i] = new MailAddress(nbttagcompound.getCompoundTag("RC" + i)); } this.text = nbttagcompound.getString("TXT"); diff --git a/src/main/java/forestry/mail/MailAddress.java b/src/main/java/forestry/mail/MailAddress.java index e27af10ae..3af1515f8 100644 --- a/src/main/java/forestry/mail/MailAddress.java +++ b/src/main/java/forestry/mail/MailAddress.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.mail; +import javax.annotation.Nonnull; import java.util.Locale; import java.util.UUID; @@ -18,24 +19,26 @@ import net.minecraft.nbt.NBTUtil; import com.mojang.authlib.GameProfile; -import forestry.api.core.INBTTagable; +import forestry.api.core.INbtWritable; import forestry.api.mail.EnumAddressee; import forestry.api.mail.IMailAddress; import forestry.core.utils.PlayerUtil; -public class MailAddress implements INBTTagable, IMailAddress { +public class MailAddress implements INbtWritable, IMailAddress { private static final GameProfile invalidGameProfile = new GameProfile(new UUID(0, 0), ""); - private EnumAddressee type; - private GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players + @Nonnull + private final EnumAddressee type; + @Nonnull + private final GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players public MailAddress() { this.type = EnumAddressee.PLAYER; this.gameProfile = invalidGameProfile; } - public MailAddress(GameProfile gameProfile) { + public MailAddress(@Nonnull GameProfile gameProfile) { if (gameProfile == null) { throw new IllegalArgumentException("gameProfile must not be null"); } @@ -44,7 +47,7 @@ public class MailAddress implements INBTTagable, IMailAddress { this.gameProfile = gameProfile; } - public MailAddress(String name) { + public MailAddress(@Nonnull String name) { if (name == null) { throw new IllegalArgumentException("name must not be null"); } @@ -53,22 +56,27 @@ public class MailAddress implements INBTTagable, IMailAddress { this.gameProfile = new GameProfile(null, name); } - public MailAddress(IMailAddress address) { - this.type = address.getType(); - if (type == EnumAddressee.TRADER) { - String name = address.getName(); - this.gameProfile = new GameProfile(null, name); - } else if (type == EnumAddressee.PLAYER) { - this.gameProfile = address.getPlayerProfile(); + public MailAddress(@Nonnull NBTTagCompound nbt) { + EnumAddressee type = null; + GameProfile gameProfile = null; + if (nbt.hasKey("TP")) { + String typeName = nbt.getString("TP"); + type = EnumAddressee.fromString(typeName); } + + if (type == null) { + type = EnumAddressee.PLAYER; + gameProfile = invalidGameProfile; + } else if (nbt.hasKey("profile")) { + NBTTagCompound profileTag = nbt.getCompoundTag("profile"); + gameProfile = NBTUtil.readGameProfileFromNBT(profileTag); + } + + this.type = type; + this.gameProfile = gameProfile; } - public static MailAddress loadFromNBT(NBTTagCompound nbttagcompound) { - MailAddress address = new MailAddress(); - address.readFromNBT(nbttagcompound); - return address; - } - + @Nonnull @Override public EnumAddressee getType() { return type; @@ -127,23 +135,6 @@ public class MailAddress implements INBTTagable, IMailAddress { } } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - type = null; - if (nbttagcompound.hasKey("TP")) { - String typeName = nbttagcompound.getString("TP"); - type = EnumAddressee.fromString(typeName); - } - - if (type == null) { - type = EnumAddressee.PLAYER; - gameProfile = invalidGameProfile; - } else if (nbttagcompound.hasKey("profile")) { - NBTTagCompound profileTag = nbttagcompound.getCompoundTag("profile"); - gameProfile = NBTUtil.readGameProfileFromNBT(profileTag); - } - } - @Override public void writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setString("TP", type.toString()); diff --git a/src/main/java/forestry/mail/POBox.java b/src/main/java/forestry/mail/POBox.java index 8394b829e..366d7bbb9 100755 --- a/src/main/java/forestry/mail/POBox.java +++ b/src/main/java/forestry/mail/POBox.java @@ -46,7 +46,7 @@ public class POBox extends WorldSavedData implements IInventory { @Override public void readFromNBT(NBTTagCompound nbttagcompound) { if (nbttagcompound.hasKey("address")) { - this.address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address")); + this.address = new MailAddress(nbttagcompound.getCompoundTag("address")); } letters.readFromNBT(nbttagcompound); } diff --git a/src/main/java/forestry/mail/TradeStation.java b/src/main/java/forestry/mail/TradeStation.java index a78eb1588..fd27fad15 100755 --- a/src/main/java/forestry/mail/TradeStation.java +++ b/src/main/java/forestry/mail/TradeStation.java @@ -90,7 +90,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve } if (nbttagcompound.hasKey("address")) { - address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address")); + address = new MailAddress(nbttagcompound.getCompoundTag("address")); } this.isVirtual = nbttagcompound.getBoolean("VRT"); diff --git a/src/main/java/forestry/mail/tiles/TileTrader.java b/src/main/java/forestry/mail/tiles/TileTrader.java index c8c30fd58..bb9dc7560 100644 --- a/src/main/java/forestry/mail/tiles/TileTrader.java +++ b/src/main/java/forestry/mail/tiles/TileTrader.java @@ -88,7 +88,7 @@ public class TileTrader extends TileBase { super.readFromNBT(nbttagcompound); if (nbttagcompound.hasKey("address")) { - address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address")); + address = new MailAddress(nbttagcompound.getCompoundTag("address")); } } diff --git a/src/main/java/forestry/plugins/ForestryPluginUtil.java b/src/main/java/forestry/plugins/ForestryPluginUtil.java index 7af0e5194..75adb6e1e 100644 --- a/src/main/java/forestry/plugins/ForestryPluginUtil.java +++ b/src/main/java/forestry/plugins/ForestryPluginUtil.java @@ -29,7 +29,7 @@ public class ForestryPluginUtil { T instance = asmInstanceClass.newInstance(); instances.add(instance); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { - Log.severe("Failed to load: {}", asmData.getClassName(), e); + Log.error("Failed to load: {}", asmData.getClassName(), e); } } return instances; diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index 82478524f..f119c27aa 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -219,7 +219,7 @@ public class PluginApiculture extends BlankForestryPlugin { } beekeepingMode = config.getStringLocalized("beekeeping", "mode", "NORMAL", validBeekeepingModeNames); - Log.finer("Beekeeping mode read from config: " + beekeepingMode); + Log.debug("Beekeeping mode read from config: " + beekeepingMode); secondPrincessChance = config.getFloatLocalized("beekeeping", "second.princess", secondPrincessChance, 0.0f, 100.0f); @@ -247,7 +247,7 @@ public class PluginApiculture extends BlankForestryPlugin { Set acceptableFlowers = flowerRegistry.getAcceptableFlowers(flowerType); if (acceptableFlowers == null || acceptableFlowers.size() == 0) { - Log.severe("Flower type '" + flowerType + "' has no valid flowers set in apiculture.cfg. Add valid flowers or delete the config to set it to default."); + Log.error("Flower type '" + flowerType + "' has no valid flowers set in apiculture.cfg. Add valid flowers or delete the config to set it to default."); } } @@ -351,7 +351,7 @@ public class PluginApiculture extends BlankForestryPlugin { for (Flower flower : flowers) { String name = ItemStackUtil.getBlockNameFromRegistryAsSting(flower.getBlock()); if (name == null) { - Log.severe("Could not find name for flower: " + flower + " with type: " + flowerType); + Log.warning("Could not find name for flower: " + flower + " with type: " + flowerType); continue; } diff --git a/src/main/java/forestry/plugins/PluginCore.java b/src/main/java/forestry/plugins/PluginCore.java index 1cce4490c..95ab31554 100644 --- a/src/main/java/forestry/plugins/PluginCore.java +++ b/src/main/java/forestry/plugins/PluginCore.java @@ -46,7 +46,6 @@ import forestry.core.blocks.BlockTypeCoreTesr; import forestry.core.circuits.CircuitRegistry; import forestry.core.circuits.SolderManager; import forestry.core.commands.CommandPlugins; -import forestry.core.commands.CommandVersion; import forestry.core.commands.RootCommand; import forestry.core.config.Config; import forestry.core.config.Constants; @@ -114,7 +113,6 @@ public class PluginCore extends BlankForestryPlugin { MinecraftForge.EVENT_BUS.register(this); - rootCommand.addChildCommand(new CommandVersion()); rootCommand.addChildCommand(new CommandPlugins()); blocks.core.addDefinitions(BlockTypeCoreTesr.VALUES); diff --git a/src/main/java/forestry/plugins/PluginFluids.java b/src/main/java/forestry/plugins/PluginFluids.java index e057184db..6751b286e 100644 --- a/src/main/java/forestry/plugins/PluginFluids.java +++ b/src/main/java/forestry/plugins/PluginFluids.java @@ -80,7 +80,7 @@ public class PluginFluids extends BlankForestryPlugin { } } else { GameRegistry.UniqueIdentifier blockID = GameRegistry.findUniqueIdentifierFor(fluidBlock); - Log.severe("Pre-existing {0} fluid block detected, deferring to {1}:{2}, " + Log.warning("Pre-existing {0} fluid block detected, deferring to {1}:{2}, " + "this may cause issues if the server/client have different mod load orders, " + "recommended that you disable all but one instance of {0} fluid blocks via your configs.", fluid.getName(), blockID.modId, blockID.name); } diff --git a/src/main/java/forestry/plugins/PluginManager.java b/src/main/java/forestry/plugins/PluginManager.java index 4177df2a5..76a42a4de 100644 --- a/src/main/java/forestry/plugins/PluginManager.java +++ b/src/main/java/forestry/plugins/PluginManager.java @@ -81,7 +81,7 @@ public class PluginManager { } private static void registerHandlers(IForestryPlugin plugin) { - Log.fine("Registering Handlers for Plugin: {0}", plugin); + Log.debug("Registering Handlers for Plugin: {}", plugin); IPacketRegistry packetRegistry = plugin.getPacketRegistry(); if (packetRegistry != null) { @@ -199,24 +199,24 @@ public class PluginManager { configurePlugins(forestryPlugins); for (IForestryPlugin plugin : loadedPlugins) { - Log.fine("Setup Start: {0}", plugin); + Log.debug("Setup Start: {0}", plugin); plugin.setupAPI(); plugin.registerItemsAndBlocks(); - Log.fine("Setup Complete: {0}", plugin); + Log.debug("Setup Complete: {0}", plugin); } stage = Stage.SETUP_DISABLED; for (IForestryPlugin plugin : unloadedPlugins) { - Log.fine("Disabled-Setup Start: {0}", plugin); + Log.debug("Disabled-Setup Start: {0}", plugin); plugin.disabledSetupAPI(); - Log.fine("Disabled-Setup Complete: {0}", plugin); + Log.debug("Disabled-Setup Complete: {0}", plugin); } } public static void runPreInit() { stage = Stage.PRE_INIT; for (IForestryPlugin plugin : loadedPlugins) { - Log.fine("Pre-Init Start: {0}", plugin); + Log.debug("Pre-Init Start: {0}", plugin); registerHandlers(plugin); plugin.preInit(); if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.BUILDCRAFT_STATEMENTS)) { @@ -226,26 +226,26 @@ public class PluginManager { plugin.registerBackpackItems(); plugin.registerCrates(); } - Log.fine("Pre-Init Complete: {0}", plugin); + Log.debug("Pre-Init Complete: {0}", plugin); } } public static void runInit() { stage = Stage.INIT; for (IForestryPlugin plugin : loadedPlugins) { - Log.fine("Init Start: {0}", plugin); + Log.debug("Init Start: {0}", plugin); plugin.doInit(); plugin.registerRecipes(); - Log.fine("Init Complete: {0}", plugin); + Log.debug("Init Complete: {0}", plugin); } } public static void runPostInit() { stage = Stage.POST_INIT; for (IForestryPlugin plugin : loadedPlugins) { - Log.fine("Post-Init Start: {0}", plugin); + Log.debug("Post-Init Start: {0}", plugin); plugin.postInit(); - Log.fine("Post-Init Complete: {0}", plugin); + Log.debug("Post-Init Complete: {0}", plugin); } stage = Stage.FINISHED; diff --git a/src/main/java/forestry/plugins/compat/PluginBuildCraftTransport.java b/src/main/java/forestry/plugins/compat/PluginBuildCraftTransport.java index 79a50d548..3e6159c5f 100644 --- a/src/main/java/forestry/plugins/compat/PluginBuildCraftTransport.java +++ b/src/main/java/forestry/plugins/compat/PluginBuildCraftTransport.java @@ -46,7 +46,7 @@ public class PluginBuildCraftTransport extends BlankForestryPlugin { if (pipeWaterproof != null) { RecipeUtil.addShapelessRecipe(new ItemStack(pipeWaterproof), beeswax); } else { - Log.fine("No BuildCraft pipe waterproof found."); + Log.warning("No BuildCraft pipe waterproof found."); } } } diff --git a/src/main/java/forestry/storage/CrateRegistry.java b/src/main/java/forestry/storage/CrateRegistry.java index c43a2676f..1862382e4 100644 --- a/src/main/java/forestry/storage/CrateRegistry.java +++ b/src/main/java/forestry/storage/CrateRegistry.java @@ -30,12 +30,12 @@ public class CrateRegistry implements ICrateRegistry { private static void registerCrate(ItemStack stack, String uid, boolean useOreDict) { if (stack == null || stack.getItem() == null) { - Log.severe("Tried to make a crate without an item"); + Log.warning("Tried to make a crate without an item"); return; } if (uid == null) { - Log.severe("Tried to make a crate without a uid"); + Log.warning("Tried to make a crate without a uid"); return; }