diff --git a/src/main/java/forestry/api/apiculture/DefaultBeeModifier.java b/src/main/java/forestry/api/apiculture/DefaultBeeModifier.java index 41d30e052..70ff9767a 100644 --- a/src/main/java/forestry/api/apiculture/DefaultBeeModifier.java +++ b/src/main/java/forestry/api/apiculture/DefaultBeeModifier.java @@ -5,6 +5,8 @@ ******************************************************************************/ package forestry.api.apiculture; +import javax.annotation.Nullable; + /** * Easily extendable default IBeeModifier. * By itself, this IBeeModifier does nothing. @@ -23,7 +25,7 @@ public class DefaultBeeModifier implements IBeeModifier { } @Override - public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) { + public float getLifespanModifier(IBeeGenome genome, @Nullable IBeeGenome mate, float currentModifier) { return 1.0f; } diff --git a/src/main/java/forestry/api/apiculture/IBee.java b/src/main/java/forestry/api/apiculture/IBee.java index 803671196..44043ddf1 100644 --- a/src/main/java/forestry/api/apiculture/IBee.java +++ b/src/main/java/forestry/api/apiculture/IBee.java @@ -14,6 +14,7 @@ import forestry.api.genetics.IEffectData; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IIndividualLiving; import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; import net.minecraft.world.biome.Biome; /** @@ -72,16 +73,16 @@ public interface IBee extends IIndividualLiving { List getSuitableBiomes(); - ItemStack[] getProduceList(); + NonNullList getProduceList(); - ItemStack[] getSpecialtyList(); + NonNullList getSpecialtyList(); - List produceStacks(IBeeHousing housing); + NonNullList produceStacks(IBeeHousing housing); @Nullable IBee spawnPrincess(IBeeHousing housing); - IBee[] spawnDrones(IBeeHousing housing); + List spawnDrones(IBeeHousing housing); void plantFlowerRandom(IBeeHousing housing); diff --git a/src/main/java/forestry/api/apiculture/IBeeModifier.java b/src/main/java/forestry/api/apiculture/IBeeModifier.java index 8f5fe283a..8b2f694b8 100644 --- a/src/main/java/forestry/api/apiculture/IBeeModifier.java +++ b/src/main/java/forestry/api/apiculture/IBeeModifier.java @@ -5,6 +5,8 @@ ******************************************************************************/ package forestry.api.apiculture; +import javax.annotation.Nullable; + public interface IBeeModifier { /** * @param genome Genome of the bee this modifier is called for. @@ -26,7 +28,7 @@ public interface IBeeModifier { * @param currentModifier Current modifier. * @return Float used to modify the life span of queens. */ - float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier); + float getLifespanModifier(IBeeGenome genome, @Nullable IBeeGenome mate, float currentModifier); /** * @param genome Genome of the bee this modifier is called for. diff --git a/src/main/java/forestry/api/apiculture/IBeeRoot.java b/src/main/java/forestry/api/apiculture/IBeeRoot.java index a09cee641..404e40421 100644 --- a/src/main/java/forestry/api/apiculture/IBeeRoot.java +++ b/src/main/java/forestry/api/apiculture/IBeeRoot.java @@ -24,9 +24,10 @@ public interface IBeeRoot extends ISpeciesRoot { boolean isMember(ItemStack stack); /** - * @return {@link IBee} pattern parsed from the passed stack's nbt data. + * @return {@link IBee} pattern parsed from the passed stack's nbt data. Null if the ItemStack is not a valid member. */ @Override + @Nullable IBee getMember(ItemStack stack); @Override diff --git a/src/main/java/forestry/api/arboriculture/ITree.java b/src/main/java/forestry/api/arboriculture/ITree.java index 4c30c6883..06fa2d7e6 100644 --- a/src/main/java/forestry/api/arboriculture/ITree.java +++ b/src/main/java/forestry/api/arboriculture/ITree.java @@ -36,7 +36,7 @@ public interface ITree extends IIndividual, ITreeGenData { /** * @since Forestry 4.0 */ - ITree[] getSaplings(World world, GameProfile playerProfile, BlockPos pos, float modifier); + ITree[] getSaplings(World world, @Nullable GameProfile playerProfile, BlockPos pos, float modifier); // Products, Chance Map getProducts(); diff --git a/src/main/java/forestry/api/arboriculture/ITreeRoot.java b/src/main/java/forestry/api/arboriculture/ITreeRoot.java index f16cb5511..505dc7cb3 100644 --- a/src/main/java/forestry/api/arboriculture/ITreeRoot.java +++ b/src/main/java/forestry/api/arboriculture/ITreeRoot.java @@ -24,6 +24,7 @@ public interface ITreeRoot extends ISpeciesRootPollinatable { boolean isMember(ItemStack itemstack); @Override + @Nullable ITree getMember(ItemStack itemstack); @Override diff --git a/src/main/java/forestry/api/circuits/ICircuitRegistry.java b/src/main/java/forestry/api/circuits/ICircuitRegistry.java index fd6af5af9..b22e05813 100644 --- a/src/main/java/forestry/api/circuits/ICircuitRegistry.java +++ b/src/main/java/forestry/api/circuits/ICircuitRegistry.java @@ -18,6 +18,7 @@ public interface ICircuitRegistry { void registerCircuit(ICircuit circuit); + @Nullable ICircuit getCircuit(String uid); ICircuitLibrary getCircuitLibrary(World world, String playerName); @@ -27,6 +28,7 @@ public interface ICircuitRegistry { void registerLayout(ICircuitLayout layout); + @Nullable ICircuitLayout getLayout(String uid); ICircuitLayout getDefaultLayout(); diff --git a/src/main/java/forestry/api/genetics/IFlowerProvider.java b/src/main/java/forestry/api/genetics/IFlowerProvider.java index d5b0bb33d..941326767 100644 --- a/src/main/java/forestry/api/genetics/IFlowerProvider.java +++ b/src/main/java/forestry/api/genetics/IFlowerProvider.java @@ -5,9 +5,8 @@ ******************************************************************************/ package forestry.api.genetics; -import java.util.List; - import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -32,5 +31,5 @@ public interface IFlowerProvider { * * @return Array of itemstacks being the (modified or unmodified) produce. */ - List affectProducts(World world, IIndividual individual, BlockPos pos, List products); + NonNullList affectProducts(World world, IIndividual individual, BlockPos pos, NonNullList products); } diff --git a/src/main/java/forestry/api/genetics/ISpeciesRoot.java b/src/main/java/forestry/api/genetics/ISpeciesRoot.java index bc694c1bc..888c32801 100644 --- a/src/main/java/forestry/api/genetics/ISpeciesRoot.java +++ b/src/main/java/forestry/api/genetics/ISpeciesRoot.java @@ -61,6 +61,7 @@ public interface ISpeciesRoot { */ boolean isMember(IIndividual individual); + @Nullable IIndividual getMember(ItemStack stack); IIndividual getMember(NBTTagCompound compound); diff --git a/src/main/java/forestry/api/lepidopterology/IButterflyRoot.java b/src/main/java/forestry/api/lepidopterology/IButterflyRoot.java index d6a73355c..1dd016fe7 100644 --- a/src/main/java/forestry/api/lepidopterology/IButterflyRoot.java +++ b/src/main/java/forestry/api/lepidopterology/IButterflyRoot.java @@ -22,6 +22,7 @@ public interface IButterflyRoot extends ISpeciesRoot { boolean isMember(ItemStack stack); @Override + @Nullable IButterfly getMember(ItemStack stack); @Override diff --git a/src/main/java/forestry/api/mail/IMailAddress.java b/src/main/java/forestry/api/mail/IMailAddress.java index bfe63d89a..d099993d6 100644 --- a/src/main/java/forestry/api/mail/IMailAddress.java +++ b/src/main/java/forestry/api/mail/IMailAddress.java @@ -5,8 +5,6 @@ ******************************************************************************/ package forestry.api.mail; -import javax.annotation.Nullable; - import com.mojang.authlib.GameProfile; import forestry.api.core.INbtWritable; @@ -18,6 +16,5 @@ public interface IMailAddress extends INbtWritable { boolean isValid(); - @Nullable GameProfile getPlayerProfile(); } diff --git a/src/main/java/forestry/apiculture/ArmorApiaristHelper.java b/src/main/java/forestry/apiculture/ArmorApiaristHelper.java index 60e4cbf19..5bda2b802 100644 --- a/src/main/java/forestry/apiculture/ArmorApiaristHelper.java +++ b/src/main/java/forestry/apiculture/ArmorApiaristHelper.java @@ -21,7 +21,7 @@ public class ArmorApiaristHelper implements IArmorApiaristHelper { @Override public boolean isArmorApiarist(ItemStack stack, EntityLivingBase entity, String cause, boolean doProtect) { - if (stack == null) { + if (stack.isEmpty()) { return false; } diff --git a/src/main/java/forestry/apiculture/BeeHousingModifier.java b/src/main/java/forestry/apiculture/BeeHousingModifier.java index ede25600b..695a82b48 100644 --- a/src/main/java/forestry/apiculture/BeeHousingModifier.java +++ b/src/main/java/forestry/apiculture/BeeHousingModifier.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.apiculture; +import javax.annotation.Nullable; + import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeeModifier; @@ -40,7 +42,7 @@ public class BeeHousingModifier implements IBeeModifier { } @Override - public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, final float currentModifier) { + public float getLifespanModifier(IBeeGenome genome, @Nullable IBeeGenome mate, final float currentModifier) { float modifierValue = 1.0f; for (IBeeModifier modifier : beeHousing.getBeeModifiers()) { modifierValue *= modifier.getLifespanModifier(genome, mate, modifierValue * currentModifier); diff --git a/src/main/java/forestry/apiculture/BeehouseBeeModifier.java b/src/main/java/forestry/apiculture/BeehouseBeeModifier.java index 03d554c98..de04e6019 100644 --- a/src/main/java/forestry/apiculture/BeehouseBeeModifier.java +++ b/src/main/java/forestry/apiculture/BeehouseBeeModifier.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.apiculture; +import javax.annotation.Nullable; + import forestry.api.apiculture.DefaultBeeModifier; import forestry.api.apiculture.IBeeGenome; @@ -25,7 +27,7 @@ public class BeehouseBeeModifier extends DefaultBeeModifier { } @Override - public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) { + public float getLifespanModifier(IBeeGenome genome, @Nullable IBeeGenome mate, float currentModifier) { return 3.0f; } diff --git a/src/main/java/forestry/apiculture/BeekeepingLogic.java b/src/main/java/forestry/apiculture/BeekeepingLogic.java index 0572df4c9..a6f0776a4 100644 --- a/src/main/java/forestry/apiculture/BeekeepingLogic.java +++ b/src/main/java/forestry/apiculture/BeekeepingLogic.java @@ -63,7 +63,6 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable { private int beeProgressMax; private int queenWorkCycleThrottle; - @Nullable private IEffectData effectData[] = new IEffectData[2]; private final Stack spawn = new Stack<>(); @@ -429,7 +428,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable { } // Drones - IBee[] drones = queen.spawnDrones(beeHousing); + List drones = queen.spawnDrones(beeHousing); for (IBee drone : drones) { ItemStack droneStack = BeeManager.beeRoot.getMemberStack(drone, EnumBeeType.DRONE); breedingTracker.registerDrone(drone); @@ -488,10 +487,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable { @Override public boolean canDoBeeFX() { - if (Proxies.common.getClientInstance().isGamePaused()) { - return false; - } - return active; + return !Proxies.common.getClientInstance().isGamePaused() && active; } @Override diff --git a/src/main/java/forestry/apiculture/compat/ApicultureJeiPlugin.java b/src/main/java/forestry/apiculture/compat/ApicultureJeiPlugin.java index c9e2c8579..8866caf77 100644 --- a/src/main/java/forestry/apiculture/compat/ApicultureJeiPlugin.java +++ b/src/main/java/forestry/apiculture/compat/ApicultureJeiPlugin.java @@ -1,5 +1,6 @@ package forestry.apiculture.compat; +import com.google.common.base.Preconditions; import forestry.api.apiculture.BeeManager; import forestry.api.genetics.IAlleleSpecies; import forestry.apiculture.PluginApiculture; @@ -16,6 +17,7 @@ public class ApicultureJeiPlugin extends BlankModPlugin { @Override public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) { ItemRegistryApiculture items = PluginApiculture.items; + Preconditions.checkNotNull(items); ISubtypeRegistry.ISubtypeInterpreter beeSubtypeInterpreter = itemStack -> { IAlleleSpecies species = Genome.getSpeciesDirectly(BeeManager.beeRoot, itemStack); @@ -30,6 +32,7 @@ public class ApicultureJeiPlugin extends BlankModPlugin { @Override public void register(IModRegistry registry) { ItemRegistryApiculture items = PluginApiculture.items; + Preconditions.checkNotNull(items); JeiUtil.addDescription(registry, "frames", items.frameImpregnated, diff --git a/src/main/java/forestry/apiculture/entities/EntityMinecartApiary.java b/src/main/java/forestry/apiculture/entities/EntityMinecartApiary.java index 20ed47c72..24923c3c2 100644 --- a/src/main/java/forestry/apiculture/entities/EntityMinecartApiary.java +++ b/src/main/java/forestry/apiculture/entities/EntityMinecartApiary.java @@ -27,7 +27,6 @@ import forestry.apiculture.gui.ContainerMinecartBeehouse; import forestry.apiculture.gui.GuiBeeHousing; import forestry.apiculture.inventory.IApiaryInventory; import forestry.apiculture.inventory.InventoryApiary; -import forestry.core.config.Config; import forestry.core.inventory.IInventoryAdapter; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -51,8 +50,8 @@ public class EntityMinecartApiary extends EntityMinecartBeeHousingBase implement } @Override - public List getHints() { - return Config.hints.get("apiary"); + public String getHintKey() { + return "apiary"; } @Override diff --git a/src/main/java/forestry/apiculture/entities/EntityMinecartBeeHousingBase.java b/src/main/java/forestry/apiculture/entities/EntityMinecartBeeHousingBase.java index ae844f10e..54312246e 100644 --- a/src/main/java/forestry/apiculture/entities/EntityMinecartBeeHousingBase.java +++ b/src/main/java/forestry/apiculture/entities/EntityMinecartBeeHousingBase.java @@ -22,7 +22,7 @@ import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorLogic; -import forestry.apiculture.gui.IGuiBeeHousingInventory; +import forestry.apiculture.gui.IGuiBeeHousingDelegate; import forestry.apiculture.network.packets.PacketBeeLogicEntityRequest; import forestry.apiculture.tiles.TileBeeHousingBase; import forestry.core.entities.EntityMinecartContainerForestry; @@ -45,7 +45,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContainerForestry implements IBeeHousing, IOwnedTile, IGuiBeeHousingInventory, IClimatised, IStreamableGui { +public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContainerForestry implements IBeeHousing, IOwnedTile, IGuiBeeHousingDelegate, IClimatised, IStreamableGui { private static final DataParameter> OWNER = EntityDataManager.createKey(EntityMinecart.class, GameProfileDataSerializer.INSTANCE); private static final Random random = new Random(); diff --git a/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java b/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java index d1d1ece1d..8cdf04cb6 100644 --- a/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java +++ b/src/main/java/forestry/apiculture/entities/EntityMinecartBeehouse.java @@ -11,7 +11,6 @@ package forestry.apiculture.entities; import java.util.Collections; -import java.util.List; import forestry.api.apiculture.DefaultBeeListener; import forestry.api.apiculture.IBeeHousingInventory; @@ -22,7 +21,6 @@ import forestry.apiculture.InventoryBeeHousing; import forestry.apiculture.PluginApiculture; import forestry.apiculture.gui.ContainerMinecartBeehouse; import forestry.apiculture.gui.GuiBeeHousing; -import forestry.core.config.Config; import forestry.core.inventory.IInventoryAdapter; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -46,8 +44,8 @@ public class EntityMinecartBeehouse extends EntityMinecartBeeHousingBase { } @Override - public List getHints() { - return Config.hints.get("bee.house"); + public String getHintKey() { + return "bee.house"; } @Override diff --git a/src/main/java/forestry/apiculture/flowers/FlowerProvider.java b/src/main/java/forestry/apiculture/flowers/FlowerProvider.java index 32c667778..a1f390660 100644 --- a/src/main/java/forestry/apiculture/flowers/FlowerProvider.java +++ b/src/main/java/forestry/apiculture/flowers/FlowerProvider.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.apiculture.flowers; -import java.util.List; - import forestry.api.apiculture.FlowerManager; import forestry.api.genetics.ICheckPollinatable; import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.core.utils.Translator; import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.EnumPlantType; @@ -58,7 +57,7 @@ public class FlowerProvider implements IFlowerProvider { } @Override - public List affectProducts(World world, IIndividual individual, BlockPos pos, List products) { + public NonNullList affectProducts(World world, IIndividual individual, BlockPos pos, NonNullList products) { return products; } diff --git a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java index 7a1ecbd69..7bf68600c 100644 --- a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java +++ b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java @@ -18,6 +18,7 @@ import java.util.Random; import java.util.Set; import java.util.TreeMap; +import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.HashMultimap; import forestry.api.apiculture.BeeManager; @@ -31,7 +32,6 @@ import forestry.api.genetics.IFlowerGrowthHelper; import forestry.api.genetics.IFlowerGrowthRule; import forestry.api.genetics.IFlowerRegistry; import forestry.api.genetics.IIndividual; -import forestry.core.utils.Log; import forestry.core.utils.VectUtil; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -95,9 +95,9 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe @Override public void registerPlantableFlower(IBlockState blockState, double weight, String... flowerTypes) { - if (blockState == null) { - return; - } + Preconditions.checkNotNull(blockState); + Preconditions.checkArgument(blockState.getBlock() != Blocks.AIR, "Tried to register AIR as a flower. Bad idea."); + if (weight <= 0.0) { weight = 0.0; } @@ -105,16 +105,10 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe weight = 1.0; } - if (blockState.getBlock() == Blocks.AIR) { - Log.error("Tried to register AIR as a flower. Bad idea."); - } - Flower newFlower = new Flower(blockState, weight); for (String flowerType : flowerTypes) { - if (flowerType == null) { - throw new NullPointerException("Tried to register flower with null type. " + blockState); - } + Preconditions.checkNotNull(flowerType, "Tried to register flower with null type. " + blockState); Set flowers = this.plantableFlowers.get(flowerType); flowers.add(newFlower); @@ -219,9 +213,7 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe @Override public void registerGrowthRule(IFlowerGrowthRule rule, String... flowerTypes) { - if (rule == null) { - return; - } + Preconditions.checkNotNull(rule); for (String flowerType : flowerTypes) { this.growthRules.get(flowerType).add(rule); diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index dc97a69ef..ef163640c 100644 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -12,6 +12,7 @@ package forestry.apiculture.genetics; import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -58,6 +59,7 @@ import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3i; import net.minecraft.util.text.TextFormatting; @@ -417,8 +419,8 @@ public class Bee extends IndividualLiving implements IBee { // / PRODUCTION @Override - public ItemStack[] getProduceList() { - ArrayList products = new ArrayList<>(); + public NonNullList getProduceList() { + NonNullList products = NonNullList.create(); IAlleleBeeSpecies primary = genome.getPrimary(); IAlleleBeeSpecies secondary = genome.getSecondary(); @@ -443,21 +445,25 @@ public class Bee extends IndividualLiving implements IBee { } - return products.toArray(new ItemStack[products.size()]); + return products; } @Override - public ItemStack[] getSpecialtyList() { + public NonNullList getSpecialtyList() { Set specialties = genome.getPrimary().getSpecialtyChances().keySet(); - return specialties.toArray(new ItemStack[specialties.size()]); + NonNullList specialtyList = NonNullList.create(); + for (ItemStack specialty : specialties) { + specialtyList.add(specialty); + } + return specialtyList; } @Override - public List produceStacks(IBeeHousing housing) { + public NonNullList produceStacks(IBeeHousing housing) { World world = housing.getWorldObj(); IBeekeepingMode mode = BeeManager.beeRoot.getBeekeepingMode(world); - List products = new ArrayList<>(); + NonNullList products = NonNullList.create(); IAlleleBeeSpecies primary = genome.getPrimary(); IAlleleBeeSpecies secondary = genome.getSecondary(); @@ -518,14 +524,13 @@ public class Bee extends IndividualLiving implements IBee { } @Override - @Nullable - public IBee[] spawnDrones(IBeeHousing housing) { + public List spawnDrones(IBeeHousing housing) { World world = housing.getWorldObj(); // We need a mated queen to produce offspring. if (mate == null) { - return new IBee[]{}; + return Collections.emptyList(); } List bees = new ArrayList<>(); @@ -543,11 +548,7 @@ public class Bee extends IndividualLiving implements IBee { bees.add(offspring); } - if (!bees.isEmpty()) { - return bees.toArray(new IBee[bees.size()]); - } else { - return null; - } + return bees; } private IBee createOffspring(IBeeHousing housing, IBeeGenome mate, int generation) { diff --git a/src/main/java/forestry/apiculture/genetics/BeeAlyzerPlugin.java b/src/main/java/forestry/apiculture/genetics/BeeAlyzerPlugin.java index c2b1e6178..2cb205ba8 100644 --- a/src/main/java/forestry/apiculture/genetics/BeeAlyzerPlugin.java +++ b/src/main/java/forestry/apiculture/genetics/BeeAlyzerPlugin.java @@ -38,9 +38,7 @@ public class BeeAlyzerPlugin implements IAlyzerPlugin { PluginApiculture.items.beeDroneGE.addCreativeItems(beeList, false); for (ItemStack beeStack : beeList) { IAlleleBeeSpecies species = BeeGenome.getSpecies(beeStack); - if (species != null) { - iconStacks.put(species.getUID(), beeStack); - } + iconStacks.put(species.getUID(), beeStack); } } @@ -50,9 +48,6 @@ public class BeeAlyzerPlugin implements IAlyzerPlugin { if (gui instanceof GuiAlyzer) { GuiAlyzer guiAlyzer = (GuiAlyzer) gui; IBee bee = BeeManager.beeRoot.getMember(itemStack); - if (bee == null) { - return; - } EnumBeeType type = BeeManager.beeRoot.getType(itemStack); if (type == null) { return; @@ -108,9 +103,6 @@ public class BeeAlyzerPlugin implements IAlyzerPlugin { if (gui instanceof GuiAlyzer) { GuiAlyzer guiAlyzer = (GuiAlyzer) gui; IBee bee = BeeManager.beeRoot.getMember(itemStack); - if (bee == null) { - return; - } EnumBeeType type = BeeManager.beeRoot.getType(itemStack); TextLayoutHelper textLayout = guiAlyzer.getTextLayout(); @@ -215,9 +207,6 @@ public class BeeAlyzerPlugin implements IAlyzerPlugin { if (gui instanceof GuiAlyzer) { GuiAlyzer guiAlyzer = (GuiAlyzer) gui; IBee bee = BeeManager.beeRoot.getMember(itemStack); - if (bee == null) { - return; - } TextLayoutHelper textLayout = guiAlyzer.getTextLayout(); WidgetManager widgetManager = guiAlyzer.getWidgetManager(); diff --git a/src/main/java/forestry/apiculture/genetics/BeeFactory.java b/src/main/java/forestry/apiculture/genetics/BeeFactory.java index 520b3aee9..421cecfcb 100644 --- a/src/main/java/forestry/apiculture/genetics/BeeFactory.java +++ b/src/main/java/forestry/apiculture/genetics/BeeFactory.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.apiculture.genetics; +import com.google.common.base.Preconditions; import forestry.api.apiculture.IAlleleBeeSpeciesBuilder; import forestry.api.apiculture.IBeeFactory; import forestry.api.genetics.IClassification; @@ -17,7 +18,23 @@ import forestry.apiculture.genetics.alleles.AlleleBeeSpecies; public class BeeFactory implements IBeeFactory { @Override - public IAlleleBeeSpeciesBuilder createSpecies(String uid, boolean dominant, String authority, String unlocalizedName, String unlocalizedDescription, IClassification branch, String binomial, int primaryColor, int secondaryColor) { + public IAlleleBeeSpeciesBuilder createSpecies( + String uid, + boolean dominant, + String authority, + String unlocalizedName, + String unlocalizedDescription, + IClassification branch, + String binomial, + int primaryColor, + int secondaryColor) { + Preconditions.checkNotNull(uid); + Preconditions.checkNotNull(authority); + Preconditions.checkNotNull(unlocalizedName); + Preconditions.checkNotNull(unlocalizedDescription); + Preconditions.checkNotNull(branch); + Preconditions.checkNotNull(binomial); + return new AlleleBeeSpecies(uid, unlocalizedName, authority, unlocalizedDescription, dominant, branch, binomial, primaryColor, secondaryColor); } diff --git a/src/main/java/forestry/apiculture/genetics/BeeRoot.java b/src/main/java/forestry/apiculture/genetics/BeeRoot.java index 7daeac74e..2d3ef7b9e 100644 --- a/src/main/java/forestry/apiculture/genetics/BeeRoot.java +++ b/src/main/java/forestry/apiculture/genetics/BeeRoot.java @@ -187,9 +187,11 @@ public class BeeRoot extends SpeciesRoot implements IBeeRoot { } @Override + @Nullable public IBee getMember(ItemStack stack) { - Preconditions.checkArgument(isMember(stack), "ItemStack must be a bee."); - Preconditions.checkArgument(stack.getTagCompound() != null, "ItemStack must have a tag compound."); + if (!isMember(stack) || stack.getTagCompound() == null) { + return null; + } return new Bee(stack.getTagCompound()); } diff --git a/src/main/java/forestry/apiculture/genetics/BeekeepingMode.java b/src/main/java/forestry/apiculture/genetics/BeekeepingMode.java index 0b332ea14..61b41fb25 100755 --- a/src/main/java/forestry/apiculture/genetics/BeekeepingMode.java +++ b/src/main/java/forestry/apiculture/genetics/BeekeepingMode.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.apiculture.genetics; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -151,7 +152,7 @@ public class BeekeepingMode implements IBeekeepingMode { } @Override - public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) { + public float getLifespanModifier(IBeeGenome genome, @Nullable IBeeGenome mate, float currentModifier) { return this.lifespanModifier; } diff --git a/src/main/java/forestry/apiculture/genetics/DefaultBeeModelProvider.java b/src/main/java/forestry/apiculture/genetics/DefaultBeeModelProvider.java index a87e39aa3..fbb833a85 100644 --- a/src/main/java/forestry/apiculture/genetics/DefaultBeeModelProvider.java +++ b/src/main/java/forestry/apiculture/genetics/DefaultBeeModelProvider.java @@ -11,6 +11,7 @@ package forestry.apiculture.genetics; import javax.annotation.Nullable; +import java.util.EnumMap; import java.util.Locale; import forestry.api.apiculture.EnumBeeType; @@ -34,7 +35,7 @@ public class DefaultBeeModelProvider implements IBeeModelProvider { @SideOnly(Side.CLIENT) @Nullable - private static ModelResourceLocation[] models; + private static EnumMap models; @Override @SideOnly(Side.CLIENT) @@ -44,16 +45,16 @@ public class DefaultBeeModelProvider implements IBeeModelProvider { String beeTypeNameBase = beeIconDir + beeType.toString().toLowerCase(Locale.ENGLISH); if (models == null) { - models = new ModelResourceLocation[EnumBeeType.values().length]; + models = new EnumMap<>(EnumBeeType.class); } - models[beeType.ordinal()] = manager.getModelLocation(beeTypeNameBase); + models.put(beeType, manager.getModelLocation(beeTypeNameBase)); ModelBakery.registerItemVariants(item, new ResourceLocation("forestry:" + beeTypeNameBase)); } @Override @SideOnly(Side.CLIENT) public ModelResourceLocation getModel(EnumBeeType type) { - return models[type.ordinal()]; + return models.get(type); } } diff --git a/src/main/java/forestry/apiculture/genetics/alleles/AlleleBeeSpecies.java b/src/main/java/forestry/apiculture/genetics/alleles/AlleleBeeSpecies.java index 8e98c437d..a98b80416 100644 --- a/src/main/java/forestry/apiculture/genetics/alleles/AlleleBeeSpecies.java +++ b/src/main/java/forestry/apiculture/genetics/alleles/AlleleBeeSpecies.java @@ -122,7 +122,7 @@ public class AlleleBeeSpecies extends AlleleSpecies implements IAlleleBeeSpecies /* RESEARCH */ @Override public float getResearchSuitability(ItemStack itemstack) { - if (itemstack == null) { + if (itemstack.isEmpty()) { return 0f; } diff --git a/src/main/java/forestry/apiculture/gui/GuiAlveary.java b/src/main/java/forestry/apiculture/gui/GuiAlveary.java index 821b2dc86..5528e17a9 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlveary.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlveary.java @@ -17,19 +17,20 @@ import forestry.core.gui.GuiForestryTitled; import forestry.core.render.EnumTankLevel; import net.minecraft.entity.player.InventoryPlayer; -public class GuiAlveary extends GuiForestryTitled { +public class GuiAlveary extends GuiForestryTitled { + private final TileAlveary tile; public GuiAlveary(InventoryPlayer inventory, TileAlveary tile) { super(Constants.TEXTURE_PATH_GUI + "/alveary.png", new ContainerAlveary(inventory, tile), tile); - - ySize = 190; + this.tile = tile; + this.ySize = 190; } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - IAlvearyControllerInternal alvearyController = inventory.getMultiblockLogic().getController(); + IAlvearyControllerInternal alvearyController = tile.getMultiblockLogic().getController(); drawHealthMeter(guiLeft + 20, guiTop + 37, alvearyController.getHealthScaled(46), EnumTankLevel.rateTankLevel(alvearyController.getHealthScaled(100))); } @@ -39,4 +40,12 @@ public class GuiAlveary extends GuiForestryTitled this.drawTexturedModalRect(x, y + 46 - height, i, k + 46 - height, 4, height); } + + @Override + protected void addLedgers() { + addErrorLedger(tile); + addClimateLedger(tile); + addHintLedger("apiary"); + addOwnerLedger(tile); + } } diff --git a/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java index 4644e4f0e..7d132e13d 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java @@ -16,12 +16,18 @@ import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; import net.minecraft.entity.player.InventoryPlayer; -public class GuiAlvearyHygroregulator extends GuiForestryTitled { +public class GuiAlvearyHygroregulator extends GuiForestryTitled { + private final TileAlvearyHygroregulator tile; public GuiAlvearyHygroregulator(InventoryPlayer inventory, TileAlvearyHygroregulator tile) { super(Constants.TEXTURE_PATH_GUI + "/hygroregulator.png", new ContainerAlvearyHygroregulator(inventory, tile), tile); + this.tile = tile; widgetManager.add(new TankWidget(this.widgetManager, 104, 17, 0)); } + @Override + protected void addLedgers() { + addErrorLedger(tile); + } } diff --git a/src/main/java/forestry/apiculture/gui/GuiAlvearySieve.java b/src/main/java/forestry/apiculture/gui/GuiAlvearySieve.java index 0b7ec13c5..10a0e212a 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlvearySieve.java @@ -15,10 +15,16 @@ import forestry.core.config.Constants; import forestry.core.gui.GuiForestryTitled; import net.minecraft.entity.player.InventoryPlayer; -public class GuiAlvearySieve extends GuiForestryTitled { +public class GuiAlvearySieve extends GuiForestryTitled { + private final TileAlvearySieve tile; public GuiAlvearySieve(InventoryPlayer inventory, TileAlvearySieve tile) { super(Constants.TEXTURE_PATH_GUI + "/sieve.png", new ContainerAlvearySieve(inventory, tile), tile); + this.tile = tile; } + @Override + protected void addLedgers() { + addErrorLedger(tile); + } } diff --git a/src/main/java/forestry/apiculture/gui/GuiAlvearySwarmer.java b/src/main/java/forestry/apiculture/gui/GuiAlvearySwarmer.java index 5a1f1844f..c8baeafce 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlvearySwarmer.java @@ -15,10 +15,16 @@ import forestry.core.config.Constants; import forestry.core.gui.GuiForestryTitled; import net.minecraft.entity.player.InventoryPlayer; -public class GuiAlvearySwarmer extends GuiForestryTitled { +public class GuiAlvearySwarmer extends GuiForestryTitled { + private final TileAlvearySwarmer tile; public GuiAlvearySwarmer(InventoryPlayer inventory, TileAlvearySwarmer tile) { super(Constants.TEXTURE_PATH_GUI + "/swarmer.png", new ContainerAlvearySwarmer(inventory, tile), tile); + this.tile = tile; } + @Override + protected void addLedgers() { + addErrorLedger(tile); + } } diff --git a/src/main/java/forestry/apiculture/gui/GuiBeeHousing.java b/src/main/java/forestry/apiculture/gui/GuiBeeHousing.java index 81965678d..8a12282d6 100644 --- a/src/main/java/forestry/apiculture/gui/GuiBeeHousing.java +++ b/src/main/java/forestry/apiculture/gui/GuiBeeHousing.java @@ -15,7 +15,8 @@ import forestry.core.gui.GuiForestryTitled; import forestry.core.render.EnumTankLevel; import net.minecraft.inventory.Container; -public class GuiBeeHousing extends GuiForestryTitled { +public class GuiBeeHousing extends GuiForestryTitled { + private final IGuiBeeHousingDelegate delegate; public enum Icon { APIARY("/apiary.png"), @@ -28,16 +29,17 @@ public class GuiBeeHousing extends G } } - public GuiBeeHousing(IGuiBeeHousingInventory tile, C container, Icon icon) { - super(Constants.TEXTURE_PATH_GUI + icon.path, container, tile); - ySize = 190; + public GuiBeeHousing(IGuiBeeHousingDelegate delegate, C container, Icon icon) { + super(Constants.TEXTURE_PATH_GUI + icon.path, container, delegate); + this.delegate = delegate; + this.ySize = 190; } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - drawHealthMeter(guiLeft + 20, guiTop + 37, inventory.getHealthScaled(46), EnumTankLevel.rateTankLevel(inventory.getHealthScaled(100))); + drawHealthMeter(guiLeft + 20, guiTop + 37, delegate.getHealthScaled(46), EnumTankLevel.rateTankLevel(delegate.getHealthScaled(100))); } private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) { @@ -47,4 +49,11 @@ public class GuiBeeHousing extends G this.drawTexturedModalRect(x, y + 46 - height, i, k + 46 - height, 4, height); } + @Override + protected void addLedgers() { + addErrorLedger(delegate); + addClimateLedger(delegate); + addHintLedger(delegate.getHintKey()); + addOwnerLedger(delegate); + } } diff --git a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java index fe3c2a686..97eeb4a81 100755 --- a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java @@ -28,7 +28,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.biome.Biome; import net.minecraftforge.common.BiomeDictionary; -public class GuiHabitatLocator extends GuiForestry { +public class GuiHabitatLocator extends GuiForestry { private static final LinkedListMultimap habitats = LinkedListMultimap.create(); static { @@ -46,14 +46,16 @@ public class GuiHabitatLocator extends GuiForestry habitatSlots = new ArrayList<>(habitats.size()); private int startX; private int startY; - public GuiHabitatLocator(EntityPlayer player, ItemInventoryHabitatLocator item) { - super(Constants.TEXTURE_PATH_GUI + "/biomefinder.png", new ContainerHabitatLocator(player, item), item); + public GuiHabitatLocator(EntityPlayer player, ItemInventoryHabitatLocator itemInventory) { + super(Constants.TEXTURE_PATH_GUI + "/biomefinder.png", new ContainerHabitatLocator(player, itemInventory)); + this.itemInventory = itemInventory; xSize = 176; ySize = 184; @@ -85,7 +87,7 @@ public class GuiHabitatLocator extends GuiForestry activeBiomeTypes = new HashSet<>(); - for (Biome biome : inventory.getBiomesToSearch()) { + for (Biome biome : itemInventory.getBiomesToSearch()) { Set biomeTypes = BiomeDictionary.getTypes(biome); activeBiomeTypes.addAll(biomeTypes); } @@ -107,4 +109,10 @@ public class GuiHabitatLocator extends GuiForestry { - +public class GuiImprinter extends GuiForestry { + private final ItemInventoryImprinter itemInventory; private int startX; private int startY; private final Map iconStacks = new HashMap<>(); - public GuiImprinter(InventoryPlayer inventoryplayer, ItemInventoryImprinter inventory) { - super(Constants.TEXTURE_PATH_GUI + "/imprinter.png", new ContainerImprinter(inventoryplayer, inventory), inventory); + public GuiImprinter(InventoryPlayer inventoryplayer, ItemInventoryImprinter itemInventory) { + super(Constants.TEXTURE_PATH_GUI + "/imprinter.png", new ContainerImprinter(inventoryplayer, itemInventory)); - xSize = 176; - ySize = 185; + this.itemInventory = itemInventory; + this.xSize = 176; + this.ySize = 185; NonNullList beeList = NonNullList.create(); PluginApiculture.items.beeDroneGE.addCreativeItems(beeList, false); @@ -59,11 +60,11 @@ public class GuiImprinter extends GuiForestry getHints() { - return Config.hints.get("habitat.locator"); - } - /* IErrorSource */ @Override public ImmutableSet getErrorStates() { diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlveary.java b/src/main/java/forestry/apiculture/multiblock/TileAlveary.java index 26ef24247..5085724d7 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlveary.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlveary.java @@ -11,7 +11,6 @@ package forestry.apiculture.multiblock; import java.io.IOException; -import java.util.List; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeeHousingInventory; @@ -26,8 +25,6 @@ import forestry.api.multiblock.IMultiblockController; import forestry.apiculture.blocks.BlockAlvearyType; import forestry.apiculture.gui.ContainerAlveary; import forestry.apiculture.gui.GuiAlveary; -import forestry.core.config.Config; -import forestry.core.gui.IHintSource; import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.MultiblockTileEntityForestry; import forestry.core.network.IStreamableGui; @@ -43,7 +40,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -public abstract class TileAlveary extends MultiblockTileEntityForestry implements IBeeHousing, IAlvearyComponent, IOwnedTile, IStreamableGui, ITitled, IClimatised, IHintSource { +public abstract class TileAlveary extends MultiblockTileEntityForestry implements IBeeHousing, IAlvearyComponent, IOwnedTile, IStreamableGui, ITitled, IClimatised { private final String unlocalizedTitle; protected TileAlveary() { @@ -157,12 +154,6 @@ public abstract class TileAlveary extends MultiblockTileEntityForestry getHints() { - return Config.hints.get("apiary"); - } - /* IClimatised */ @Override public float getExactTemperature() { diff --git a/src/main/java/forestry/apiculture/multiblock/TileAlvearySieve.java b/src/main/java/forestry/apiculture/multiblock/TileAlvearySieve.java index 260041fe7..1e7b50293 100644 --- a/src/main/java/forestry/apiculture/multiblock/TileAlvearySieve.java +++ b/src/main/java/forestry/apiculture/multiblock/TileAlvearySieve.java @@ -74,10 +74,10 @@ public class TileAlvearySieve extends TileAlveary implements IAlvearyComponent.B return false; } - ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(pollen.getClass()); + ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(pollen); ItemStack pollenStack = speciesRoot.getMemberStack(pollen, EnumGermlingType.POLLEN); - if (pollenStack != null) { + if (!pollenStack.isEmpty()) { inventory.storePollenStack(pollenStack); return true; } diff --git a/src/main/java/forestry/apiculture/tiles/TileBeeHousingBase.java b/src/main/java/forestry/apiculture/tiles/TileBeeHousingBase.java index f8737f035..844bb63a3 100644 --- a/src/main/java/forestry/apiculture/tiles/TileBeeHousingBase.java +++ b/src/main/java/forestry/apiculture/tiles/TileBeeHousingBase.java @@ -20,7 +20,7 @@ import forestry.api.climate.IClimatePosition; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.ForestryAPI; -import forestry.apiculture.gui.IGuiBeeHousingInventory; +import forestry.apiculture.gui.IGuiBeeHousingDelegate; import forestry.core.network.IStreamableGui; import forestry.core.network.PacketBufferForestry; import forestry.core.owner.IOwnedTile; @@ -35,7 +35,8 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing, IOwnedTile, IClimatised, IGuiBeeHousingInventory, IStreamableGui { +public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing, IOwnedTile, IClimatised, IGuiBeeHousingDelegate, IStreamableGui { + private final String hintKey; private final OwnerHandler ownerHandler = new OwnerHandler(); private final IBeekeepingLogic beeLogic; @@ -43,10 +44,15 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing private int breedingProgressPercent = 0; protected TileBeeHousingBase(String hintKey) { - super(hintKey); + this.hintKey = hintKey; this.beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this); } + @Override + public String getHintKey() { + return hintKey; + } + @Override public IBeekeepingLogic getBeekeepingLogic() { return beeLogic; diff --git a/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java b/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java index c4f519356..576e26d98 100644 --- a/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java +++ b/src/main/java/forestry/apiculture/worldgen/VillageApiaristHouse.java @@ -65,46 +65,18 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { private static final Random random = new Random(); + private final Materials materials; private int averageGroundLevel = -1; - private IBlockState planks; - private IBlockState slabs; - private IBlockState logs; - private IBlockState stairs; - private IBlockState fence; - private IBlockState door; - private IBlockState fenceGate; @SuppressWarnings("unused") public VillageApiaristHouse() { - createBuildingBlocks(random); + this.materials = new Materials(random); } public VillageApiaristHouse(StructureVillagePieces.Start startPiece, int componentType, Random random, StructureBoundingBox boundingBox, EnumFacing facing) { super(startPiece, componentType, random, boundingBox, facing); - createBuildingBlocks(random); - } - - private void createBuildingBlocks(Random random) { - IWoodType woodType; - boolean fireproof; - - if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) { - woodType = EnumForestryWoodType.getRandom(random); - fireproof = random.nextInt(4) == 0; - } else { - woodType = EnumVanillaWoodType.getRandom(random); - fireproof = false; - } - - IWoodAccess woodAccess = TreeManager.woodAccess; - this.logs = woodAccess.getBlock(woodType, WoodBlockKind.LOG, fireproof).withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X); - this.planks = woodAccess.getBlock(woodType, WoodBlockKind.PLANKS, fireproof); - this.slabs = woodAccess.getBlock(woodType, WoodBlockKind.SLAB, fireproof); - this.stairs = woodAccess.getBlock(woodType, WoodBlockKind.STAIRS, fireproof); - this.fence = woodAccess.getBlock(woodType, WoodBlockKind.FENCE, fireproof); - this.door = woodAccess.getBlock(woodType, WoodBlockKind.DOOR, false); - this.fenceGate = woodAccess.getBlock(woodType, WoodBlockKind.FENCE_GATE, fireproof); + this.materials = new Materials(random); } @Nullable @@ -136,13 +108,13 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { buildGarden(world, structBoundingBox); // Garden fence - fillWithBlocks(world, structBoundingBox, 1, 1, 6, 1, 1, 10, fence, fence, false); - fillWithBlocks(world, structBoundingBox, 8, 1, 6, 8, 1, 10, fence, fence, false); - fillWithBlocks(world, structBoundingBox, 2, 1, 10, 7, 1, 10, fence, fence, false); + fillWithBlocks(world, structBoundingBox, 1, 1, 6, 1, 1, 10, materials.fence, materials.fence, false); + fillWithBlocks(world, structBoundingBox, 8, 1, 6, 8, 1, 10, materials.fence, materials.fence, false); + fillWithBlocks(world, structBoundingBox, 2, 1, 10, 7, 1, 10, materials.fence, materials.fence, false); - setBlockState(world, fenceGate.withProperty(BlockHorizontal.FACING, EnumFacing.EAST), 8, 1, 8, structBoundingBox); - setBlockState(world, fenceGate.withProperty(BlockHorizontal.FACING, EnumFacing.EAST), 1, 1, 8, structBoundingBox); - setBlockState(world, fenceGate.withProperty(BlockHorizontal.FACING, EnumFacing.NORTH), 4, 1, 10, structBoundingBox); + setBlockState(world, materials.fenceGate.withProperty(BlockHorizontal.FACING, EnumFacing.EAST), 8, 1, 8, structBoundingBox); + setBlockState(world, materials.fenceGate.withProperty(BlockHorizontal.FACING, EnumFacing.EAST), 1, 1, 8, structBoundingBox); + setBlockState(world, materials.fenceGate.withProperty(BlockHorizontal.FACING, EnumFacing.NORTH), 4, 1, 10, structBoundingBox); // Flowers plantFlowerGarden(world, structBoundingBox, 2, 1, 5, 7, 1, 9); @@ -151,10 +123,10 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { buildApiaries(world, structBoundingBox); // Floor - IBlockState slabFloor = slabs.withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.BOTTOM); + IBlockState slabFloor = materials.slabs.withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.BOTTOM); fillWithBlocks(world, structBoundingBox, 2, 0, 1, 6, 0, 4, slabFloor, slabFloor, false); - fillWithBlocks(world, structBoundingBox, 1, 0, 1, 1, 0, 4, planks, planks, false); - fillWithBlocks(world, structBoundingBox, 7, 0, 1, 7, 0, 4, planks, planks, false); + fillWithBlocks(world, structBoundingBox, 1, 0, 1, 1, 0, 4, materials.planks, materials.planks, false); + fillWithBlocks(world, structBoundingBox, 7, 0, 1, 7, 0, 4, materials.planks, materials.planks, false); IBlockState cobblestoneState = Blocks.COBBLESTONE.getDefaultState(); fillWithBlocks(world, structBoundingBox, 0, 0, 0, 0, 2, 5, cobblestoneState, cobblestoneState, false); @@ -162,33 +134,33 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { fillWithBlocks(world, structBoundingBox, 1, 0, 0, 7, 1, 0, cobblestoneState, cobblestoneState, false); fillWithBlocks(world, structBoundingBox, 1, 0, 5, 7, 1, 5, cobblestoneState, cobblestoneState, false); - fillWithBlocks(world, structBoundingBox, 0, 3, 0, 0, 3, 5, planks, planks, false); - fillWithBlocks(world, structBoundingBox, 8, 3, 0, 8, 3, 5, planks, planks, false); - fillWithBlocks(world, structBoundingBox, 1, 2, 0, 7, 3, 0, planks, planks, false); - fillWithBlocks(world, structBoundingBox, 1, 2, 5, 7, 3, 5, planks, planks, false); + fillWithBlocks(world, structBoundingBox, 0, 3, 0, 0, 3, 5, materials.planks, materials.planks, false); + fillWithBlocks(world, structBoundingBox, 8, 3, 0, 8, 3, 5, materials.planks, materials.planks, false); + fillWithBlocks(world, structBoundingBox, 1, 2, 0, 7, 3, 0, materials.planks, materials.planks, false); + fillWithBlocks(world, structBoundingBox, 1, 2, 5, 7, 3, 5, materials.planks, materials.planks, false); // Ceiling - IBlockState slabCeiling = slabs.withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.TOP); + IBlockState slabCeiling = materials.slabs.withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.TOP); fillWithBlocks(world, structBoundingBox, 1, 4, 1, 7, 4, 4, slabCeiling, slabCeiling, false); - IBlockState logBracing = logs.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X); + IBlockState logBracing = materials.logs.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X); fillWithBlocks(world, structBoundingBox, 0, 4, 1, 8, 4, 1, logBracing, logBracing, false); fillWithBlocks(world, structBoundingBox, 0, 4, 4, 8, 4, 4, logBracing, logBracing, false); - fillWithBlocks(world, structBoundingBox, 0, 5, 2, 8, 5, 3, planks, planks, false); + fillWithBlocks(world, structBoundingBox, 0, 5, 2, 8, 5, 3, materials.planks, materials.planks, false); - setBlockState(world, planks, 0, 4, 2, structBoundingBox); - setBlockState(world, planks, 0, 4, 3, structBoundingBox); - setBlockState(world, planks, 8, 4, 2, structBoundingBox); - setBlockState(world, planks, 8, 4, 3, structBoundingBox); + setBlockState(world, materials.planks, 0, 4, 2, structBoundingBox); + setBlockState(world, materials.planks, 0, 4, 3, structBoundingBox); + setBlockState(world, materials.planks, 8, 4, 2, structBoundingBox); + setBlockState(world, materials.planks, 8, 4, 3, structBoundingBox); buildRoof(world, structBoundingBox); // sides of windows - setBlockState(world, planks, 0, 2, 1, structBoundingBox); - setBlockState(world, planks, 0, 2, 4, structBoundingBox); - setBlockState(world, planks, 8, 2, 1, structBoundingBox); - setBlockState(world, planks, 8, 2, 4, structBoundingBox); + setBlockState(world, materials.planks, 0, 2, 1, structBoundingBox); + setBlockState(world, materials.planks, 0, 2, 4, structBoundingBox); + setBlockState(world, materials.planks, 8, 2, 1, structBoundingBox); + setBlockState(world, materials.planks, 8, 2, 4, structBoundingBox); IBlockState glassPaneState = Blocks.GLASS_PANE.getDefaultState(); @@ -196,7 +168,7 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { setBlockState(world, glassPaneState, 0, 2, 2, structBoundingBox); setBlockState(world, glassPaneState, 0, 2, 3, structBoundingBox); // stairs over window - IBlockState eastStairs = stairs.withProperty(BlockStairs.FACING, EnumFacing.EAST); + IBlockState eastStairs = materials.stairs.withProperty(BlockStairs.FACING, EnumFacing.EAST); setBlockState(world, eastStairs, -1, 3, 2, structBoundingBox); setBlockState(world, eastStairs, -1, 3, 3, structBoundingBox); @@ -204,7 +176,7 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { setBlockState(world, glassPaneState, 8, 2, 2, structBoundingBox); setBlockState(world, glassPaneState, 8, 2, 3, structBoundingBox); // stairs over window - IBlockState westStairs = stairs.withProperty(BlockStairs.FACING, EnumFacing.WEST); + IBlockState westStairs = materials.stairs.withProperty(BlockStairs.FACING, EnumFacing.WEST); setBlockState(world, westStairs, 9, 3, 2, structBoundingBox); setBlockState(world, westStairs, 9, 3, 3, structBoundingBox); @@ -225,13 +197,13 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { IBlockState airState = Blocks.AIR.getDefaultState(); - this.setBlockState(world, this.door.withProperty(BlockDoor.FACING, EnumFacing.NORTH), 2, 1, 0, structBoundingBox); - this.setBlockState(world, this.door.withProperty(BlockDoor.FACING, EnumFacing.NORTH).withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 2, 2, 0, structBoundingBox); + this.setBlockState(world, materials.door.withProperty(BlockDoor.FACING, EnumFacing.NORTH), 2, 1, 0, structBoundingBox); + this.setBlockState(world, materials.door.withProperty(BlockDoor.FACING, EnumFacing.NORTH).withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 2, 2, 0, structBoundingBox); this.setBlockState(world, Blocks.TORCH.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.NORTH), 2, 3, 1, structBoundingBox); if (isAirBlockAtCurrentPosition(world, new BlockPos(2, 0, -1), structBoundingBox) && !isAirBlockAtCurrentPosition(world, new BlockPos(2, -1, -1), structBoundingBox)) { - setBlockState(world, stairs.withProperty(BlockStairs.FACING, EnumFacing.NORTH), 2, 0, -1, structBoundingBox); + setBlockState(world, materials.stairs.withProperty(BlockStairs.FACING, EnumFacing.NORTH), 2, 0, -1, structBoundingBox); } setBlockState(world, airState, 6, 1, 5, structBoundingBox); @@ -239,8 +211,8 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { this.setBlockState(world, Blocks.TORCH.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.SOUTH), 6, 3, 4, structBoundingBox); - this.setBlockState(world, this.door.withProperty(BlockDoor.FACING, EnumFacing.SOUTH), 6, 1, 5, structBoundingBox); - this.setBlockState(world, this.door.withProperty(BlockDoor.FACING, EnumFacing.SOUTH).withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 6, 2, 5, structBoundingBox); + this.setBlockState(world, materials.door.withProperty(BlockDoor.FACING, EnumFacing.SOUTH), 6, 1, 5, structBoundingBox); + this.setBlockState(world, materials.door.withProperty(BlockDoor.FACING, EnumFacing.SOUTH).withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 6, 2, 5, structBoundingBox); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 9; ++j) { @@ -252,10 +224,10 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { generateChest(world, structBoundingBox, random, 7, 1, 3, Constants.VILLAGE_NATURALIST_LOOT_KEY); // Inside Corners - fillWithBlocks(world, structBoundingBox, 1, 1, 1, 1, 3, 1, fence, fence, false); - fillWithBlocks(world, structBoundingBox, 1, 1, 4, 1, 3, 4, fence, fence, false); - fillWithBlocks(world, structBoundingBox, 7, 1, 1, 7, 3, 1, fence, fence, false); - fillWithBlocks(world, structBoundingBox, 7, 1, 4, 7, 3, 4, fence, fence, false); + fillWithBlocks(world, structBoundingBox, 1, 1, 1, 1, 3, 1, materials.fence, materials.fence, false); + fillWithBlocks(world, structBoundingBox, 1, 1, 4, 1, 3, 4, materials.fence, materials.fence, false); + fillWithBlocks(world, structBoundingBox, 7, 1, 1, 7, 3, 1, materials.fence, materials.fence, false); + fillWithBlocks(world, structBoundingBox, 7, 1, 4, 7, 3, 4, materials.fence, materials.fence, false); spawnVillagers(world, boundingBox, 2, 1, 2, 2); @@ -265,10 +237,10 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { private void buildRoof(World world, StructureBoundingBox structBoundingBox) { for (int z = -1; z <= 2; ++z) { for (int x = 0; x <= 8; ++x) { - IBlockState northStairs = stairs.withProperty(BlockStairs.FACING, EnumFacing.NORTH); + IBlockState northStairs = materials.stairs.withProperty(BlockStairs.FACING, EnumFacing.NORTH); setBlockState(world, northStairs, x, 4 + z, z, structBoundingBox); - IBlockState southStairs = stairs.withProperty(BlockStairs.FACING, EnumFacing.SOUTH); + IBlockState southStairs = materials.stairs.withProperty(BlockStairs.FACING, EnumFacing.SOUTH); setBlockState(world, southStairs, x, 4 + z, 5 - z, structBoundingBox); } } @@ -415,4 +387,36 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 { IBlockState blockStateFromPos = getBlockStateFromPos(world, pos.getX(), pos.getY(), pos.getZ(), box); return blockStateFromPos.getBlock().isAir(blockStateFromPos, world, pos); } + + private static class Materials { + public final IBlockState planks; + public final IBlockState slabs; + public final IBlockState logs; + public final IBlockState stairs; + public final IBlockState fence; + public final IBlockState door; + public final IBlockState fenceGate; + + public Materials(Random random) { + IWoodType woodType; + boolean fireproof; + + if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) { + woodType = EnumForestryWoodType.getRandom(random); + fireproof = random.nextInt(4) == 0; + } else { + woodType = EnumVanillaWoodType.getRandom(random); + fireproof = false; + } + + IWoodAccess woodAccess = TreeManager.woodAccess; + this.logs = woodAccess.getBlock(woodType, WoodBlockKind.LOG, fireproof).withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X); + this.planks = woodAccess.getBlock(woodType, WoodBlockKind.PLANKS, fireproof); + this.slabs = woodAccess.getBlock(woodType, WoodBlockKind.SLAB, fireproof); + this.stairs = woodAccess.getBlock(woodType, WoodBlockKind.STAIRS, fireproof); + this.fence = woodAccess.getBlock(woodType, WoodBlockKind.FENCE, fireproof); + this.door = woodAccess.getBlock(woodType, WoodBlockKind.DOOR, false); + this.fenceGate = woodAccess.getBlock(woodType, WoodBlockKind.FENCE_GATE, fireproof); + } + } } diff --git a/src/main/java/forestry/arboriculture/compat/ArboricultureJeiPlugin.java b/src/main/java/forestry/arboriculture/compat/ArboricultureJeiPlugin.java index aa1467559..07076b3ba 100644 --- a/src/main/java/forestry/arboriculture/compat/ArboricultureJeiPlugin.java +++ b/src/main/java/forestry/arboriculture/compat/ArboricultureJeiPlugin.java @@ -1,5 +1,6 @@ package forestry.arboriculture.compat; +import com.google.common.base.Preconditions; import forestry.arboriculture.PluginArboriculture; import forestry.arboriculture.items.ItemRegistryArboriculture; import forestry.core.utils.JeiUtil; @@ -12,6 +13,7 @@ public class ArboricultureJeiPlugin extends BlankModPlugin { @Override public void register(IModRegistry registry) { ItemRegistryArboriculture items = PluginArboriculture.items; + Preconditions.checkNotNull(items); JeiUtil.addDescription(registry, items.grafter, diff --git a/src/main/java/forestry/arboriculture/genetics/Tree.java b/src/main/java/forestry/arboriculture/genetics/Tree.java index 2ef6fd7d8..69fb0dc9c 100755 --- a/src/main/java/forestry/arboriculture/genetics/Tree.java +++ b/src/main/java/forestry/arboriculture/genetics/Tree.java @@ -67,7 +67,7 @@ public class Tree extends Individual implements ITree, IPlantable { if (nbttagcompound.hasKey("Genome")) { this.genome = new TreeGenome(nbttagcompound.getCompoundTag("Genome")); } else { - this.genome = TreeDefinition.Oak.getGenome(); + throw new IllegalArgumentException("Nbt has no Genome " + nbttagcompound); } if (nbttagcompound.hasKey("Mate")) { @@ -279,7 +279,7 @@ public class Tree extends Individual implements ITree, IPlantable { /* REPRODUCTION */ @Override - public ITree[] getSaplings(World world, GameProfile playerProfile, BlockPos pos, float modifier) { + public ITree[] getSaplings(World world, @Nullable GameProfile playerProfile, BlockPos pos, float modifier) { ArrayList prod = new ArrayList<>(); float chance = genome.getFertility() * modifier; @@ -295,7 +295,7 @@ public class Tree extends Individual implements ITree, IPlantable { return prod.toArray(new ITree[prod.size()]); } - private ITree createOffspring(World world, ITreeGenome mate, GameProfile playerProfile, BlockPos pos) { + private ITree createOffspring(World world, ITreeGenome mate, @Nullable GameProfile playerProfile, BlockPos pos) { IChromosome[] chromosomes = new IChromosome[genome.getChromosomes().length]; IChromosome[] parent1 = genome.getChromosomes(); IChromosome[] parent2 = mate.getChromosomes(); diff --git a/src/main/java/forestry/arboriculture/genetics/TreeRoot.java b/src/main/java/forestry/arboriculture/genetics/TreeRoot.java index 4f158248a..de0b943e0 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeRoot.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeRoot.java @@ -44,7 +44,9 @@ import forestry.api.genetics.IPollinatable; import forestry.api.genetics.ISpeciesType; import forestry.arboriculture.PluginArboriculture; import forestry.arboriculture.blocks.BlockFruitPod; +import forestry.arboriculture.blocks.BlockRegistryArboriculture; import forestry.arboriculture.blocks.BlockSapling; +import forestry.arboriculture.items.ItemRegistryArboriculture; import forestry.arboriculture.tiles.TileFruitPod; import forestry.arboriculture.tiles.TileSapling; import forestry.core.config.Config; @@ -75,7 +77,7 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { private static ITreekeepingMode activeTreekeepingMode; public static final List treeTemplates = new ArrayList<>(); - private final ArrayList treekeepingModes = new ArrayList<>(); + private final List treekeepingModes = new ArrayList<>(); public TreeRoot() { setResearchSuitability(new ItemStack(Blocks.SAPLING, 1, OreDictionary.WILDCARD_VALUE), 1.0f); @@ -129,12 +131,13 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { if (stack.isEmpty()) { return null; } + ItemRegistryArboriculture items = PluginArboriculture.items; + Preconditions.checkState(items != null); Item item = stack.getItem(); - - if (PluginArboriculture.items.sapling == item) { + if (items.sapling == item) { return EnumGermlingType.SAPLING; - } else if (PluginArboriculture.items.pollenFertile == item) { + } else if (items.pollenFertile == item) { return EnumGermlingType.POLLEN; } @@ -157,10 +160,12 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { } @Override + @Nullable public ITree getMember(ItemStack itemstack) { itemstack = GeneticsUtil.convertToGeneticEquivalent(itemstack); - Preconditions.checkArgument(isMember(itemstack), "ItemStack must be a tree."); - Preconditions.checkArgument(itemstack.getTagCompound() != null, "ItemStack must have a tag compound."); + if (!isMember(itemstack) || itemstack.getTagCompound() == null) { + return null; + } return new Tree(itemstack.getTagCompound()); } @@ -179,14 +184,16 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { public ItemStack getMemberStack(IIndividual tree, ISpeciesType type) { Preconditions.checkArgument(tree instanceof ITree, "individual is not a tree"); Preconditions.checkArgument(type instanceof EnumGermlingType, "type is not an EnumGermlingType"); + ItemRegistryArboriculture items = PluginArboriculture.items; + Preconditions.checkState(items != null); Item germlingItem; switch ((EnumGermlingType) type) { case SAPLING: - germlingItem = PluginArboriculture.items.sapling; + germlingItem = items.sapling; break; case POLLEN: - germlingItem = PluginArboriculture.items.pollenFertile; + germlingItem = items.pollenFertile; break; default: throw new RuntimeException("Cannot instantiate a tree of type " + type); @@ -204,8 +211,10 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { @Override public boolean plantSapling(World world, ITree tree, GameProfile owner, BlockPos pos) { + BlockRegistryArboriculture blocks = PluginArboriculture.blocks; + Preconditions.checkState(blocks != null); - IBlockState state = PluginArboriculture.blocks.saplingGE.getDefaultState().withProperty(BlockSapling.TREE, tree.getGenome().getPrimary()); + IBlockState state = blocks.saplingGE.getDefaultState().withProperty(BlockSapling.TREE, tree.getGenome().getPrimary()); boolean placed = world.setBlockState(pos, state); if (!placed) { return false; @@ -213,7 +222,7 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { IBlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); - if (PluginArboriculture.blocks.saplingGE != block) { + if (blocks.saplingGE != block) { return false; } @@ -234,36 +243,36 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { @Override public boolean setFruitBlock(World world, ITreeGenome genome, IAlleleFruit allele, float sappiness, BlockPos pos) { + BlockRegistryArboriculture blocks = PluginArboriculture.blocks; + Preconditions.checkState(blocks != null); EnumFacing facing = BlockUtil.getValidPodFacing(world, pos); - if (facing == null) { - return false; - } + if (facing != null) { - BlockFruitPod fruitPod = PluginArboriculture.blocks.getFruitPod(allele); - if (fruitPod == null) { - return false; - } + BlockFruitPod fruitPod = blocks.getFruitPod(allele); + if (fruitPod != null) { - IBlockState state = fruitPod.getDefaultState().withProperty(BlockHorizontal.FACING, facing); - boolean placed = world.setBlockState(pos, state); - if (!placed) { - return false; - } + IBlockState state = fruitPod.getDefaultState().withProperty(BlockHorizontal.FACING, facing); + boolean placed = world.setBlockState(pos, state); + if (placed) { - Block block = world.getBlockState(pos).getBlock(); - if (fruitPod != block) { - return false; - } + Block block = world.getBlockState(pos).getBlock(); + if (fruitPod == block) { - TileFruitPod pod = TileUtil.getTile(world, pos, TileFruitPod.class); - if (pod == null) { - world.setBlockToAir(pos); - return false; + TileFruitPod pod = TileUtil.getTile(world, pos, TileFruitPod.class); + if (pod != null) { + pod.setProperties(genome, allele, sappiness); + world.markBlockRangeForRenderUpdate(pos, pos); + return true; + } else { + world.setBlockToAir(pos); + return false; + } + } + } + } } - pod.setProperties(genome, allele, sappiness); - world.markBlockRangeForRenderUpdate(pos, pos); - return true; + return false; } /* GENOME CONVERSIONS */ diff --git a/src/main/java/forestry/core/circuits/CircuitRegistry.java b/src/main/java/forestry/core/circuits/CircuitRegistry.java index a2633945b..628098c57 100755 --- a/src/main/java/forestry/core/circuits/CircuitRegistry.java +++ b/src/main/java/forestry/core/circuits/CircuitRegistry.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.circuits; +import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Map; @@ -73,6 +74,7 @@ public class CircuitRegistry implements ICircuitRegistry { } @Override + @Nullable public ICircuitLayout getLayout(String uid) { if (layoutMap.containsKey(uid)) { return layoutMap.get(uid); @@ -93,6 +95,7 @@ public class CircuitRegistry implements ICircuitRegistry { } @Override + @Nullable public ICircuit getCircuit(String uid) { return circuitMap.get(uid); } diff --git a/src/main/java/forestry/core/circuits/Circuits.java b/src/main/java/forestry/core/circuits/Circuits.java index 8ae064869..707f33859 100644 --- a/src/main/java/forestry/core/circuits/Circuits.java +++ b/src/main/java/forestry/core/circuits/Circuits.java @@ -2,6 +2,7 @@ package forestry.core.circuits; import forestry.api.circuits.ICircuit; +@SuppressWarnings({"unused", "NullableProblems"}) public class Circuits { public static ICircuit energyElectricChoke1; public static ICircuit energyElectricEfficiency1; diff --git a/src/main/java/forestry/core/circuits/GuiSolderingIron.java b/src/main/java/forestry/core/circuits/GuiSolderingIron.java index 0f78853ec..3005827b7 100755 --- a/src/main/java/forestry/core/circuits/GuiSolderingIron.java +++ b/src/main/java/forestry/core/circuits/GuiSolderingIron.java @@ -26,13 +26,15 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -public class GuiSolderingIron extends GuiForestry { +public class GuiSolderingIron extends GuiForestry { + private final ItemInventorySolderingIron itemInventory; - public GuiSolderingIron(EntityPlayer player, ItemInventorySolderingIron inventory) { - super(Constants.TEXTURE_PATH_GUI + "/solder.png", new ContainerSolderingIron(player, inventory), inventory); + public GuiSolderingIron(EntityPlayer player, ItemInventorySolderingIron itemInventory) { + super(Constants.TEXTURE_PATH_GUI + "/solder.png", new ContainerSolderingIron(player, itemInventory)); - xSize = 176; - ySize = 205; + this.itemInventory = itemInventory; + this.xSize = 176; + this.ySize = 205; } @Override @@ -45,7 +47,7 @@ public class GuiSolderingIron extends GuiForestry { +public class GuiAlyzer extends GuiForestry { public static final int COLUMN_0 = 12; public static final int COLUMN_1 = 90; public static final int COLUMN_2 = 155; - public GuiAlyzer(EntityPlayer player, ItemInventoryAlyzer inventory) { - super(Constants.TEXTURE_PATH_GUI + "/portablealyzer.png", new ContainerAlyzer(inventory, player), inventory); + private final ItemInventoryAlyzer itemInventory; + public GuiAlyzer(EntityPlayer player, ItemInventoryAlyzer itemInventory) { + super(Constants.TEXTURE_PATH_GUI + "/portablealyzer.png", new ContainerAlyzer(itemInventory, player)); + + this.itemInventory = itemInventory; this.xSize = 246; this.ySize = 238; } @@ -136,7 +140,7 @@ public class GuiAlyzer extends GuiForestry { return; } - ItemStack stackInSlot = inventory.getStackInSlot(specimenSlot); + ItemStack stackInSlot = itemInventory.getStackInSlot(specimenSlot); ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(stackInSlot); if (speciesRoot == null) { return; @@ -173,7 +177,7 @@ public class GuiAlyzer extends GuiForestry { private int getSpecimenSlot() { for (int k = ItemInventoryAlyzer.SLOT_SPECIMEN; k <= ItemInventoryAlyzer.SLOT_ANALYZE_5; k++) { - ItemStack stackInSlot = inventory.getStackInSlot(k); + ItemStack stackInSlot = itemInventory.getStackInSlot(k); if (stackInSlot.isEmpty()) { continue; } @@ -475,8 +479,21 @@ public class GuiAlyzer extends GuiForestry { return widgetManager; } - public LedgerManager getLedgerManager() { - return ledgerManager; + @Override + protected void addLedgers() { + addErrorLedger(itemInventory); + addHintLedger(getHints()); } + public List getHints() { + ItemStack specimen = itemInventory.getSpecimen(); + if (!specimen.isEmpty()) { + ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen); + if (speciesRoot != null) { + IAlyzerPlugin alyzerPlugin = speciesRoot.getAlyzerPlugin(); + return alyzerPlugin.getHints(); + } + } + return Collections.emptyList(); + } } diff --git a/src/main/java/forestry/core/gui/GuiAnalyzer.java b/src/main/java/forestry/core/gui/GuiAnalyzer.java index cb3a9e341..f221bb080 100755 --- a/src/main/java/forestry/core/gui/GuiAnalyzer.java +++ b/src/main/java/forestry/core/gui/GuiAnalyzer.java @@ -16,18 +16,20 @@ import forestry.core.render.EnumTankLevel; import forestry.core.tiles.TileAnalyzer; import net.minecraft.entity.player.InventoryPlayer; -public class GuiAnalyzer extends GuiForestryTitled { +public class GuiAnalyzer extends GuiForestryTitled { + private final TileAnalyzer tile; public GuiAnalyzer(InventoryPlayer inventory, TileAnalyzer tile) { super(Constants.TEXTURE_PATH_GUI + "/alyzer.png", new ContainerAnalyzer(inventory, tile), tile); - ySize = 176; - widgetManager.add(new TankWidget(this.widgetManager, 95, 24, 0)); + this.tile = tile; + this.ySize = 176; + this.widgetManager.add(new TankWidget(this.widgetManager, 95, 24, 0)); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - drawAnalyzeMeter(guiLeft + 64, guiTop + 30, inventory.getProgressScaled(46), EnumTankLevel.rateTankLevel(inventory.getProgressScaled(100))); + drawAnalyzeMeter(guiLeft + 64, guiTop + 30, tile.getProgressScaled(46), EnumTankLevel.rateTankLevel(tile.getProgressScaled(100))); } private void drawAnalyzeMeter(int x, int y, int height, EnumTankLevel rated) { @@ -36,4 +38,10 @@ public class GuiAnalyzer extends GuiForestryTitled { +public class GuiCamouflageSprayCan extends GuiForestry { public GuiCamouflageSprayCan(EntityPlayer player, ItemInventoryCamouflageSprayCan inventory) { - super(Constants.TEXTURE_PATH_GUI + "/camouflage_spray_can.png", new ContainerCamouflageSprayCan(inventory, player.inventory), inventory); + super(Constants.TEXTURE_PATH_GUI + "/camouflage_spray_can.png", new ContainerCamouflageSprayCan(inventory, player.inventory)); widgetManager.add(new WidgetCamouflageSlot(widgetManager, 80, 39, inventory, CamouflageManager.NONE)); } @@ -26,4 +26,9 @@ public class GuiCamouflageSprayCan extends GuiForestry { +public class GuiEscritoire extends GuiForestry { private final ItemStack LEVEL_ITEM = new ItemStack(Items.PAPER); private final EscritoireTextSource textSource = new EscritoireTextSource(); + private final TileEscritoire tile; public GuiEscritoire(EntityPlayer player, TileEscritoire tile) { - super(Constants.TEXTURE_PATH_GUI + "/escritoire.png", new ContainerEscritoire(player, tile), tile); + super(Constants.TEXTURE_PATH_GUI + "/escritoire.png", new ContainerEscritoire(player, tile)); - xSize = 228; - ySize = 235; + this.tile = tile; + this.xSize = 228; + this.ySize = 235; - widgetManager.add(new ProbeButton(this, widgetManager, 14, 16)); + this.widgetManager.add(new ProbeButton(this, widgetManager, 14, 16)); EscritoireGame game = tile.getGame(); @@ -80,7 +82,7 @@ public class GuiEscritoire extends GuiForestry extends GuiContainer { - @Nullable - protected final I inventory; +public abstract class GuiForestry extends GuiContainer { protected final C container; public final ResourceLocation textureFile; @@ -55,11 +51,11 @@ public abstract class GuiForestry ext protected final LedgerManager ledgerManager; protected final TextLayoutHelper textLayout; - protected GuiForestry(String texture, C container, @Nullable I inventory) { - this(new ForestryResource(texture), container, inventory); + protected GuiForestry(String texture, C container) { + this(new ForestryResource(texture), container); } - protected GuiForestry(ResourceLocation texture, C container, @Nullable I inventory) { + protected GuiForestry(ResourceLocation texture, C container) { super(container); this.widgetManager = new WidgetManager(this); @@ -67,7 +63,6 @@ public abstract class GuiForestry ext this.textureFile = texture; - this.inventory = inventory; this.container = container; this.textLayout = new TextLayoutHelper(this, ColourProperties.INSTANCE); @@ -82,46 +77,47 @@ public abstract class GuiForestry ext this.ledgerManager.setMaxWidth(maxLedgerWidth); this.ledgerManager.clear(); - + addLedgers(); } - protected void addLedgers() { - if (inventory instanceof IErrorSource) { - ledgerManager.add((IErrorSource) inventory); - } + protected abstract void addLedgers(); - if (inventory instanceof IErrorLogicSource) { - IErrorLogicSource errorLogicSource = (IErrorLogicSource) inventory; - ledgerManager.add(errorLogicSource.getErrorLogic()); - } + protected final void addErrorLedger(IErrorSource errorSource) { + ledgerManager.add(errorSource); + } - if (inventory instanceof IClimatised) { - ledgerManager.add(new ClimateLedger(ledgerManager, (IClimatised) inventory)); - } + protected final void addErrorLedger(IErrorLogicSource errorSource) { + ledgerManager.add(errorSource.getErrorLogic()); + } + protected final void addClimateLedger(IClimatised climatised) { + ledgerManager.add(new ClimateLedger(ledgerManager, climatised)); + } + + protected final void addPowerLedger(EnergyManager energyManager) { if (Config.enableEnergyStat) { - if (inventory instanceof IPowerHandler && !(inventory instanceof TileEngine)) { - IPowerHandler powerHandler = (IPowerHandler) this.inventory; - if (powerHandler.getEnergyManager().getMaxEnergyStored() > 0) { - ledgerManager.add(new PowerLedger(ledgerManager, powerHandler)); - } - } + ledgerManager.add(new PowerLedger(ledgerManager, energyManager)); } + } - if (Config.enableHints && inventory instanceof IHintSource) { - IHintSource hintSource = (IHintSource) inventory; - List hints = hintSource.getHints(); - if (!hints.isEmpty()) { - ledgerManager.add(new HintLedger(ledgerManager, hintSource)); - } + protected final void addHintLedger(String hintsKey) { + if (Config.enableHints) { + List hints = Config.hints.get(hintsKey); + ledgerManager.add(new HintLedger(ledgerManager, hints)); } + } - if (inventory instanceof IOwnedTile) { - ledgerManager.add(new OwnerLedger(ledgerManager, (IOwnedTile) inventory)); + protected final void addHintLedger(List hints) { + if (Config.enableHints) { + ledgerManager.add(new HintLedger(ledgerManager, hints)); } } + protected final void addOwnerLedger(IOwnedTile ownedTile) { + ledgerManager.add(new OwnerLedger(ledgerManager, ownedTile)); + } + @Override public void onGuiClosed() { super.onGuiClosed(); @@ -147,7 +143,7 @@ public abstract class GuiForestry ext @Override protected void mouseReleased(int mouseX, int mouseY, int state) { - if(widgetManager.handleMouseRelease(mouseX, mouseY, state)){ + if (widgetManager.handleMouseRelease(mouseX, mouseY, state)) { return; } super.mouseReleased(mouseX, mouseY, state); diff --git a/src/main/java/forestry/core/gui/GuiForestryTitled.java b/src/main/java/forestry/core/gui/GuiForestryTitled.java index 994bd4e2f..980351375 100644 --- a/src/main/java/forestry/core/gui/GuiForestryTitled.java +++ b/src/main/java/forestry/core/gui/GuiForestryTitled.java @@ -14,19 +14,20 @@ import forestry.core.render.ColourProperties; import forestry.core.tiles.ITitled; import forestry.core.utils.Translator; import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -public abstract class GuiForestryTitled extends GuiForestry { +public abstract class GuiForestryTitled extends GuiForestry { + private final String unlocalizedTitle; - protected GuiForestryTitled(String texture, C container, I inventory) { - super(texture, container, inventory); + protected GuiForestryTitled(String texture, C container, ITitled titled) { + super(texture, container); + this.unlocalizedTitle = titled.getUnlocalizedTitle(); } @Override protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY); - String name = Translator.translateToLocal(inventory.getUnlocalizedTitle()); + String name = Translator.translateToLocal(this.unlocalizedTitle); textLayout.line = 6; textLayout.drawCenteredLine(name, 0, ColourProperties.INSTANCE.get("gui.title")); bindTexture(textureFile); diff --git a/src/main/java/forestry/core/gui/GuiNaturalistInventory.java b/src/main/java/forestry/core/gui/GuiNaturalistInventory.java index 56edbdb8b..cb8ab609b 100755 --- a/src/main/java/forestry/core/gui/GuiNaturalistInventory.java +++ b/src/main/java/forestry/core/gui/GuiNaturalistInventory.java @@ -36,14 +36,14 @@ import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -public class GuiNaturalistInventory extends GuiForestry { +public class GuiNaturalistInventory extends GuiForestry { private final ISpeciesRoot speciesRoot; private final IBreedingTracker breedingTracker; private final HashMap iconStacks = new HashMap<>(); private final int pageCurrent, pageMax; - public GuiNaturalistInventory(ISpeciesRoot speciesRoot, EntityPlayer player, Container container, IPagedInventory inventory, int page, int maxPages) { - super(Constants.TEXTURE_PATH_GUI + "/apiaristinventory.png", container, inventory); + public GuiNaturalistInventory(ISpeciesRoot speciesRoot, EntityPlayer player, Container container, int page, int maxPages) { + super(Constants.TEXTURE_PATH_GUI + "/apiaristinventory.png", container); this.speciesRoot = speciesRoot; @@ -250,4 +250,9 @@ public class GuiNaturalistInventory extends GuiForestry getHints(); -} diff --git a/src/main/java/forestry/core/gui/ledgers/HintLedger.java b/src/main/java/forestry/core/gui/ledgers/HintLedger.java index 2b6c7c9db..26ab3ccf3 100644 --- a/src/main/java/forestry/core/gui/ledgers/HintLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/HintLedger.java @@ -13,7 +13,6 @@ package forestry.core.gui.ledgers; import java.util.List; import java.util.Random; -import forestry.core.gui.IHintSource; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; import forestry.core.utils.Translator; @@ -25,9 +24,8 @@ public class HintLedger extends Ledger { private final String hintString; private final String hintTooltip; - public HintLedger(LedgerManager manager, IHintSource tile) { + public HintLedger(LedgerManager manager, List hints) { super(manager, "hint"); - List hints = tile.getHints(); int position = new Random().nextInt(hints.size()); String hint = hints.get(position); diff --git a/src/main/java/forestry/core/gui/ledgers/PowerLedger.java b/src/main/java/forestry/core/gui/ledgers/PowerLedger.java index fa9160885..3d152f7ad 100644 --- a/src/main/java/forestry/core/gui/ledgers/PowerLedger.java +++ b/src/main/java/forestry/core/gui/ledgers/PowerLedger.java @@ -11,17 +11,15 @@ package forestry.core.gui.ledgers; import forestry.core.render.TextureManager; -import forestry.core.tiles.IPowerHandler; import forestry.core.utils.Translator; import forestry.energy.EnergyManager; public class PowerLedger extends Ledger { + private final EnergyManager energyManager; - private final IPowerHandler tile; - - public PowerLedger(LedgerManager manager, IPowerHandler tile) { + public PowerLedger(LedgerManager manager, EnergyManager energyManager) { super(manager, "power"); - this.tile = tile; + this.energyManager = energyManager; maxHeight = 94; } @@ -40,8 +38,6 @@ public class PowerLedger extends Ledger { int xHeader = x + 22; int xBody = x + 12; - EnergyManager energyManager = tile.getEnergyManager(); - drawHeader(Translator.translateToLocal("for.gui.energy"), xHeader, y + 8); drawSubheader(Translator.translateToLocal("for.gui.stored") + ':', xBody, y + 20); @@ -56,7 +52,7 @@ public class PowerLedger extends Ledger { @Override public String getTooltip() { - return tile.getEnergyManager().getEnergyStored() + " RF"; + return energyManager.getEnergyStored() + " RF"; } } diff --git a/src/main/java/forestry/core/inventory/ItemInventoryAlyzer.java b/src/main/java/forestry/core/inventory/ItemInventoryAlyzer.java index c7a5443ef..9a73d265b 100644 --- a/src/main/java/forestry/core/inventory/ItemInventoryAlyzer.java +++ b/src/main/java/forestry/core/inventory/ItemInventoryAlyzer.java @@ -10,22 +10,17 @@ ******************************************************************************/ package forestry.core.inventory; -import java.util.Collections; -import java.util.List; - import com.google.common.collect.ImmutableSet; import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorSource; import forestry.api.core.IErrorState; import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IAlyzerPlugin; import forestry.api.genetics.IBreedingTracker; import forestry.api.genetics.IIndividual; import forestry.api.genetics.ISpeciesRoot; import forestry.apiculture.PluginApiculture; import forestry.apiculture.items.ItemRegistryApiculture; import forestry.core.errors.EnumErrorCode; -import forestry.core.gui.IHintSource; import forestry.core.utils.GeneticsUtil; import forestry.plugins.ForestryPluginUids; import net.minecraft.entity.player.EntityPlayer; @@ -33,7 +28,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -public class ItemInventoryAlyzer extends ItemInventory implements IErrorSource, IHintSource { +public class ItemInventoryAlyzer extends ItemInventory implements IErrorSource { public static final int SLOT_ENERGY = 0; public static final int SLOT_SPECIMEN = 1; public static final int SLOT_ANALYZE_1 = 2; @@ -172,18 +167,4 @@ public class ItemInventoryAlyzer extends ItemInventory implements IErrorSource, public boolean hasSpecimen() { return !getSpecimen().isEmpty(); } - - /* IHintSource */ - @Override - public List getHints() { - ItemStack specimen = getSpecimen(); - if (!specimen.isEmpty()) { - ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen); - if (speciesRoot != null) { - IAlyzerPlugin alyzerPlugin = speciesRoot.getAlyzerPlugin(); - return alyzerPlugin.getHints(); - } - } - return Collections.emptyList(); - } } diff --git a/src/main/java/forestry/core/inventory/ItemInventorySolderingIron.java b/src/main/java/forestry/core/inventory/ItemInventorySolderingIron.java index ab633b7ab..b44169fd7 100644 --- a/src/main/java/forestry/core/inventory/ItemInventorySolderingIron.java +++ b/src/main/java/forestry/core/inventory/ItemInventorySolderingIron.java @@ -10,7 +10,7 @@ ******************************************************************************/ package forestry.core.inventory; -import java.util.List; +import javax.annotation.Nullable; import com.google.common.collect.ImmutableSet; import forestry.api.circuits.ChipsetManager; @@ -23,15 +23,13 @@ import forestry.core.circuits.CircuitRegistry; import forestry.core.circuits.EnumCircuitBoardType; import forestry.core.circuits.ItemCircuitBoard; import forestry.core.circuits.SolderManager; -import forestry.core.config.Config; import forestry.core.errors.EnumErrorCode; -import forestry.core.gui.IHintSource; import forestry.core.utils.datastructures.RevolvingList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -public class ItemInventorySolderingIron extends ItemInventory implements IErrorSource, IHintSource { +public class ItemInventorySolderingIron extends ItemInventory implements IErrorSource { private final RevolvingList layouts = new RevolvingList<>(ChipsetManager.circuitRegistry.getRegisteredLayouts().values()); @@ -51,6 +49,7 @@ public class ItemInventorySolderingIron extends ItemInventory implements IErrorS return 1; } + @Nullable public ICircuitLayout getLayout() { return layouts.getCurrent(); } @@ -186,9 +185,4 @@ public class ItemInventorySolderingIron extends ItemInventory implements IErrorS } return false; } - - @Override - public List getHints() { - return Config.hints.get("soldering.iron"); - } } diff --git a/src/main/java/forestry/core/tiles/AdjacentTileCache.java b/src/main/java/forestry/core/tiles/AdjacentTileCache.java index e580d6460..6bfd1286f 100644 --- a/src/main/java/forestry/core/tiles/AdjacentTileCache.java +++ b/src/main/java/forestry/core/tiles/AdjacentTileCache.java @@ -103,6 +103,7 @@ public final class AdjacentTileCache { return source.getPos().getX() + side.getFrontOffsetX() == target.getPos().getX() && source.getPos().getY() + side.getFrontOffsetY() == target.getPos().getY() && source.getPos().getZ() + side.getFrontOffsetZ() == target.getPos().getZ(); } + @Nullable public TileEntity getTileOnSide(EnumFacing side) { int s = side.ordinal(); if (cache[s] != null) { diff --git a/src/main/java/forestry/core/tiles/TileAnalyzer.java b/src/main/java/forestry/core/tiles/TileAnalyzer.java index 967e3b875..3dad1a8a0 100644 --- a/src/main/java/forestry/core/tiles/TileAnalyzer.java +++ b/src/main/java/forestry/core/tiles/TileAnalyzer.java @@ -59,7 +59,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui /* CONSTRUCTOR */ public TileAnalyzer() { - super("analyzer", 800, Constants.MACHINE_MAX_ENERGY); + super(800, Constants.MACHINE_MAX_ENERGY); setInternalInventory(new InventoryAnalyzer(this)); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY).setFilters(Fluids.FOR_HONEY.getFluid()); tankManager = new TankManager(this, resourceTank); diff --git a/src/main/java/forestry/core/tiles/TileBase.java b/src/main/java/forestry/core/tiles/TileBase.java index 24ad89c23..793f12fa9 100644 --- a/src/main/java/forestry/core/tiles/TileBase.java +++ b/src/main/java/forestry/core/tiles/TileBase.java @@ -10,14 +10,8 @@ ******************************************************************************/ package forestry.core.tiles; -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - import forestry.core.blocks.BlockBase; -import forestry.core.config.Config; import forestry.core.gui.GuiHandler; -import forestry.core.gui.IHintSource; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -25,27 +19,12 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public abstract class TileBase extends TileForestry implements IHintSource { - protected final List hints; - - protected TileBase(@Nullable String hintKey) { - this.hints = new ArrayList<>(Config.hints.get(hintKey)); - } +public abstract class TileBase extends TileForestry { public void openGui(EntityPlayer player, ItemStack heldItem) { GuiHandler.openGui(player, this); } - public boolean canDrainWithBucket() { - return false; - } - - /* IHintSource */ - @Override - public final List getHints() { - return hints; - } - @Override public String getUnlocalizedTitle() { Block block = getBlockType(); diff --git a/src/main/java/forestry/core/tiles/TileEngine.java b/src/main/java/forestry/core/tiles/TileEngine.java index 853a3c768..75fc0e030 100644 --- a/src/main/java/forestry/core/tiles/TileEngine.java +++ b/src/main/java/forestry/core/tiles/TileEngine.java @@ -16,7 +16,6 @@ import java.io.IOException; import forestry.api.core.IErrorLogic; import forestry.apiculture.network.packets.PacketActiveUpdate; import forestry.core.blocks.BlockBase; -import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; import forestry.core.network.IStreamableGui; @@ -52,15 +51,18 @@ public abstract class TileEngine extends TileBase implements IActivatable, IStre protected boolean forceCooldown = false; public float progress; protected final EnergyManager energyManager; + private final String hintKey; - protected TileEngine(@Nullable String hintKey, int maxHeat, int maxEnergy) { - super(hintKey); + protected TileEngine(String hintKey, int maxHeat, int maxEnergy) { + this.hintKey = hintKey; this.maxHeat = maxHeat; energyManager = new EnergyManager(2000, maxEnergy); energyManager.setExternalMode(EnergyTransferMode.EXTRACT); + } - hints.addAll(Config.hints.get("engine")); + public String getHintKey() { + return hintKey; } protected void addHeat(int i) { diff --git a/src/main/java/forestry/core/tiles/TileEscritoire.java b/src/main/java/forestry/core/tiles/TileEscritoire.java index cdf2de30c..fc13f353c 100644 --- a/src/main/java/forestry/core/tiles/TileEscritoire.java +++ b/src/main/java/forestry/core/tiles/TileEscritoire.java @@ -37,7 +37,6 @@ public class TileEscritoire extends TileBase implements ISidedInventory, ISlotPi private ItemStack individualOnDisplayClient = ItemStack.EMPTY; public TileEscritoire() { - super("escritoire"); setInternalInventory(new InventoryEscritoire(this)); } diff --git a/src/main/java/forestry/core/tiles/TileMill.java b/src/main/java/forestry/core/tiles/TileMill.java index 234f0a82a..f99e41293 100644 --- a/src/main/java/forestry/core/tiles/TileMill.java +++ b/src/main/java/forestry/core/tiles/TileMill.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.core.tiles; -import javax.annotation.Nullable; import java.io.IOException; import forestry.core.network.PacketBufferForestry; @@ -22,8 +21,7 @@ public abstract class TileMill extends TileBase { public int charge = 0; public float progress; - protected TileMill(@Nullable String hintKey) { - super(hintKey); + protected TileMill() { speed = 0.01F; } diff --git a/src/main/java/forestry/core/tiles/TileNaturalistChest.java b/src/main/java/forestry/core/tiles/TileNaturalistChest.java index 218e9afeb..2e3446c0c 100644 --- a/src/main/java/forestry/core/tiles/TileNaturalistChest.java +++ b/src/main/java/forestry/core/tiles/TileNaturalistChest.java @@ -35,7 +35,6 @@ public abstract class TileNaturalistChest extends TileBase implements IPagedInve private int numPlayersUsing; public TileNaturalistChest(ISpeciesRoot speciesRoot) { - super("naturalist.chest"); this.speciesRoot = speciesRoot; setInternalInventory(new InventoryNaturalistChest(this, speciesRoot)); } @@ -112,7 +111,7 @@ public abstract class TileNaturalistChest extends TileBase implements IPagedInve @Override public Object getGui(EntityPlayer player, int page) { ContainerNaturalistInventory container = new ContainerNaturalistInventory(player.inventory, this, page); - return new GuiNaturalistInventory(speciesRoot, player, container, this, page, 5); + return new GuiNaturalistInventory(speciesRoot, player, container, page, 5); } @Override diff --git a/src/main/java/forestry/core/tiles/TilePowered.java b/src/main/java/forestry/core/tiles/TilePowered.java index d07317cf4..763022011 100644 --- a/src/main/java/forestry/core/tiles/TilePowered.java +++ b/src/main/java/forestry/core/tiles/TilePowered.java @@ -15,7 +15,6 @@ import java.io.IOException; import forestry.api.core.IErrorLogic; import forestry.core.circuits.ISpeedUpgradable; -import forestry.core.config.Config; import forestry.core.errors.EnumErrorCode; import forestry.core.network.IStreamableGui; import forestry.core.network.PacketBufferForestry; @@ -43,14 +42,15 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I // the number of work ticks that this tile has had no power private int noPowerTime = 0; - protected TilePowered(String hintKey, int maxTransfer, int capacity) { - super(hintKey); + protected TilePowered(int maxTransfer, int capacity) { this.energyManager = new EnergyManager(maxTransfer, capacity); this.energyManager.setExternalMode(EnergyTransferMode.RECEIVE); this.ticksPerWorkCycle = 4; + } - hints.addAll(Config.hints.get("powered.machine")); + public EnergyManager getEnergyManager() { + return energyManager; } public int getWorkCounter() { diff --git a/src/main/java/forestry/energy/EnergyHelper.java b/src/main/java/forestry/energy/EnergyHelper.java index f73c1cdc9..a191cda17 100644 --- a/src/main/java/forestry/energy/EnergyHelper.java +++ b/src/main/java/forestry/energy/EnergyHelper.java @@ -1,5 +1,7 @@ package forestry.energy; +import javax.annotation.Nullable; + import forestry.api.core.ForestryAPI; import forestry.core.tiles.TileEngine; import forestry.energy.compat.tesla.TeslaHelper; @@ -87,8 +89,8 @@ public class EnergyHelper { return sendEnergy(energyManager, orientation, tile, Integer.MAX_VALUE, true) > 0; } - public static boolean isEnergyReceiverOrEngine(EnumFacing side, TileEntity tile) { - if(tile == null){ + public static boolean isEnergyReceiverOrEngine(EnumFacing side, @Nullable TileEntity tile) { + if (tile == null) { return false; } if (tile instanceof TileEngine) { // engine chaining diff --git a/src/main/java/forestry/energy/gui/GuiEngine.java b/src/main/java/forestry/energy/gui/GuiEngine.java index ff3cf1c81..26e3d6d6a 100755 --- a/src/main/java/forestry/energy/gui/GuiEngine.java +++ b/src/main/java/forestry/energy/gui/GuiEngine.java @@ -17,10 +17,12 @@ import forestry.core.tiles.TileEngine; import forestry.core.utils.Translator; import net.minecraft.inventory.Container; -public abstract class GuiEngine extends GuiForestryTitled { +public abstract class GuiEngine extends GuiForestryTitled { + protected final I tile; protected GuiEngine(String texture, C container, I tile) { super(texture, container, tile); + this.tile = tile; } @Override @@ -52,19 +54,25 @@ public abstract class GuiEngine exten drawHeader(Translator.translateToLocal("for.gui.energy"), x + 22, y + 8); drawSubheader(Translator.translateToLocal("for.gui.currentOutput") + ':', x + 22, y + 20); - drawText(inventory.getCurrentOutput() + " RF/t", x + 22, y + 32); + drawText(tile.getCurrentOutput() + " RF/t", x + 22, y + 32); drawSubheader(Translator.translateToLocal("for.gui.stored") + ':', x + 22, y + 44); - drawText(inventory.getEnergyManager().getEnergyStored() + " RF", x + 22, y + 56); + drawText(tile.getEnergyManager().getEnergyStored() + " RF", x + 22, y + 56); drawSubheader(Translator.translateToLocal("for.gui.heat") + ':', x + 22, y + 68); - drawText((double) inventory.getHeat() / (double) 10 + 20.0 + " C", x + 22, y + 80); + drawText((double) tile.getHeat() / (double) 10 + 20.0 + " C", x + 22, y + 80); } @Override public String getTooltip() { - return inventory.getCurrentOutput() + " RF/t"; + return tile.getCurrentOutput() + " RF/t"; } } + @Override + protected void addLedgers() { + addErrorLedger(tile); + addHintLedger(tile.getHintKey()); + ledgerManager.add(new EngineLedger()); + } } diff --git a/src/main/java/forestry/energy/gui/GuiEngineBiogas.java b/src/main/java/forestry/energy/gui/GuiEngineBiogas.java index 05589ea52..4df180a60 100644 --- a/src/main/java/forestry/energy/gui/GuiEngineBiogas.java +++ b/src/main/java/forestry/energy/gui/GuiEngineBiogas.java @@ -28,7 +28,7 @@ public class GuiEngineBiogas extends GuiEngine 16) { temperature = 16; } diff --git a/src/main/java/forestry/energy/gui/GuiEnginePeat.java b/src/main/java/forestry/energy/gui/GuiEnginePeat.java index 3ab267aaf..0c9e9b959 100644 --- a/src/main/java/forestry/energy/gui/GuiEnginePeat.java +++ b/src/main/java/forestry/energy/gui/GuiEnginePeat.java @@ -24,10 +24,8 @@ public class GuiEnginePeat extends GuiEngine { +public class GuiBottler extends GuiForestryTitled { + private final TileBottler tile; - public GuiBottler(InventoryPlayer inventory, TileBottler processor) { - super(Constants.TEXTURE_PATH_GUI + "/bottler.png", new ContainerBottler(inventory, processor), processor); + public GuiBottler(InventoryPlayer inventory, TileBottler tile) { + super(Constants.TEXTURE_PATH_GUI + "/bottler.png", new ContainerBottler(inventory, tile), tile); + this.tile = tile; widgetManager.add(new TankWidget(this.widgetManager, 80, 14, 0)); } @@ -46,14 +48,14 @@ public class GuiBottler extends GuiForestryTitled } GlStateManager.popMatrix(); - String name = Translator.translateToLocal(inventory.getUnlocalizedTitle()); + String name = Translator.translateToLocal(tile.getUnlocalizedTitle()); textLayout.line = 5; textLayout.drawCenteredLine(name, 0, ColourProperties.INSTANCE.get("gui.title")); bindTexture(textureFile); bindTexture(textureFile); - TileBottler bottler = inventory; + TileBottler bottler = tile; int progressArrow = bottler.getProgressScaled(22); if (progressArrow > 0) { if (bottler.isFillRecipe) { @@ -63,4 +65,11 @@ public class GuiBottler extends GuiForestryTitled } } } + + @Override + protected void addLedgers() { + addErrorLedger(tile); + addHintLedger("bottler"); + addPowerLedger(tile.getEnergyManager()); + } } diff --git a/src/main/java/forestry/factory/gui/GuiCarpenter.java b/src/main/java/forestry/factory/gui/GuiCarpenter.java index ec6915eac..f359f5a53 100755 --- a/src/main/java/forestry/factory/gui/GuiCarpenter.java +++ b/src/main/java/forestry/factory/gui/GuiCarpenter.java @@ -16,20 +16,28 @@ import forestry.core.gui.widgets.TankWidget; import forestry.factory.tiles.TileCarpenter; import net.minecraft.entity.player.InventoryPlayer; -public class GuiCarpenter extends GuiForestryTitled { +public class GuiCarpenter extends GuiForestryTitled { + private final TileCarpenter tile; public GuiCarpenter(InventoryPlayer inventory, TileCarpenter tile) { super(Constants.TEXTURE_PATH_GUI + "/carpenter.png", new ContainerCarpenter(inventory, tile), tile); - this.ySize = 218; - widgetManager.add(new TankWidget(this.widgetManager, 150, 17, 0)); + this.tile = tile; + this.ySize = 218; + this.widgetManager.add(new TankWidget(this.widgetManager, 150, 17, 0)); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - int progressScaled = inventory.getProgressScaled(16); + int progressScaled = tile.getProgressScaled(16); drawTexturedModalRect(guiLeft + 98, guiTop + 51 + 16 - progressScaled, 176, 60 + 16 - progressScaled, 4, progressScaled); } + @Override + protected void addLedgers() { + addErrorLedger(tile); + addPowerLedger(tile.getEnergyManager()); + addHintLedger("carpenter"); + } } diff --git a/src/main/java/forestry/factory/gui/GuiCentrifuge.java b/src/main/java/forestry/factory/gui/GuiCentrifuge.java index d5c00408d..292b60d3b 100755 --- a/src/main/java/forestry/factory/gui/GuiCentrifuge.java +++ b/src/main/java/forestry/factory/gui/GuiCentrifuge.java @@ -16,10 +16,12 @@ import forestry.core.gui.widgets.SocketWidget; import forestry.factory.tiles.TileCentrifuge; import net.minecraft.entity.player.InventoryPlayer; -public class GuiCentrifuge extends GuiForestryTitled { +public class GuiCentrifuge extends GuiForestryTitled { + private final TileCentrifuge tile; public GuiCentrifuge(InventoryPlayer inventory, TileCentrifuge tile) { super(Constants.TEXTURE_PATH_GUI + "/centrifugesocket2.png", new ContainerCentrifuge(inventory, tile), tile); + this.tile = tile; widgetManager.add(new SocketWidget(this.widgetManager, 79, 37, tile, 0)); } @@ -27,8 +29,15 @@ public class GuiCentrifuge extends GuiForestryTitled { +public class GuiFabricator extends GuiForestryTitled { + private final TileFabricator tile; public GuiFabricator(InventoryPlayer player, TileFabricator tile) { super(Constants.TEXTURE_PATH_GUI + "/fabricator.png", new ContainerFabricator(player, tile), tile); + this.tile = tile; this.ySize = 211; - widgetManager.add(new ReservoirWidget(this.widgetManager, 26, 48, 0)); + this.widgetManager.add(new ReservoirWidget(this.widgetManager, 26, 48, 0)); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - TileFabricator fabricator = inventory; - int heatScaled = fabricator.getHeatScaled(52); + int heatScaled = tile.getHeatScaled(52); if (heatScaled > 0) { drawTexturedModalRect(guiLeft + 55, guiTop + 17 + 52 - heatScaled, 192, 52 - heatScaled, 4, heatScaled); } - int meltingPointScaled = fabricator.getMeltingPointScaled(52); + int meltingPointScaled = tile.getMeltingPointScaled(52); if (meltingPointScaled > 0) { drawTexturedModalRect(guiLeft + 52, guiTop + 15 + 52 - meltingPointScaled, 196, 0, 10, 5); } } + @Override + protected void addLedgers() { + addErrorLedger(tile); + addPowerLedger(tile.getEnergyManager()); + addHintLedger("fabricator"); + } } diff --git a/src/main/java/forestry/factory/gui/GuiFermenter.java b/src/main/java/forestry/factory/gui/GuiFermenter.java index 9a461a06f..f95b5dd4c 100755 --- a/src/main/java/forestry/factory/gui/GuiFermenter.java +++ b/src/main/java/forestry/factory/gui/GuiFermenter.java @@ -16,10 +16,12 @@ import forestry.core.gui.widgets.TankWidget; import forestry.factory.tiles.TileFermenter; import net.minecraft.entity.player.InventoryPlayer; -public class GuiFermenter extends GuiForestryTitled { +public class GuiFermenter extends GuiForestryTitled { + private final TileFermenter tile; public GuiFermenter(InventoryPlayer inventory, TileFermenter tile) { super(Constants.TEXTURE_PATH_GUI + "/fermenter.png", new ContainerFermenter(inventory, tile), tile); + this.tile = tile; widgetManager.add(new TankWidget(this.widgetManager, 35, 19, 0)); widgetManager.add(new TankWidget(this.widgetManager, 125, 19, 1)); } @@ -29,16 +31,22 @@ public class GuiFermenter extends GuiForestryTitled 0) { drawTexturedModalRect(guiLeft + 98, guiTop + 46 + 17 - fuelRemain, 176, 78 + 17 - fuelRemain, 4, fuelRemain); } // Raw bio mush remaining - int bioRemain = inventory.getFermentationProgressScaled(16); + int bioRemain = tile.getFermentationProgressScaled(16); if (bioRemain > 0) { drawTexturedModalRect(guiLeft + 74, guiTop + 32 + 17 - bioRemain, 176, 60 + 17 - bioRemain, 4, bioRemain); } } + @Override + protected void addLedgers() { + addErrorLedger(tile); + addHintLedger("fermenter"); + addPowerLedger(tile.getEnergyManager()); + } } diff --git a/src/main/java/forestry/factory/gui/GuiMoistener.java b/src/main/java/forestry/factory/gui/GuiMoistener.java index 02c7ad53b..f72203f90 100755 --- a/src/main/java/forestry/factory/gui/GuiMoistener.java +++ b/src/main/java/forestry/factory/gui/GuiMoistener.java @@ -16,10 +16,12 @@ import forestry.core.gui.widgets.TankWidget; import forestry.factory.tiles.TileMoistener; import net.minecraft.entity.player.InventoryPlayer; -public class GuiMoistener extends GuiForestryTitled { +public class GuiMoistener extends GuiForestryTitled { + private final TileMoistener tile; public GuiMoistener(InventoryPlayer inventory, TileMoistener tile) { super(Constants.TEXTURE_PATH_GUI + "/moistener.png", new ContainerMoistener(inventory, tile), tile); + this.tile = tile; widgetManager.add(new TankWidget(this.widgetManager, 16, 16, 0)); } @@ -28,16 +30,21 @@ public class GuiMoistener extends GuiForestryTitled { +public class GuiRaintank extends GuiForestryTitled { + private final TileRaintank tile; public GuiRaintank(InventoryPlayer inventory, TileRaintank tile) { super(Constants.TEXTURE_PATH_GUI + "/raintank.png", new ContainerRaintank(inventory, tile), tile); + this.tile = tile; widgetManager.add(new TankWidget(this.widgetManager, 53, 17, 0)); } @@ -27,9 +29,15 @@ public class GuiRaintank extends GuiForestryTitled { +public class GuiSqueezer extends GuiForestryTitled { + private final TileSqueezer tile; public GuiSqueezer(InventoryPlayer inventory, TileSqueezer tile) { super(Constants.TEXTURE_PATH_GUI + "/squeezersocket.png", new ContainerSqueezer(inventory, tile), tile); + this.tile = tile; widgetManager.add(new TankWidget(this.widgetManager, 122, 18, 0)); widgetManager.add(new SocketWidget(this.widgetManager, 75, 20, tile, 0)); } @Override protected void drawWidgets() { - int progress = inventory.getProgressScaled(43); + int progress = tile.getProgressScaled(43); drawTexturedModalRect(75, 41, 176, 60, progress, 18); super.drawWidgets(); } + @Override + protected void addLedgers() { + addErrorLedger(tile); + addPowerLedger(tile.getEnergyManager()); + addHintLedger("squeezer"); + } } diff --git a/src/main/java/forestry/factory/gui/GuiStill.java b/src/main/java/forestry/factory/gui/GuiStill.java index d807dfedd..3bcd99cc2 100755 --- a/src/main/java/forestry/factory/gui/GuiStill.java +++ b/src/main/java/forestry/factory/gui/GuiStill.java @@ -16,10 +16,12 @@ import forestry.core.gui.widgets.TankWidget; import forestry.factory.tiles.TileStill; import net.minecraft.entity.player.InventoryPlayer; -public class GuiStill extends GuiForestryTitled { +public class GuiStill extends GuiForestryTitled { + private final TileStill tile; public GuiStill(InventoryPlayer inventory, TileStill tile) { super(Constants.TEXTURE_PATH_GUI + "/still.png", new ContainerStill(inventory, tile), tile); + this.tile = tile; widgetManager.add(new TankWidget(this.widgetManager, 35, 15, 0)); widgetManager.add(new TankWidget(this.widgetManager, 125, 15, 1)); } @@ -27,14 +29,19 @@ public class GuiStill extends GuiForestryTitled { @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - TileStill still = inventory; drawTexturedModalRect(guiLeft + 81, guiTop + 57, 176, 60, 14, 14); - if (still.getWorkCounter() > 0) { - int massRemaining = still.getProgressScaled(16); + if (tile.getWorkCounter() > 0) { + int massRemaining = tile.getProgressScaled(16); drawTexturedModalRect(guiLeft + 84, guiTop + 17 + massRemaining, 176, 74 + massRemaining, 4, 17 - massRemaining); } } + @Override + protected void addLedgers() { + addErrorLedger(tile); + addHintLedger("still"); + addPowerLedger(tile.getEnergyManager()); + } } diff --git a/src/main/java/forestry/factory/gui/GuiWorktable.java b/src/main/java/forestry/factory/gui/GuiWorktable.java index 96672bfa3..c02d329f0 100755 --- a/src/main/java/forestry/factory/gui/GuiWorktable.java +++ b/src/main/java/forestry/factory/gui/GuiWorktable.java @@ -23,14 +23,17 @@ import forestry.factory.tiles.TileWorktable; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; -public class GuiWorktable extends GuiForestryTitled { +public class GuiWorktable extends GuiForestryTitled { private static final int SPACING = 18; + + private final TileWorktable tile; private boolean hasRecipeConflict = false; public GuiWorktable(EntityPlayer player, TileWorktable tile) { super(Constants.TEXTURE_PATH_GUI + "/worktable2.png", new ContainerWorktable(player, tile), tile); + this.tile = tile; - ySize = 218; + this.ySize = 218; RecipeMemory recipeMemory = tile.getMemory(); @@ -51,8 +54,8 @@ public class GuiWorktable extends GuiForestryTitled getGuiExtraAreas(GuiForestry guiContainer) { - return ((GuiForestry) guiContainer).getExtraGuiAreas(); + return ((GuiForestry) guiContainer).getExtraGuiAreas(); } @Nullable diff --git a/src/main/java/forestry/factory/tiles/TileBottler.java b/src/main/java/forestry/factory/tiles/TileBottler.java index 3bf5f6ac2..fdd9ea9b0 100644 --- a/src/main/java/forestry/factory/tiles/TileBottler.java +++ b/src/main/java/forestry/factory/tiles/TileBottler.java @@ -63,7 +63,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid public boolean isFillRecipe; public TileBottler() { - super("bottler", 1100, 4000); + super(1100, 4000); setInternalInventory(new InventoryBottler(this)); diff --git a/src/main/java/forestry/factory/tiles/TileCarpenter.java b/src/main/java/forestry/factory/tiles/TileCarpenter.java index 325e1d2fc..6f82ce400 100644 --- a/src/main/java/forestry/factory/tiles/TileCarpenter.java +++ b/src/main/java/forestry/factory/tiles/TileCarpenter.java @@ -63,7 +63,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu } public TileCarpenter() { - super("carpenter", 1100, 4000); + super(1100, 4000); setEnergyPerWorkCycle(ENERGY_PER_WORK_CYCLE); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY).setFilters(CarpenterRecipeManager.getRecipeFluids()); diff --git a/src/main/java/forestry/factory/tiles/TileCentrifuge.java b/src/main/java/forestry/factory/tiles/TileCentrifuge.java index b22359828..d5b0a8fa0 100644 --- a/src/main/java/forestry/factory/tiles/TileCentrifuge.java +++ b/src/main/java/forestry/factory/tiles/TileCentrifuge.java @@ -55,7 +55,7 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn private final Stack pendingProducts = new Stack<>(); public TileCentrifuge() { - super("centrifuge", 800, Constants.MACHINE_MAX_ENERGY); + super(800, Constants.MACHINE_MAX_ENERGY); setInternalInventory(new InventoryCentrifuge(this)); craftPreviewInventory = new InventoryCraftResult(); } diff --git a/src/main/java/forestry/factory/tiles/TileFabricator.java b/src/main/java/forestry/factory/tiles/TileFabricator.java index 011a74f34..3478a7425 100644 --- a/src/main/java/forestry/factory/tiles/TileFabricator.java +++ b/src/main/java/forestry/factory/tiles/TileFabricator.java @@ -61,7 +61,7 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I private int meltingPoint = 0; public TileFabricator() { - super("fabricator", 1100, 3300); + super(1100, 3300); setEnergyPerWorkCycle(200); craftingInventory = new InventoryGhostCrafting<>(this, InventoryGhostCrafting.SLOT_CRAFTING_COUNT); setInternalInventory(new InventoryFabricator(this)); diff --git a/src/main/java/forestry/factory/tiles/TileFermenter.java b/src/main/java/forestry/factory/tiles/TileFermenter.java index 8fc911195..6c01f590f 100644 --- a/src/main/java/forestry/factory/tiles/TileFermenter.java +++ b/src/main/java/forestry/factory/tiles/TileFermenter.java @@ -58,7 +58,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu private int fuelCurrentFerment = 0; public TileFermenter() { - super("fermenter", 2000, 8000); + super(2000, 8000); setEnergyPerWorkCycle(4200); setInternalInventory(new InventoryFermenter(this)); diff --git a/src/main/java/forestry/factory/tiles/TileMillRainmaker.java b/src/main/java/forestry/factory/tiles/TileMillRainmaker.java index c9bcebccf..dd5035211 100644 --- a/src/main/java/forestry/factory/tiles/TileMillRainmaker.java +++ b/src/main/java/forestry/factory/tiles/TileMillRainmaker.java @@ -28,7 +28,6 @@ public class TileMillRainmaker extends TileMill { private boolean reverse; public TileMillRainmaker() { - super(null); speed = 0.01f; setInternalInventory(new InventoryRainmaker(this)); } diff --git a/src/main/java/forestry/factory/tiles/TileMoistener.java b/src/main/java/forestry/factory/tiles/TileMoistener.java index 17816f188..ea68d1868 100644 --- a/src/main/java/forestry/factory/tiles/TileMoistener.java +++ b/src/main/java/forestry/factory/tiles/TileMoistener.java @@ -62,7 +62,6 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT private ItemStack pendingProduct; public TileMoistener() { - super("moistener"); setInternalInventory(new InventoryMoistener(this)); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY).setFilters(FluidRegistry.WATER); tankManager = new TankManager(this, resourceTank); diff --git a/src/main/java/forestry/factory/tiles/TileRaintank.java b/src/main/java/forestry/factory/tiles/TileRaintank.java index f60bac979..13c18dc5c 100644 --- a/src/main/java/forestry/factory/tiles/TileRaintank.java +++ b/src/main/java/forestry/factory/tiles/TileRaintank.java @@ -60,7 +60,6 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa private int fillingProgress; public TileRaintank() { - super("raintank"); setInternalInventory(new InventoryRaintank(this)); resourceTank = new FilteredTank(Constants.RAINTANK_TANK_CAPACITY).setFilters(FluidRegistry.WATER); diff --git a/src/main/java/forestry/factory/tiles/TileSqueezer.java b/src/main/java/forestry/factory/tiles/TileSqueezer.java index 0e8d9ea4b..17f3efd78 100644 --- a/src/main/java/forestry/factory/tiles/TileSqueezer.java +++ b/src/main/java/forestry/factory/tiles/TileSqueezer.java @@ -59,7 +59,7 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve private ISqueezerRecipe currentRecipe; public TileSqueezer() { - super("squeezer", 1100, Constants.MACHINE_MAX_ENERGY); + super(1100, Constants.MACHINE_MAX_ENERGY); this.inventory = new InventorySqueezer(this); setInternalInventory(this.inventory); this.productTank = new StandardTank(Constants.PROCESSOR_TANK_CAPACITY, false, true); diff --git a/src/main/java/forestry/factory/tiles/TileStill.java b/src/main/java/forestry/factory/tiles/TileStill.java index 9387fde4e..c7561e288 100644 --- a/src/main/java/forestry/factory/tiles/TileStill.java +++ b/src/main/java/forestry/factory/tiles/TileStill.java @@ -50,7 +50,7 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa private FluidStack bufferedLiquid; public TileStill() { - super("still", 1100, 8000); + super(1100, 8000); setInternalInventory(new InventoryStill(this)); resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, true, false); resourceTank.setFilters(StillRecipeManager.recipeFluidInputs); diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/factory/tiles/TileWorktable.java index 6d5a707e6..4b8f0c88b 100644 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/factory/tiles/TileWorktable.java @@ -45,7 +45,6 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { private MemorizedRecipe currentRecipe; public TileWorktable() { - super("worktable"); setInternalInventory(new InventoryWorktable(this)); craftingDisplay = new InventoryGhostCrafting<>(this, 10); diff --git a/src/main/java/forestry/farming/gui/GuiFarm.java b/src/main/java/forestry/farming/gui/GuiFarm.java index f03291892..f735f20db 100755 --- a/src/main/java/forestry/farming/gui/GuiFarm.java +++ b/src/main/java/forestry/farming/gui/GuiFarm.java @@ -13,23 +13,24 @@ package forestry.farming.gui; import forestry.api.farming.FarmDirection; import forestry.core.config.Constants; import forestry.core.gui.GuiForestryTitled; -import forestry.core.gui.ledgers.ClimateLedger; import forestry.core.gui.widgets.SocketWidget; import forestry.core.gui.widgets.TankWidget; import forestry.farming.multiblock.IFarmControllerInternal; import forestry.farming.tiles.TileFarm; import net.minecraft.entity.player.EntityPlayer; -public class GuiFarm extends GuiForestryTitled { +public class GuiFarm extends GuiForestryTitled { + private final TileFarm tile; public GuiFarm(EntityPlayer player, TileFarm tile) { super(Constants.TEXTURE_PATH_GUI + "/mfarm.png", new ContainerFarm(player.inventory, tile), tile); + this.tile = tile; widgetManager.add(new TankWidget(widgetManager, 15, 19, 0).setOverlayOrigin(216, 18)); widgetManager.add(new SocketWidget(widgetManager, 69, 40, tile, 0)); - IFarmControllerInternal farmController = inventory.getMultiblockLogic().getController(); + IFarmControllerInternal farmController = tile.getMultiblockLogic().getController(); widgetManager.add(new FarmLogicSlot(farmController, widgetManager, 69, 22, FarmDirection.NORTH)); widgetManager.add(new FarmLogicSlot(farmController, widgetManager, 69, 58, FarmDirection.SOUTH)); @@ -42,10 +43,12 @@ public class GuiFarm extends GuiForestryTitled { @Override protected void addLedgers() { - IFarmControllerInternal farmController = inventory.getMultiblockLogic().getController(); - ledgerManager.add(new ClimateLedger(ledgerManager, farmController)); + IFarmControllerInternal farmController = tile.getMultiblockLogic().getController(); + + addErrorLedger(farmController); + addClimateLedger(farmController); ledgerManager.add(new FarmLedger(ledgerManager, farmController.getFarmLedgerDelegate())); - super.addLedgers(); + addHintLedger("farm"); } @Override @@ -53,7 +56,7 @@ public class GuiFarm extends GuiForestryTitled { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); // Fuel remaining - int fertilizerRemain = inventory.getMultiblockLogic().getController().getStoredFertilizerScaled(16); + int fertilizerRemain = tile.getMultiblockLogic().getController().getStoredFertilizerScaled(16); if (fertilizerRemain > 0) { drawTexturedModalRect(guiLeft + 81, guiTop + 94 + 17 - fertilizerRemain, xSize, 17 - fertilizerRemain, 4, fertilizerRemain); } diff --git a/src/main/java/forestry/farming/tiles/TileFarm.java b/src/main/java/forestry/farming/tiles/TileFarm.java index b4ddac1fc..15d4f2f1a 100644 --- a/src/main/java/forestry/farming/tiles/TileFarm.java +++ b/src/main/java/forestry/farming/tiles/TileFarm.java @@ -11,7 +11,6 @@ package forestry.farming.tiles; import java.io.IOException; -import java.util.List; import forestry.api.circuits.ICircuitSocketType; import forestry.api.core.IErrorLogic; @@ -19,8 +18,6 @@ import forestry.api.core.IErrorLogicSource; import forestry.api.multiblock.IFarmComponent; import forestry.api.multiblock.IMultiblockController; import forestry.core.circuits.ISocketable; -import forestry.core.config.Config; -import forestry.core.gui.IHintSource; import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.MultiblockTileEntityForestry; import forestry.core.network.IStreamableGui; @@ -40,7 +37,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public abstract class TileFarm extends MultiblockTileEntityForestry implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled { +public abstract class TileFarm extends MultiblockTileEntityForestry implements IFarmComponent, ISocketable, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled { private EnumFarmBlockTexture farmBlockTexture = EnumFarmBlockTexture.BRICK_STONE; protected TileFarm() { @@ -115,12 +112,6 @@ public abstract class TileFarm extends MultiblockTileEntityForestry getHints() { - return Config.hints.get("farm"); - } - /* ISocketable */ @Override public int getSocketCount() { diff --git a/src/main/java/forestry/food/gui/GuiInfuser.java b/src/main/java/forestry/food/gui/GuiInfuser.java index ce67bf54e..3792f5cd5 100755 --- a/src/main/java/forestry/food/gui/GuiInfuser.java +++ b/src/main/java/forestry/food/gui/GuiInfuser.java @@ -17,24 +17,25 @@ import forestry.core.render.ColourProperties; import forestry.food.inventory.ItemInventoryInfuser; import net.minecraft.entity.player.InventoryPlayer; -public class GuiInfuser extends GuiForestry { - +public class GuiInfuser extends GuiForestry { + private final ItemInventoryInfuser itemInventory; private int startX; private int startY; - public GuiInfuser(InventoryPlayer inventoryplayer, ItemInventoryInfuser inventory) { - super(Constants.TEXTURE_PATH_GUI + "/infuser.png", new ContainerInfuser(inventoryplayer, inventory), inventory); + public GuiInfuser(InventoryPlayer inventoryplayer, ItemInventoryInfuser itemInventory) { + super(Constants.TEXTURE_PATH_GUI + "/infuser.png", new ContainerInfuser(inventoryplayer, itemInventory)); - xSize = 176; - ySize = 185; + this.itemInventory = itemInventory; + this.xSize = 176; + this.ySize = 185; } @Override protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) { super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY); - for (int l = 2; l < inventory.getSizeInventory(); l++) { - String description = BeverageManager.ingredientManager.getDescription(inventory.getStackInSlot(l)); + for (int l = 2; l < itemInventory.getSizeInventory(); l++) { + String description = BeverageManager.ingredientManager.getDescription(itemInventory.getStackInSlot(l)); if (description == null) { description = "(No effect)"; } @@ -51,4 +52,9 @@ public class GuiInfuser extends GuiForestry { +public class GuiGreenhouse extends GuiForestryTitled { private static final Predicate numberFilter = text -> { if (text == null) { @@ -51,23 +50,26 @@ public class GuiGreenhouse extends GuiForestryTitled= 0.0F; }; + + private final TileGreenhouse tile; private GuiTextField humidityField; private GuiTextField temperatureField; private boolean fieldsEnabeled; public GuiGreenhouse(EntityPlayer player, TileGreenhouse tile) { super(Constants.TEXTURE_PATH_GUI + "/greenhouse.png", new ContainerGreenhouse(player.inventory, tile), tile); + this.tile = tile; //Add the water tank widgetManager.add(new TankWidget(widgetManager, 152, 16, 0).setOverlayOrigin(176, 0)); //Add the multiblock camouflage tabs WidgetCamouflageTab previous; int x = 3; - widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, inventory.getMultiblockLogic().getController(), tile, CamouflageManager.BLOCK)); + widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, tile.getMultiblockLogic().getController(), tile, CamouflageManager.BLOCK)); x+=50 + (previous.getHandlerSlot() != null ? 20 : 0); - widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, inventory.getMultiblockLogic().getController(), tile, CamouflageManager.GLASS)); + widgetManager.add(previous = new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, tile.getMultiblockLogic().getController(), tile, CamouflageManager.GLASS)); x+=50 + (previous.getHandlerSlot() != null ? 20 : 0); - widgetManager.add(new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, inventory.getMultiblockLogic().getController(), tile, CamouflageManager.DOOR)); + widgetManager.add(new WidgetCamouflageTab(widgetManager, guiLeft + x, guiTop - 25, tile.getMultiblockLogic().getController(), tile, CamouflageManager.DOOR)); widgetManager.add(new WidgetClimatePillar(widgetManager, guiLeft- 23, guiTop + 5)); @@ -87,7 +89,7 @@ public class GuiGreenhouse extends GuiForestryTitled { +public class GuiGreenhouseButterflyHatch extends GuiForestryTitled { + private final TileGreenhouseButterflyHatch tile; public GuiGreenhouseButterflyHatch(EntityPlayer player, TileGreenhouseButterflyHatch tile) { super(Constants.TEXTURE_PATH_GUI + "/greenhouse_butterfly_hatch.png", new ContainerGreenhouseButterflyHatch(player.inventory, tile), tile); + this.tile = tile; + //Add the tile camouflage slots - widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 17, inventory, tile.getCamouflageType())); + widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 17, tile, tile.getCamouflageType())); } @Override protected void addLedgers() { - IGreenhouseControllerInternal greenhouseController = inventory.getMultiblockLogic().getController(); + IGreenhouseControllerInternal greenhouseController = tile.getMultiblockLogic().getController(); - ledgerManager.add(new ClimateLedger(ledgerManager, greenhouseController)); - super.addLedgers(); + addErrorLedger(greenhouseController); + addClimateLedger(greenhouseController); + addOwnerLedger(greenhouseController); } } diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java index 77d77aa70..2a42d79b4 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouse.java @@ -11,7 +11,6 @@ package forestry.greenhouse.tiles; import java.io.IOException; -import java.util.List; import forestry.api.core.CamouflageManager; import forestry.api.core.ICamouflageHandler; @@ -21,8 +20,6 @@ import forestry.api.core.IErrorLogicSource; import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent; import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IMultiblockController; -import forestry.core.config.Config; -import forestry.core.gui.IHintSource; import forestry.core.inventory.IInventoryAdapter; import forestry.core.multiblock.MultiblockTileEntityForestry; import forestry.core.network.IStreamableGui; @@ -48,7 +45,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; -public abstract class TileGreenhouse extends MultiblockTileEntityForestry implements IGreenhouseComponent, IHintSource, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled, ICamouflageHandler, ICamouflagedTile { +public abstract class TileGreenhouse extends MultiblockTileEntityForestry implements IGreenhouseComponent, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled, ICamouflageHandler, ICamouflagedTile { protected ItemStack camouflageBlock; protected TileGreenhouse() { @@ -147,12 +144,6 @@ public abstract class TileGreenhouse extends MultiblockTileEntityForestry getHints() { - return Config.hints.get("greenhouse"); - } - /* IErrorLogicSource */ @Override public IErrorLogic getErrorLogic() { diff --git a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHatch.java b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHatch.java index 3973746c5..83dfa6b15 100644 --- a/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHatch.java +++ b/src/main/java/forestry/greenhouse/tiles/TileGreenhouseHatch.java @@ -12,7 +12,6 @@ package forestry.greenhouse.tiles; import javax.annotation.Nullable; import java.io.IOException; -import java.util.List; import com.mojang.authlib.GameProfile; import forestry.api.core.CamouflageManager; @@ -24,8 +23,6 @@ import forestry.api.greenhouse.GreenhouseEvents.CamouflageChangeEvent; import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IMultiblockController; import forestry.api.multiblock.MultiblockTileEntityBase; -import forestry.core.config.Config; -import forestry.core.gui.IHintSource; import forestry.core.network.IStreamableGui; import forestry.core.network.PacketBufferForestry; import forestry.core.network.packets.CamouflageSelectionType; @@ -49,7 +46,7 @@ import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.items.CapabilityItemHandler; -public class TileGreenhouseHatch extends MultiblockTileEntityBase implements IGreenhouseComponent, IStreamableGui, IHintSource, IErrorLogicSource, IOwnedTile, ICamouflageHandler, ICamouflagedTile { +public class TileGreenhouseHatch extends MultiblockTileEntityBase implements IGreenhouseComponent, IStreamableGui, IErrorLogicSource, IOwnedTile, ICamouflageHandler, ICamouflagedTile { @Nullable private EnumFacing outwards; @@ -189,12 +186,6 @@ public class TileGreenhouseHatch extends MultiblockTileEntityBase getHints() { - return Config.hints.get("greenhouse"); - } - /* IErrorLogicSource */ @Override public IErrorLogic getErrorLogic() { diff --git a/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java b/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java index 5ce2a3966..67df3d5ee 100644 --- a/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java +++ b/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java @@ -39,7 +39,9 @@ import forestry.core.genetics.SpeciesRoot; import forestry.core.utils.BlockUtil; import forestry.core.utils.EntityUtil; import forestry.lepidopterology.PluginLepidopterology; +import forestry.lepidopterology.blocks.BlockRegistryLepidopterology; import forestry.lepidopterology.entities.EntityButterfly; +import forestry.lepidopterology.items.ItemRegistryLepidopterology; import forestry.lepidopterology.tiles.TileCocoon; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -96,14 +98,17 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot { return null; } + ItemRegistryLepidopterology butterflyItems = PluginLepidopterology.items; + Preconditions.checkState(butterflyItems != null); + Item item = stack.getItem(); - if (PluginLepidopterology.items.butterflyGE == item) { + if (butterflyItems.butterflyGE == item) { return EnumFlutterType.BUTTERFLY; - } else if (PluginLepidopterology.items.serumGE == item) { + } else if (butterflyItems.serumGE == item) { return EnumFlutterType.SERUM; - } else if (PluginLepidopterology.items.caterpillarGE == item) { + } else if (butterflyItems.caterpillarGE == item) { return EnumFlutterType.CATERPILLAR; - } else if (PluginLepidopterology.items.cocoonGE == item) { + } else if (butterflyItems.cocoonGE == item) { return EnumFlutterType.COCOON; } else { return null; @@ -127,8 +132,9 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot { @Override public IButterfly getMember(ItemStack stack) { - Preconditions.checkArgument(isMember(stack)); - Preconditions.checkArgument(stack.getTagCompound() != null); + if (!isMember(stack) || stack.getTagCompound() == null) { + return null; + } return new Butterfly(stack.getTagCompound()); } @@ -141,21 +147,23 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot { @Override public ItemStack getMemberStack(IIndividual butterfly, ISpeciesType type) { Preconditions.checkArgument(type instanceof EnumFlutterType); + ItemRegistryLepidopterology items = PluginLepidopterology.items; + Preconditions.checkState(items != null); Item butterflyItem; switch ((EnumFlutterType) type) { case SERUM: - butterflyItem = PluginLepidopterology.items.serumGE; + butterflyItem = items.serumGE; break; case CATERPILLAR: - butterflyItem = PluginLepidopterology.items.caterpillarGE; + butterflyItem = items.caterpillarGE; break; case COCOON: - butterflyItem = PluginLepidopterology.items.cocoonGE; + butterflyItem = items.cocoonGE; break; case BUTTERFLY: default: - butterflyItem = PluginLepidopterology.items.butterflyGE; + butterflyItem = items.butterflyGE; break; } @@ -178,15 +186,18 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot { return false; } + BlockRegistryLepidopterology blocks = PluginLepidopterology.blocks; + Preconditions.checkState(blocks != null); + BlockPos pos = getNextPos(world, nursery.getCoordinates()); - IBlockState state = PluginLepidopterology.blocks.cocoon.getDefaultState(); + IBlockState state = blocks.cocoon.getDefaultState(); boolean placed = world.setBlockState(pos, state); if (!placed) { return false; } Block block = world.getBlockState(pos).getBlock(); - if (PluginLepidopterology.blocks.cocoon != block) { + if (blocks.cocoon != block) { return false; } @@ -218,7 +229,7 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot { @Override public boolean isMated(ItemStack stack) { IButterfly butterfly = getMember(stack); - return butterfly.getMate() != null; + return butterfly != null && butterfly.getMate() != null; } /* GENOME CONVERSIONS */ diff --git a/src/main/java/forestry/mail/MailAddress.java b/src/main/java/forestry/mail/MailAddress.java index 7d6e541ad..792d418f1 100644 --- a/src/main/java/forestry/mail/MailAddress.java +++ b/src/main/java/forestry/mail/MailAddress.java @@ -63,6 +63,9 @@ public class MailAddress implements INbtWritable, IMailAddress { } else if (nbt.hasKey("profile")) { NBTTagCompound profileTag = nbt.getCompoundTag("profile"); gameProfile = PlayerUtil.readGameProfileFromNBT(profileTag); + if (gameProfile == null) { + gameProfile = invalidGameProfile; + } } this.type = type; @@ -87,7 +90,7 @@ public class MailAddress implements INbtWritable, IMailAddress { @Override public GameProfile getPlayerProfile() { if (this.type != EnumAddressee.PLAYER) { - return null; + return invalidGameProfile; } return gameProfile; } diff --git a/src/main/java/forestry/mail/gui/ContainerLetter.java b/src/main/java/forestry/mail/gui/ContainerLetter.java index eac2b54fa..ca0d6e8d0 100755 --- a/src/main/java/forestry/mail/gui/ContainerLetter.java +++ b/src/main/java/forestry/mail/gui/ContainerLetter.java @@ -65,11 +65,9 @@ public class ContainerLetter extends ContainerItemInventory // Set recipient type ILetter letter = inventory.getLetter(); - if (letter != null) { - IMailAddress recipient = letter.getRecipient(); - if (recipient != null) { - this.carrierType = recipient.getType(); - } + IMailAddress recipient = letter.getRecipient(); + if (recipient != null) { + this.carrierType = recipient.getType(); } } diff --git a/src/main/java/forestry/mail/gui/GuiCatalogue.java b/src/main/java/forestry/mail/gui/GuiCatalogue.java index e9bfb70b4..41e736f47 100755 --- a/src/main/java/forestry/mail/gui/GuiCatalogue.java +++ b/src/main/java/forestry/mail/gui/GuiCatalogue.java @@ -23,13 +23,12 @@ import forestry.core.render.ColourProperties; import forestry.core.utils.Translator; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextFormatting; import org.lwjgl.input.Keyboard; -public class GuiCatalogue extends GuiForestry { +public class GuiCatalogue extends GuiForestry { private static final String boldUnderline = TextFormatting.BOLD.toString() + TextFormatting.UNDERLINE; @@ -39,7 +38,7 @@ public class GuiCatalogue extends GuiForestry { private final List tradeInfoWidgets = new ArrayList<>(); public GuiCatalogue(EntityPlayer player) { - super(new ResourceLocation("textures/gui/book.png"), new ContainerCatalogue(player), null); + super(new ResourceLocation("textures/gui/book.png"), new ContainerCatalogue(player)); this.xSize = 192; this.ySize = 192; @@ -154,4 +153,9 @@ public class GuiCatalogue extends GuiForestry { break; } } + + @Override + protected void addLedgers() { + + } } diff --git a/src/main/java/forestry/mail/gui/GuiLetter.java b/src/main/java/forestry/mail/gui/GuiLetter.java index e9abe4b27..6cd9d4546 100755 --- a/src/main/java/forestry/mail/gui/GuiLetter.java +++ b/src/main/java/forestry/mail/gui/GuiLetter.java @@ -31,8 +31,8 @@ import net.minecraft.entity.player.EntityPlayer; import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Keyboard; -public class GuiLetter extends GuiForestry { - +public class GuiLetter extends GuiForestry { + private final ItemInventoryLetter itemInventory; private final boolean isProcessedLetter; private boolean checkedSessionVars; @@ -44,8 +44,10 @@ public class GuiLetter extends GuiForestry private final ArrayList tradeInfoWidgets; - public GuiLetter(EntityPlayer player, ItemInventoryLetter inventory) { - super(Constants.TEXTURE_PATH_GUI + "/letter.png", new ContainerLetter(player, inventory), inventory); + public GuiLetter(EntityPlayer player, ItemInventoryLetter itemInventory) { + super(Constants.TEXTURE_PATH_GUI + "/letter.png", new ContainerLetter(player, itemInventory)); + + this.itemInventory = itemInventory; this.xSize = 194; this.ySize = 227; @@ -244,4 +246,9 @@ public class GuiLetter extends GuiForestry container.setText(this.text.getText()); } + @Override + protected void addLedgers() { + addErrorLedger(itemInventory); + addHintLedger("letter"); + } } diff --git a/src/main/java/forestry/mail/gui/GuiMailbox.java b/src/main/java/forestry/mail/gui/GuiMailbox.java index e9f1e88f3..540af363d 100755 --- a/src/main/java/forestry/mail/gui/GuiMailbox.java +++ b/src/main/java/forestry/mail/gui/GuiMailbox.java @@ -15,11 +15,19 @@ import forestry.core.gui.GuiForestry; import forestry.mail.tiles.TileMailbox; import net.minecraft.entity.player.InventoryPlayer; -public class GuiMailbox extends GuiForestry { +public class GuiMailbox extends GuiForestry { + private final TileMailbox tile; public GuiMailbox(InventoryPlayer player, TileMailbox tile) { - super(Constants.TEXTURE_PATH_GUI + "/mailbox.png", new ContainerMailbox(player, tile), tile); + super(Constants.TEXTURE_PATH_GUI + "/mailbox.png", new ContainerMailbox(player, tile)); + this.tile = tile; this.xSize = 230; this.ySize = 227; } + + @Override + protected void addLedgers() { + addErrorLedger(tile); + addHintLedger("mailbox"); + } } diff --git a/src/main/java/forestry/mail/gui/GuiStampCollector.java b/src/main/java/forestry/mail/gui/GuiStampCollector.java index 134032e4a..18ef023e9 100644 --- a/src/main/java/forestry/mail/gui/GuiStampCollector.java +++ b/src/main/java/forestry/mail/gui/GuiStampCollector.java @@ -15,10 +15,19 @@ import forestry.core.gui.GuiForestry; import forestry.mail.tiles.TileStampCollector; import net.minecraft.entity.player.InventoryPlayer; -public class GuiStampCollector extends GuiForestry { +public class GuiStampCollector extends GuiForestry { + private final TileStampCollector tile; + public GuiStampCollector(InventoryPlayer player, TileStampCollector tile) { - super(Constants.TEXTURE_PATH_GUI + "/philatelist.png", new ContainerStampCollector(player, tile), tile); + super(Constants.TEXTURE_PATH_GUI + "/philatelist.png", new ContainerStampCollector(player, tile)); + this.tile = tile; this.xSize = 176; this.ySize = 193; } + + @Override + protected void addLedgers() { + addErrorLedger(tile); + addHintLedger("philatelist"); + } } diff --git a/src/main/java/forestry/mail/gui/GuiTradeName.java b/src/main/java/forestry/mail/gui/GuiTradeName.java index e340fea6b..9231b58c8 100755 --- a/src/main/java/forestry/mail/gui/GuiTradeName.java +++ b/src/main/java/forestry/mail/gui/GuiTradeName.java @@ -23,11 +23,13 @@ import net.minecraft.client.gui.GuiTextField; import org.apache.commons.lang3.StringUtils; import org.lwjgl.input.Keyboard; -public class GuiTradeName extends GuiForestry { +public class GuiTradeName extends GuiForestry { + private final TileTrader tile; private GuiTextField addressNameField; public GuiTradeName(TileTrader tile) { - super(Constants.TEXTURE_PATH_GUI + "/tradername.png", new ContainerTradeName(tile), tile); + super(Constants.TEXTURE_PATH_GUI + "/tradername.png", new ContainerTradeName(tile)); + this.tile = tile; this.xSize = 176; this.ySize = 90; @@ -86,9 +88,13 @@ public class GuiTradeName extends GuiForestry { private void setAddress() { String address = addressNameField.getText(); if (StringUtils.isNotBlank(address)) { - PacketTraderAddressRequest packet = new PacketTraderAddressRequest(inventory, address); + PacketTraderAddressRequest packet = new PacketTraderAddressRequest(tile, address); Proxies.net.sendToServer(packet); } } + @Override + protected void addLedgers() { + addErrorLedger(tile); + } } diff --git a/src/main/java/forestry/mail/gui/GuiTrader.java b/src/main/java/forestry/mail/gui/GuiTrader.java index b71769453..3994a8921 100755 --- a/src/main/java/forestry/mail/gui/GuiTrader.java +++ b/src/main/java/forestry/mail/gui/GuiTrader.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.mail.gui; -import com.google.common.base.Preconditions; import forestry.core.config.Constants; import forestry.core.gui.GuiForestry; import forestry.core.render.ColourProperties; @@ -18,18 +17,19 @@ import forestry.core.utils.Translator; import forestry.mail.tiles.TileTrader; import net.minecraft.entity.player.InventoryPlayer; -public class GuiTrader extends GuiForestry { +public class GuiTrader extends GuiForestry { + private final TileTrader tile; public GuiTrader(InventoryPlayer inventoryplayer, TileTrader tile) { - super(Constants.TEXTURE_PATH_GUI + "/mailtrader2.png", new ContainerTrader(inventoryplayer, tile), tile); + super(Constants.TEXTURE_PATH_GUI + "/mailtrader2.png", new ContainerTrader(inventoryplayer, tile)); + this.tile = tile; this.xSize = 226; this.ySize = 220; } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - Preconditions.checkState(inventory != null); - String name = Translator.translateToLocal(inventory.getUnlocalizedTitle()); + String name = Translator.translateToLocal(tile.getUnlocalizedTitle()); this.fontRendererObj.drawString(name, textLayout.getCenteredOffset(name), 6, ColourProperties.INSTANCE.get("gui.mail.text")); String receive = Translator.translateToLocal("for.gui.mail.receive"); @@ -47,4 +47,11 @@ public class GuiTrader extends GuiForestry { fontRendererObj.drawString(container.getAddress().getName(), guiLeft + 19, guiTop + 22, ColourProperties.INSTANCE.get("gui.mail.text")); } + + @Override + protected void addLedgers() { + addErrorLedger(tile); + addHintLedger("trade.station"); + addOwnerLedger(tile); + } } diff --git a/src/main/java/forestry/mail/inventory/ItemInventoryLetter.java b/src/main/java/forestry/mail/inventory/ItemInventoryLetter.java index c6641ce59..6b2105c87 100644 --- a/src/main/java/forestry/mail/inventory/ItemInventoryLetter.java +++ b/src/main/java/forestry/mail/inventory/ItemInventoryLetter.java @@ -10,16 +10,12 @@ ******************************************************************************/ package forestry.mail.inventory; -import java.util.List; - import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import forestry.api.core.IErrorSource; import forestry.api.core.IErrorState; import forestry.api.mail.ILetter; -import forestry.core.config.Config; import forestry.core.errors.EnumErrorCode; -import forestry.core.gui.IHintSource; import forestry.core.inventory.ItemInventory; import forestry.core.items.ItemWithGui; import forestry.core.utils.SlotUtil; @@ -31,7 +27,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -public class ItemInventoryLetter extends ItemInventory implements IErrorSource, IHintSource { +public class ItemInventoryLetter extends ItemInventory implements IErrorSource { private final ILetter letter; public ItemInventoryLetter(EntityPlayer player, ItemStack itemstack) { @@ -131,11 +127,4 @@ public class ItemInventoryLetter extends ItemInventory implements IErrorSource, return errorStates.build(); } - - /* IHintSource */ - @Override - public List getHints() { - return Config.hints.get("letter"); - } - } diff --git a/src/main/java/forestry/mail/network/packets/PacketLetterInfoResponse.java b/src/main/java/forestry/mail/network/packets/PacketLetterInfoResponse.java index a16652013..07512fea9 100644 --- a/src/main/java/forestry/mail/network/packets/PacketLetterInfoResponse.java +++ b/src/main/java/forestry/mail/network/packets/PacketLetterInfoResponse.java @@ -36,11 +36,12 @@ import net.minecraft.util.NonNullList; // TODO: split this into two different packets public class PacketLetterInfoResponse extends ForestryPacket implements IForestryPacketClient { public final EnumAddressee type; + @Nullable public final ITradeStationInfo tradeInfo; @Nullable public final IMailAddress address; - public PacketLetterInfoResponse(EnumAddressee type, ITradeStationInfo info, @Nullable IMailAddress address) { + public PacketLetterInfoResponse(EnumAddressee type, @Nullable ITradeStationInfo info, @Nullable IMailAddress address) { this.type = type; if (type == EnumAddressee.TRADER) { this.tradeInfo = info; @@ -71,16 +72,21 @@ public class PacketLetterInfoResponse extends ForestryPacket implements IForestr data.writeString(profile.getName()); } else if (type == EnumAddressee.TRADER) { - data.writeString(tradeInfo.getAddress().getName()); + if (tradeInfo == null) { + data.writeBoolean(false); + } else { + data.writeBoolean(true); + data.writeString(tradeInfo.getAddress().getName()); - data.writeLong(tradeInfo.getOwner().getId().getMostSignificantBits()); - data.writeLong(tradeInfo.getOwner().getId().getLeastSignificantBits()); - data.writeString(tradeInfo.getOwner().getName()); + data.writeLong(tradeInfo.getOwner().getId().getMostSignificantBits()); + data.writeLong(tradeInfo.getOwner().getId().getLeastSignificantBits()); + data.writeString(tradeInfo.getOwner().getName()); - data.writeItemStack(tradeInfo.getTradegood()); - data.writeItemStacks(tradeInfo.getRequired()); + data.writeItemStack(tradeInfo.getTradegood()); + data.writeItemStacks(tradeInfo.getRequired()); - data.writeEnum(tradeInfo.getState(), EnumTradeStationState.values()); + data.writeEnum(tradeInfo.getState(), EnumTradeStationState.values()); + } } } @@ -97,14 +103,18 @@ public class PacketLetterInfoResponse extends ForestryPacket implements IForestr GameProfile profile = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readString()); address = PostManager.postRegistry.getMailAddress(profile); } else if (type == EnumAddressee.TRADER) { - address = PostManager.postRegistry.getMailAddress(data.readString()); - GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readString()); + if (data.readBoolean()) { + address = PostManager.postRegistry.getMailAddress(data.readString()); + GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readString()); - ItemStack tradegood = data.readItemStack(); - NonNullList required = data.readItemStacks(); + ItemStack tradegood = data.readItemStack(); + NonNullList required = data.readItemStacks(); - EnumTradeStationState state = data.readEnum(EnumTradeStationState.values()); - tradeInfo = new TradeStationInfo(address, owner, tradegood, required, state); + EnumTradeStationState state = data.readEnum(EnumTradeStationState.values()); + tradeInfo = new TradeStationInfo(address, owner, tradegood, required, state); + } else { + tradeInfo = null; + } } ((ILetterInfoReceiver) container).handleLetterInfoUpdate(type, address, tradeInfo); } diff --git a/src/main/java/forestry/mail/tiles/TileMailbox.java b/src/main/java/forestry/mail/tiles/TileMailbox.java index f463af666..69d485f78 100644 --- a/src/main/java/forestry/mail/tiles/TileMailbox.java +++ b/src/main/java/forestry/mail/tiles/TileMailbox.java @@ -31,7 +31,6 @@ import net.minecraft.world.World; public class TileMailbox extends TileBase { public TileMailbox() { - super("mailbox"); setInternalInventory(new InventoryAdapter(POBox.SLOT_SIZE, "Letters").disableAutomation()); } diff --git a/src/main/java/forestry/mail/tiles/TileStampCollector.java b/src/main/java/forestry/mail/tiles/TileStampCollector.java index b466e1915..265213166 100644 --- a/src/main/java/forestry/mail/tiles/TileStampCollector.java +++ b/src/main/java/forestry/mail/tiles/TileStampCollector.java @@ -24,7 +24,6 @@ import net.minecraft.item.ItemStack; public class TileStampCollector extends TileBase implements IInventory { public TileStampCollector() { - super("philatelist"); setInternalInventory(new InventoryStampCollector(this)); } diff --git a/src/main/java/forestry/mail/tiles/TileTrader.java b/src/main/java/forestry/mail/tiles/TileTrader.java index 55d42dcd2..e935798df 100644 --- a/src/main/java/forestry/mail/tiles/TileTrader.java +++ b/src/main/java/forestry/mail/tiles/TileTrader.java @@ -46,7 +46,6 @@ public class TileTrader extends TileBase implements IOwnedTile { private IMailAddress address; public TileTrader() { - super("trade.station"); address = new MailAddress(); setInternalInventory(new InventoryTradeStation()); } diff --git a/src/main/java/forestry/storage/CrateRegistry.java b/src/main/java/forestry/storage/CrateRegistry.java index 85f8dcbfa..31958b0af 100644 --- a/src/main/java/forestry/storage/CrateRegistry.java +++ b/src/main/java/forestry/storage/CrateRegistry.java @@ -27,7 +27,7 @@ public class CrateRegistry implements ICrateRegistry { private static void registerCrate(ItemStack stack, @Nullable String oreDictName) { if (stack.isEmpty()) { - Log.warning("Tried to make a crate without an item"); + Log.error("Tried to make a crate without an item"); return; } @@ -35,7 +35,12 @@ public class CrateRegistry implements ICrateRegistry { if (oreDictName != null) { crateName = "crated." + oreDictName; } else { - String itemName = ItemStackUtil.getStringForItemStack(stack).replace(':', '.'); + String stringForItemStack = ItemStackUtil.getStringForItemStack(stack); + if (stringForItemStack == null) { + Log.error("Could not get string name for itemStack {}", stack); + return; + } + String itemName = stringForItemStack.replace(':', '.'); crateName = "crated." + itemName; } diff --git a/src/main/java/forestry/storage/gui/GuiBackpack.java b/src/main/java/forestry/storage/gui/GuiBackpack.java index e5a224745..a9951e52e 100755 --- a/src/main/java/forestry/storage/gui/GuiBackpack.java +++ b/src/main/java/forestry/storage/gui/GuiBackpack.java @@ -12,15 +12,19 @@ package forestry.storage.gui; import forestry.core.config.Constants; import forestry.core.gui.GuiForestry; -import net.minecraft.inventory.IInventory; -public class GuiBackpack extends GuiForestry { +public class GuiBackpack extends GuiForestry { public GuiBackpack(ContainerBackpack container) { this(Constants.TEXTURE_PATH_GUI + "/backpack.png", container); } protected GuiBackpack(String texture, ContainerBackpack container) { - super(texture, container, null); + super(texture, container); + } + + @Override + protected void addLedgers() { + } } diff --git a/src/main/java/forestry/storage/inventory/ItemInventoryBackpack.java b/src/main/java/forestry/storage/inventory/ItemInventoryBackpack.java index 8fe819bf8..6541af6ff 100644 --- a/src/main/java/forestry/storage/inventory/ItemInventoryBackpack.java +++ b/src/main/java/forestry/storage/inventory/ItemInventoryBackpack.java @@ -19,10 +19,6 @@ public class ItemInventoryBackpack extends ItemInventory { Preconditions.checkArgument(item instanceof ItemBackpack, "Parent must be a backpack."); this.backpackDefinition = ((ItemBackpack) item).getDefinition(); - - if (this.backpackDefinition == null) { - throw new IllegalArgumentException("Backpack must have a backpack definition."); - } } @Override diff --git a/src/main/java/forestry/storage/items/ItemBackpack.java b/src/main/java/forestry/storage/items/ItemBackpack.java index 53673812b..a3b8ef488 100755 --- a/src/main/java/forestry/storage/items/ItemBackpack.java +++ b/src/main/java/forestry/storage/items/ItemBackpack.java @@ -58,6 +58,9 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem { private final EnumBackpackType type; public ItemBackpack(IBackpackDefinition definition, EnumBackpackType type) { + Preconditions.checkNotNull(definition, "Backpack must have a backpack definition."); + Preconditions.checkNotNull(type, "Backpack must have a backpack type."); + this.definition = definition; this.type = type; } diff --git a/src/main/java/forestry/storage/items/ItemBackpackNaturalist.java b/src/main/java/forestry/storage/items/ItemBackpackNaturalist.java index f0adda877..ad1bd813d 100644 --- a/src/main/java/forestry/storage/items/ItemBackpackNaturalist.java +++ b/src/main/java/forestry/storage/items/ItemBackpackNaturalist.java @@ -38,7 +38,7 @@ public class ItemBackpackNaturalist extends ItemBackpack { public Object getGui(EntityPlayer player, ItemStack heldItem, int page) { ItemInventoryBackpackPaged inventory = new ItemInventoryBackpackPaged(player, Constants.SLOTS_BACKPACK_APIARIST, heldItem, this); ContainerNaturalistBackpack container = new ContainerNaturalistBackpack(player, inventory, page); - return new GuiNaturalistInventory(speciesRoot, player, container, inventory, page, 5); + return new GuiNaturalistInventory(speciesRoot, player, container, page, 5); } @Override diff --git a/src/main/resources/config/forestry/hints.properties b/src/main/resources/config/forestry/hints.properties index 881a096be..4778db34a 100755 --- a/src/main/resources/config/forestry/hints.properties +++ b/src/main/resources/config/forestry/hints.properties @@ -18,7 +18,6 @@ mailbox=postage; philatelist=postage; trade.station=postage; -powered.machine= analyzer=pipette;flowerjungle;flowernether;apiaristsuit;honeyfood; bottler=pipette; carpenter=pipette;crating; @@ -28,7 +27,6 @@ fermenter=pipette;shortmead; squeezer=pipette; still=pipette; -engine=energyunit;energybuffer; -engine.bronze=pipette;enginebronzefuels;enginebronzeheatloss;enginebronzeoutput;enginebronzewaste -engine.copper=forcedcooldown;cooldownloss;enginecopperfuels;usesofash;enginecopperwaste;manualpeat;peatharvest -engine.tin=forcedcooldown;cooldownloss;enginetinbatteries;enginetinchoke; +engine.bronze=energyunit;energybuffer;pipette;enginebronzefuels;enginebronzeheatloss;enginebronzeoutput;enginebronzewaste +engine.copper=energyunit;energybuffer;forcedcooldown;cooldownloss;enginecopperfuels;usesofash;enginecopperwaste;manualpeat;peatharvest +engine.tin=energyunit;energybuffer;forcedcooldown;cooldownloss;enginetinbatteries;enginetinchoke;