More null annotations

This commit is contained in:
mezz committed 2017-02-06 01:34:48 -08:00
1 parent 16b955b443
commit da8a833485
96 files changed
+573 -360

No files matched your search

@@ -12,6 +12,7 @@ import java.util.List;
public interface IFlowerRoot extends ISpeciesRoot {
@Override
@Nullable
IFlower getMember(ItemStack memberStack);
@Override
@@ -27,15 +28,16 @@ public interface IFlowerRoot extends ISpeciesRoot {
IFlowerGenome templateAsGenome(IAllele[] templateFrist, IAllele[] templateSecond);
@Override
IBotanistTracker getBreedingTracker(World world, GameProfile profile);
IBotanistTracker getBreedingTracker(World world, @Nullable GameProfile profile);
@Override
List<? extends IFlowerMutation> getMutations(boolean shuffle);
@Override
@Nullable
EnumFlowerStage getType(ItemStack itemStack);
IFlower getFlower(World world, IFlowerGenome genome);
IFlower getFlower(IFlowerGenome genome);
void addConversion(ItemStack memberStack, IAllele[] template);
@@ -23,6 +23,7 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -50,7 +51,7 @@ public class BlockCeramic extends Block implements IColoredBlock, IItemModelRegi
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, @Nullable EntityPlayer player, boolean willHarvest) {
List<ItemStack> drops = new ArrayList<>();
TileCeramic ceramic = TileUtil.getTile(world, pos, TileCeramic.class);
if (ceramic != null) {
@@ -27,6 +27,7 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -91,7 +92,7 @@ public class BlockStainedGlass extends Block implements IBlockMetadata, IColored
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, @Nullable EntityPlayer player, boolean willHarvest) {
List<ItemStack> drops = new ArrayList<>();
TileCeramic ceramic = TileUtil.getTile(world, pos, TileCeramic.class);
if (ceramic != null) {
@@ -15,6 +15,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
@@ -54,6 +55,7 @@ public class CeramicDesignSystem implements IDesignSystem {
}
@Override
@Nullable
public TextureAtlasSprite getPrimarySprite(IPattern pattern) {
if (pattern instanceof EnumPattern) {
return this.primary.get(((EnumPattern) pattern).ordinal());
@@ -62,6 +64,7 @@ public class CeramicDesignSystem implements IDesignSystem {
}
@Override
@Nullable
public TextureAtlasSprite getSecondarySprite(IPattern pattern) {
if (pattern instanceof EnumPattern) {
return this.secondary.get(((EnumPattern) pattern).ordinal());
@@ -72,7 +72,7 @@ public class BlockCeramicBrick extends Block implements IMultipassBlock<CeramicB
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, @Nullable EntityPlayer player, boolean willHarvest) {
List<ItemStack> drops = new ArrayList<>();
TileCeramic ceramic = TileUtil.getTile(world, pos, TileCeramic.class);
if (ceramic != null) {
@@ -10,16 +10,19 @@ import forestry.api.farming.IFarmHousing;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import javax.annotation.Nullable;
public class CircuitGarden extends BinnieCircuit {
private Class<? extends FarmLogic> logicClass;
private boolean isManual;
private boolean isFertilised;
private ItemStack icon;
private EnumMoisture moisture;
@Nullable
private EnumAcidity acidity;
private GardenLogic logic;
public CircuitGarden(EnumMoisture moisture, EnumAcidity ph, boolean manual, boolean fertilised, ItemStack recipe, ItemStack icon) {
public CircuitGarden(EnumMoisture moisture, @Nullable EnumAcidity ph, boolean manual, boolean fertilised, ItemStack recipe, ItemStack icon) {
super(getName(moisture, ph, manual, fertilised), 4, manual ? ChipsetManager.circuitRegistry.getLayout("forestry.farms.manual") : ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed"), recipe);
this.isFertilised = false;
this.isManual = manual;
@@ -44,7 +47,7 @@ public class CircuitGarden extends BinnieCircuit {
this.addTooltipString("Flowers" + info);
}
private static String getName(EnumMoisture moisture, EnumAcidity ph, boolean manual, boolean fertilised) {
private static String getName(EnumMoisture moisture, @Nullable EnumAcidity ph, boolean manual, boolean fertilised) {
String name = "garden." + moisture.getName();
if (ph != null) {
name += "." + ph.getName();
@@ -68,6 +71,7 @@ public class CircuitGarden extends BinnieCircuit {
return tile instanceof IFarmHousing;
}
@Nullable
private IFarmHousing getCircuitable(Object tile) {
if (!isCircuitable(tile)) {
return null;
@@ -26,12 +26,14 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class GardenLogic extends FarmLogic {
EnumMoisture moisture;
@Nullable
EnumAcidity acidity;
boolean fertilised;
String name;
@@ -39,7 +41,7 @@ public class GardenLogic extends FarmLogic {
private ItemStack icon;
List<IFarmable> farmables;
public GardenLogic(EnumMoisture moisture2, EnumAcidity acidity2, boolean isManual, boolean isFertilised, ItemStack icon2, String name2) {
public GardenLogic(EnumMoisture moisture2, @Nullable EnumAcidity acidity2, boolean isManual, boolean isFertilised, ItemStack icon2, String name2) {
this.produce = new ArrayList<>();
(this.farmables = new ArrayList<>()).add(new FarmableFlower());
this.farmables.add(new FarmableVanillaFlower());
@@ -170,11 +172,12 @@ public class GardenLogic extends FarmLogic {
return false;
}
@Nullable
private ItemStack getAvailableLoam(IFarmHousing housing) {
EnumMoisture[] moistures;
if (this.moisture == EnumMoisture.Damp) {
moistures = new EnumMoisture[]{EnumMoisture.Damp, EnumMoisture.Normal, EnumMoisture.Dry};
} else if (this.moisture == EnumMoisture.Damp) {
} else if (this.moisture == EnumMoisture.Dry) {
moistures = new EnumMoisture[]{EnumMoisture.Dry, EnumMoisture.Damp, EnumMoisture.Dry};
} else {
moistures = new EnumMoisture[]{EnumMoisture.Dry, EnumMoisture.Normal, EnumMoisture.Damp};
@@ -201,7 +204,7 @@ public class GardenLogic extends FarmLogic {
return this.trySetSoil(world, position, this.getAvailableLoam(housing), housing);
}
private boolean trySetSoil(World world, BlockPos position, ItemStack loam, IFarmHousing housing) {
private boolean trySetSoil(World world, BlockPos position, @Nullable ItemStack loam, IFarmHousing housing) {
ItemStack copy = loam;
if (loam != null) {
if (loam.getItem() == Item.getItemFromBlock(Blocks.DIRT)) {
@@ -252,6 +255,7 @@ public class GardenLogic extends FarmLogic {
}
@Override
@Nullable
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
return null;
}
@@ -302,6 +306,7 @@ public class GardenLogic extends FarmLogic {
return false;
}
@Nullable
public ItemStack getAvailableAcid(IFarmHousing housing) {
for (final ItemStack stack : Gardening.getAcidFertilisers()) {
if (stack != null && stack.getItem() != null && housing.getFarmInventory().hasResources(new ItemStack[]{stack})) {
@@ -311,6 +316,7 @@ public class GardenLogic extends FarmLogic {
return null;
}
@Nullable
public ItemStack getAvailableAlkaline(IFarmHousing housing) {
for (final ItemStack stack : Gardening.getAlkalineFertilisers()) {
if (stack != null && stack.getItem() != null && housing.getFarmInventory().hasResources(new ItemStack[]{stack})) {
@@ -39,15 +39,20 @@ import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.EnumPlantType;
import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class TileEntityFlower extends TileEntity implements IPollinatable, IButterflyNursery {
@Nullable
IFlower flower;
@Nullable
GameProfile owner;
int section;
@Nullable
RenderInfo renderInfo;
@Nullable
IButterfly caterpillar;
int matureTime;
@@ -147,6 +152,7 @@ public class TileEntityFlower extends TileEntity implements IPollinatable, IButt
}
}
@Nullable
public IFlower getFlower() {
if (this.getSection() <= 0) {
return this.flower;
@@ -23,6 +23,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -175,9 +176,6 @@ public class Gardening {
}
public static int getFertiliserStrength(final ItemStack stack) {
if (stack == null) {
return 1;
}
for (final Map.Entry<ItemStack, Integer> entry : Gardening.fertiliserAcid.entrySet()) {
if (entry.getKey().isItemEqual(stack)) {
return entry.getValue();
@@ -196,8 +194,8 @@ public class Gardening {
return 1;
}
public static boolean canTolerate(final IFlower flower, final World world, final BlockPos pos) {
if (flower == null || flower.getGenome() == null) {
public static boolean canTolerate(@Nullable final IFlower flower, final World world, final BlockPos pos) {
if (flower == null) {
return false;
}
IBlockState soil = world.getBlockState(pos.down());
@@ -237,7 +235,7 @@ public class Gardening {
}
public static boolean isWeedkiller(ItemStack heldItem) {
return heldItem != null && heldItem.isItemEqual(BotanyItems.Weedkiller.get(1));
return heldItem.isItemEqual(BotanyItems.Weedkiller.get(1));
}
public static boolean addWeedKiller(World world, BlockPos pos) {
@@ -46,7 +46,7 @@ public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
@Override
public String getUID() {
return "rootFlowers";
return UID;
}
@Override
@@ -79,6 +79,7 @@ public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
@Override
public IAlyzerPlugin getAlyzerPlugin() {
// TODO write flower alyzer plugin
return null;
}
@@ -88,11 +89,8 @@ public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
}
@Override
@Nullable
public EnumFlowerStage getType(ItemStack stack) {
if (stack == null) {
return null;
}
Item item = stack.getItem();
if (Botany.flowerItem == item) {
@@ -107,6 +105,7 @@ public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
}
@Override
@Nullable
public ItemStack getMemberStack(IIndividual flower, ISpeciesType type) {
if (!this.isMember(flower)) {
return null;
@@ -129,15 +128,16 @@ public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
}
@Override
@Nullable
public IFlower getMember(final ItemStack stack) {
if (!this.isMember(stack)) {
if (!this.isMember(stack) || stack.getTagCompound() == null) {
return null;
}
return new Flower(stack.getTagCompound());
}
@Override
public IFlower getFlower(final World world, final IFlowerGenome genome) {
public IFlower getFlower(final IFlowerGenome genome) {
return new Flower(genome, 2);
}
@@ -217,7 +217,7 @@ public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
}
@Override
public IBotanistTracker getBreedingTracker(final World world, final GameProfile player) {
public IBotanistTracker getBreedingTracker(final World world, @Nullable final GameProfile player) {
final String filename = "BotanistTracker." + ((player == null) ? "common" : player.getId());
BotanistTracker tracker = (BotanistTracker) world.loadItemData(BotanistTracker.class, filename);
if (tracker == null) {
@@ -250,7 +250,7 @@ public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
@Override
public void addConversion(final ItemStack itemstack, final IAllele[] template) {
final IFlower flower = this.getFlower(null, this.templateAsGenome(template));
final IFlower flower = this.getFlower(this.templateAsGenome(template));
this.conversions.put(itemstack, flower);
}
+2 -4
View File
@@ -66,10 +66,8 @@ public abstract class AbstractMod implements IPacketProvider, IInitializable {
return;
}
registerModules();
if (this.getConfigs() != null) {
for (final Class<?> cls : this.getConfigs()) {
Binnie.CONFIGURATION.registerConfiguration(cls, this);
}
for (final Class<?> cls : this.getConfigs()) {
Binnie.CONFIGURATION.registerConfiguration(cls, this);
}
this.getProxy().preInit();
for (final IInitializable module : this.modules) {
+10 -5
View File
@@ -77,7 +77,8 @@ public class Mods {
super(id);
}
@Override
@Override
@Nonnull
public Item item(final String name) {
Item item = super.item(name);
if (item == null) {
@@ -86,7 +87,8 @@ public class Mods {
return item;
}
@Override
@Override
@Nonnull
public Block block(final String name) {
Block block = super.block(name);
if (block == null) {
@@ -95,19 +97,22 @@ public class Mods {
return block;
}
@Override
@Override
@Nonnull
public ItemStack stack(final String name) {
Item item = this.item(name);
return new ItemStack(item);
}
@Override
@Override
@Nonnull
public ItemStack stack(final String name, final int amount) {
Item item = this.item(name);
return new ItemStack(item, amount);
}
@Override
@Override
@Nonnull
public ItemStack stack(final String name, final int amount, final int meta) {
Item item = this.item(name);
return new ItemStack(item, amount, meta);
@@ -28,6 +28,7 @@ import net.minecraftforge.common.model.TRSRTransformation;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;
import java.util.EnumMap;
@@ -40,7 +41,7 @@ public abstract class BaseBakedModel implements IPerspectiveAwareModel {
this(null);
}
public BaseBakedModel(ResourceLocation particle) {
public BaseBakedModel(@Nullable ResourceLocation particle) {
this.particle = particle != null ? particle : TextureMap.LOCATION_MISSING_TEXTURE;
}
@@ -19,6 +19,8 @@ import java.util.List;
import binnie.core.BinnieCore;
import javax.annotation.Nullable;
public class BlockMetadata extends BlockContainer implements IBlockMetadata {
static int temporyMeta = -1;
@@ -47,6 +49,7 @@ public class BlockMetadata extends BlockContainer implements IBlockMetadata {
}
@Override
@Nullable
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
return getPickBlock(world, pos);
}
@@ -59,15 +62,15 @@ public class BlockMetadata extends BlockContainer implements IBlockMetadata {
@Override
public int getPlacedMeta(final ItemStack item, final World world, final BlockPos pos, final EnumFacing clickedBlock) {
final int damage = TileEntityMetadata.getItemDamage(item);
return damage;
return TileEntityMetadata.getItemDamage(item);
}
@Override
public int getDroppedMeta(IBlockState state, int tileMetadata) {
return getMetaFromState(state);
}
@Nullable
public static ItemStack getBlockDropped(IBlockMetadata block, IBlockAccess world, BlockPos pos) {
TileEntityMetadata tile = TileEntityMetadata.getTile(world, pos);
if (tile != null && !tile.hasDroppedBlock()) {
@@ -85,7 +88,7 @@ public class BlockMetadata extends BlockContainer implements IBlockMetadata {
return Collections.emptyList();
}
public static boolean breakBlock(IBlockMetadata blockMetadata, EntityPlayer player, World world, BlockPos pos) {
public static boolean breakBlock(IBlockMetadata blockMetadata, @Nullable EntityPlayer player, World world, BlockPos pos) {
List<ItemStack> drops = new ArrayList<>();
Block block = (Block) blockMetadata;
TileEntityMetadata tile = TileEntityMetadata.getTile(world, pos);
@@ -94,16 +97,20 @@ public class BlockMetadata extends BlockContainer implements IBlockMetadata {
}
boolean hasBeenBroken = world.setBlockToAir(pos);
if (hasBeenBroken && BinnieCore.getBinnieProxy().isSimulating(world) && drops.size() > 0 && (player == null || !player.capabilities.isCreativeMode)) {
for(ItemStack drop : drops) {
for (ItemStack drop : drops) {
spawnAsEntity(world, pos, drop);
}
tile.dropBlock();
if (tile != null) {
tile.dropBlock();
}
}
return hasBeenBroken;
}
@Nullable
public static ItemStack getPickBlock(World world, BlockPos pos) {
return getBlockDropped((IBlockMetadata) world.getBlockState(pos).getBlock(), world, pos);
Block block = world.getBlockState(pos).getBlock();
return getBlockDropped((IBlockMetadata) block, world, pos);
}
}
@@ -13,6 +13,8 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import javax.annotation.Nullable;
public class TileEntityMetadata extends TileEntity {
private int meta;
private boolean droppedBlock;
@@ -76,6 +78,7 @@ public class TileEntityMetadata extends TileEntity {
return new PacketMetadata(pos, meta, getUpdateTag());
}
@Nullable
public static TileEntityMetadata getTile(final IBlockAccess world, final BlockPos pos) {
final TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof TileEntityMetadata)) {
@@ -18,6 +18,7 @@ import forestry.api.genetics.ISpeciesType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
import java.util.TreeSet;
class BeeBreedingSystem extends BreedingSystem {
@@ -78,7 +79,7 @@ class BeeBreedingSystem extends BreedingSystem {
}
@Override
public boolean isDNAManipulable(ISpeciesType type) {
public boolean isDNAManipulable(@Nullable ISpeciesType type) {
return type == EnumBeeType.LARVAE;
}
@@ -219,7 +219,7 @@ public abstract class BreedingSystem implements IItemStackRepresentitive {
}
public final boolean isMutationDiscovered(final IMutation mutation, final IBreedingTracker tracker) {
return tracker == null || tracker.isDiscovered(mutation);
return tracker.isDiscovered(mutation);
}
public final boolean isSpeciesDiscovered(final IAlleleSpecies species, final World world, final GameProfile name) {
@@ -227,7 +227,7 @@ public abstract class BreedingSystem implements IItemStackRepresentitive {
}
public final boolean isSpeciesDiscovered(final IAlleleSpecies species, final IBreedingTracker tracker) {
return tracker == null || tracker.isDiscovered(species);
return tracker.isDiscovered(species);
}
public final boolean isSecret(final IAlleleSpecies species) {
@@ -413,6 +413,7 @@ public abstract class BreedingSystem implements IItemStackRepresentitive {
return this.getSpeciesRoot().getUID();
}
@Nullable
public final IChromosomeType getChromosome(final int i) {
for (final IChromosomeType chromosome : this.getSpeciesRoot().getKaryotype()) {
if (i == chromosome.ordinal()) {
@@ -130,19 +130,26 @@ public class ManagerGenetics extends ManagerBase {
}
@Nullable
public BreedingSystem getConversionSystem(final ItemStack stack) {
for (final BreedingSystem system : this.getActiveSystems()) {
if (system.getConversion(stack) != null) {
return system;
public BreedingSystem getConversionSystem(@Nullable final ItemStack stack) {
if (stack != null) {
for (final BreedingSystem system : this.getActiveSystems()) {
if (system.getConversion(stack) != null) {
return system;
}
}
}
return null;
}
@Nullable
public ItemStack getConversionStack(final ItemStack stack) {
final BreedingSystem system = this.getConversionSystem(stack);
return (system == null) ? null : system.getConversionStack(stack);
public ItemStack getConversionStack(@Nullable final ItemStack stack) {
if (stack != null) {
final BreedingSystem system = this.getConversionSystem(stack);
if (system != null) {
return system.getConversionStack(stack);
}
}
return null;
}
@Nullable
@@ -11,12 +11,14 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
public enum BinnieCoreGUI implements IBinnieGUID {
Compartment,
FieldKit,
Genesis;
public Window getWindow(final EntityPlayer player, final IInventory object, final Side side) {
public Window getWindow(final EntityPlayer player, @Nullable final IInventory object, final Side side) {
switch (this) {
case Compartment: {
return new WindowCompartment(player, object, side);
@@ -8,6 +8,8 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
public final class BinnieGUIHandler implements IGuiHandler {
private AbstractMod mod;
@@ -16,6 +18,7 @@ public final class BinnieGUIHandler implements IGuiHandler {
}
@Override
@Nullable
public final Object getServerGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
final Window window = this.getWindow(id, player, world, x, y, z, Side.SERVER);
if (window == null) {
@@ -26,6 +29,7 @@ public final class BinnieGUIHandler implements IGuiHandler {
}
@Override
@Nullable
public final Object getClientGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
if (BinnieCore.getBinnieProxy().isSimulating(world)) {
return this.getServerGuiElement(id, player, world, x, y, z);
@@ -37,6 +41,7 @@ public final class BinnieGUIHandler implements IGuiHandler {
return window.getGui();
}
@Nullable
public Window getWindow(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z, final Side side) {
for (final IBinnieGUID guid : this.mod.getGUIDs()) {
if (guid.ordinal() == id) {
@@ -88,13 +88,15 @@ class BlockMachine extends BlockContainer implements IBlockMachine {
}
@Override
@Nullable
public MachinePackage getPackage(final int meta) {
return this.group.getPackage(meta);
}
@Override
public String getMachineName(final int meta) {
return (this.getPackage(meta) == null) ? "Unnamed Machine" : this.getPackage(meta).getDisplayName();
MachinePackage machinePackage = this.getPackage(meta);
return (machinePackage == null) ? "Unnamed Machine" : machinePackage.getDisplayName();
}
@Override
@@ -104,10 +106,11 @@ class BlockMachine extends BlockContainer implements IBlockMachine {
@Override
public TileEntity createNewTileEntity(final World var1, final int meta) {
if (this.group.getPackage(meta) == null) {
return null;
MachinePackage machinePackage = this.group.getPackage(meta);
if (machinePackage == null) {
throw new IllegalArgumentException("Could not find package for meta value " + meta);
}
return this.group.getPackage(meta).createTileEntity();
return machinePackage.createTileEntity();
}
@Override
@@ -119,14 +122,16 @@ class BlockMachine extends BlockContainer implements IBlockMachine {
return true;
}
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
IFluidHandler tileFluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
if (FluidUtil.interactWithFluidHandler(heldItem, tileFluidHandler, player)) {
return true;
if (tileEntity != null) {
if (tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
IFluidHandler tileFluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
if (FluidUtil.interactWithFluidHandler(heldItem, tileFluidHandler, player)) {
return true;
}
}
if (tileEntity instanceof TileEntityMachine) {
((TileEntityMachine) tileEntity).getMachine().onRightClick(world, player, pos);
}
}
if (tileEntity instanceof TileEntityMachine) {
((TileEntityMachine) tileEntity).getMachine().onRightClick(world, player, pos);
}
return true;
}
@@ -1,7 +1,10 @@
package binnie.core.machines;
interface IBlockMachine {
MachinePackage getPackage(final int p0);
import javax.annotation.Nullable;
String getMachineName(final int p0);
interface IBlockMachine {
@Nullable
MachinePackage getPackage(final int meta);
String getMachineName(final int meta);
}
@@ -3,6 +3,7 @@ package binnie.core.machines;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.Collection;
public interface IMachine extends IOwnable {
+16 -10
View File
@@ -10,6 +10,7 @@ import binnie.core.network.BinnieCorePacketID;
import binnie.core.network.INetworkedEntity;
import binnie.core.network.packet.MessageTileNBT;
import binnie.core.network.packet.PacketPayload;
import com.google.common.base.Preconditions;
import com.mojang.authlib.GameProfile;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
@@ -36,6 +37,7 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
private Map<Class<? extends MachineComponent>, MachineComponent> componentMap;
private TileEntity tile;
private boolean queuedInventoryUpdate;
@Nullable
private GameProfile owner;
public Machine(final MachinePackage pack, final TileEntity tile) {
@@ -50,9 +52,7 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
@Override
public void addComponent(final MachineComponent component) {
if (component == null) {
throw new NullPointerException("Can't have a null machine component!");
}
Preconditions.checkNotNull(component, "Can't have a null machine component!");
component.setMachine(this);
this.componentMap.put(component.getClass(), component);
for (final Class<? extends MachineComponent> inter : component.getComponentInterfaces()) {
@@ -67,8 +67,12 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
return this.componentMap.values();
}
@Nullable
public <T extends MachineComponent> T getComponent(final Class<T> componentClass) {
return this.hasComponent(componentClass) ? componentClass.cast(this.componentMap.get(componentClass)) : null;
if (this.hasComponent(componentClass)) {
return componentClass.cast(this.componentMap.get(componentClass));
}
return null;
}
@Override
@@ -84,7 +88,7 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
return interfaceClass.cast(component);
}
}
return null;
throw new IllegalArgumentException("No interface for : " + interfaceClass);
}
@Override
@@ -205,21 +209,22 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
return this.machinePackage;
}
public static IMachine getMachine(final Object inventory) {
if (inventory != null && inventory instanceof IMachine) {
@Nullable
public static IMachine getMachine(@Nullable final Object inventory) {
if (inventory instanceof IMachine) {
return (IMachine) inventory;
}
if (inventory != null && inventory instanceof TileEntityMachine) {
if (inventory instanceof TileEntityMachine) {
return ((TileEntityMachine) inventory).getMachine();
}
if (inventory != null && inventory instanceof MachineComponent) {
if (inventory instanceof MachineComponent) {
return ((MachineComponent) inventory).getMachine();
}
return null;
}
@Nullable
public static <T> T getInterface(final Class<T> interfac, final Object inventory) {
public static <T> T getInterface(final Class<T> interfac, @Nullable final Object inventory) {
final IMachine machine = getMachine(inventory);
if (machine != null) {
return machine.getInterface(interfac);
@@ -256,6 +261,7 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
this.owner = owner;
}
@Nullable
public Packet<?> getDescriptionPacket() {
final NBTTagCompound nbt = new NBTTagCompound();
this.syncToNBT(nbt);
@@ -11,7 +11,7 @@ public class MachineComponent implements INbtReadable, INbtWritable {
private IMachine machine;
public MachineComponent(final IMachine machine) {
this.setMachine(machine);
this.machine = machine;
machine.addComponent(this);
}
@@ -7,6 +7,7 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -70,6 +71,7 @@ public class MachineGroup {
return this.block;
}
@Nullable
public MachinePackage getPackage(final int metadata) {
return this.packagesID.get(metadata);
}
@@ -150,7 +150,7 @@ public class MachineUtil {
IInventory inventory = this.getInventory();
for (int slot : inventorySlots) {
ItemStack stackInSlot = this.getStack(slot);
if (ItemStack.areItemsEqual(requiredStack, stackInSlot) && ItemStack.areItemStackTagsEqual(requiredStack, stackInSlot)) {
if (stackInSlot != null && ItemStack.areItemsEqual(requiredStack, stackInSlot) && ItemStack.areItemStackTagsEqual(requiredStack, stackInSlot)) {
if (requiredStack.stackSize >= stackInSlot.stackSize) {
requiredStack.stackSize -= stackInSlot.stackSize;
inventory.removeStackFromSlot(slot);
@@ -35,7 +35,7 @@ class DefaultTankContainer implements ITankMachine {
}
@Override
public TankSlot getTankSlot(final int slot) {
public TankSlot getTankSlot(final int index) {
return null;
}
@@ -2,10 +2,14 @@ package binnie.core.machines.component;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public interface IComponentRecipe {
boolean isRecipe();
ItemStack doRecipe(final boolean p0);
@Nullable
ItemStack doRecipe(final boolean takeItem);
@Nullable
ItemStack getProduct();
}
@@ -11,6 +11,7 @@ import java.util.EnumSet;
public abstract class BaseSlot<T> implements INbtWritable, INbtReadable, IValidator<T> {
private SidedAccess access;
@Nullable
Validator<T> validator;
private boolean readOnly;
private int index;
@@ -38,7 +39,7 @@ public abstract class BaseSlot<T> implements INbtWritable, INbtReadable, IValida
@Nullable
public abstract T getContent();
public abstract void setContent(final T p0);
public abstract void setContent(final T content);
public void setValidator(final Validator<T> val) {
this.validator = val;
@@ -121,6 +122,7 @@ public abstract class BaseSlot<T> implements INbtWritable, INbtReadable, IValida
public abstract String getName();
@Nullable
public Validator<T> getValidator() {
return this.validator;
}
@@ -10,7 +10,6 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -100,8 +99,10 @@ public class ComponentInventorySlots extends ComponentInventory implements IInve
protected void transferItem(final int indexFrom, final int indexTo) {
if (this.inventory.containsKey(indexFrom) && this.inventory.containsKey(indexTo)) {
final ItemStack newStack = this.inventory.get(indexFrom).getContent().copy();
this.inventory.get(indexFrom).setContent(null);
final InventorySlot slotFrom = this.inventory.get(indexFrom);
final ItemStack oldStack = slotFrom.getContent();
final ItemStack newStack = oldStack == null ? null : oldStack.copy();
slotFrom.setContent(null);
this.inventory.get(indexTo).setContent(newStack);
}
this.markDirty();
@@ -181,6 +182,7 @@ public class ComponentInventorySlots extends ComponentInventory implements IInve
}
@Override
@Nullable
public InventorySlot getSlot(final int index) {
if (this.inventory.containsKey(index)) {
return this.inventory.get(index);
@@ -243,7 +245,7 @@ public class ComponentInventorySlots extends ComponentInventory implements IInve
}
@Override
public int[] getSlotsForFace(final EnumFacing var1) {
public int[] getSlotsForFace(final EnumFacing facing) {
final List<Integer> slots = new ArrayList<>();
for (final InventorySlot slot : this.inventory.values()) {
if (slot.canInsert() || slot.canExtract()) {
@@ -258,12 +260,19 @@ public class ComponentInventorySlots extends ComponentInventory implements IInve
}
@Override
public boolean canInsertItem(final int i, final ItemStack itemstack, final EnumFacing direction) {
return this.isItemValidForSlot(i, itemstack) && this.getSlot(i).canInsert(direction);
public boolean canInsertItem(final int index, final ItemStack itemstack, final EnumFacing direction) {
if (this.isItemValidForSlot(index, itemstack)) {
InventorySlot slot = this.getSlot(index);
if (slot != null && slot.canInsert(direction)) {
return true;
}
}
return false;
}
@Override
public boolean canExtractItem(final int i, final ItemStack itemstack, final EnumFacing direction) {
return this.getSlot(i).canExtract(direction);
public boolean canExtractItem(final int index, final ItemStack itemstack, final EnumFacing direction) {
InventorySlot slot = this.getSlot(index);
return slot != null && slot.canExtract(direction);
}
}
@@ -13,6 +13,7 @@ import net.minecraftforge.fluids.capability.FluidTankProperties;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.LinkedHashMap;
@@ -39,7 +40,7 @@ public class ComponentTankContainer extends MachineComponent implements ITankMac
return tank;
}
private final int fill(final int tankIndex, final FluidStack resource, final boolean doFill) {
private int fill(final int tankIndex, final FluidStack resource, final boolean doFill) {
if (!this.tanks.containsKey(tankIndex)) {
return 0;
}
@@ -54,7 +55,8 @@ public class ComponentTankContainer extends MachineComponent implements ITankMac
return filled;
}
private final FluidStack drain(final int tankIndex, final int maxDrain, final boolean doDrain) {
@Nullable
private FluidStack drain(final int tankIndex, final int maxDrain, final boolean doDrain) {
if (!this.tanks.containsKey(tankIndex)) {
return null;
}
@@ -75,7 +77,7 @@ public class ComponentTankContainer extends MachineComponent implements ITankMac
return -1;
}
private int getTankIndexToDrain(final EnumFacing from, final FluidStack resource) {
private int getTankIndexToDrain(final EnumFacing from, @Nullable final FluidStack resource) {
for (final TankSlot tank : this.tanks.values()) {
if (tank.getContent() != null && tank.canExtract(from) && (resource == null || resource.isFluidEqual(tank.getContent()))) {
return tank.getIndex();
@@ -144,6 +146,7 @@ public class ComponentTankContainer extends MachineComponent implements ITankMac
}
@Override
@Nullable
public TankSlot getTankSlot(final int index) {
return this.tanks.get(index);
}
@@ -1,11 +1,14 @@
package binnie.core.machines.inventory;
import javax.annotation.Nullable;
public interface IInventorySlots {
InventorySlot addSlot(final int p0, final String p1);
InventorySlot[] addSlotArray(final int[] p0, final String p1);
InventorySlot getSlot(final int p0);
@Nullable
InventorySlot getSlot(final int index);
InventorySlot[] getSlots(final int[] p0);
@@ -6,6 +6,8 @@ import binnie.core.machines.MachineComponent;
import binnie.core.machines.network.INetwork;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
public abstract class ComponentProcessIndefinate extends MachineComponent implements IProcess, INetwork.TilePacketSync {
private float energyPerTick;
private boolean inProgress;
@@ -73,16 +75,25 @@ public abstract class ComponentProcessIndefinate extends MachineComponent implem
}
@Override
@Nullable
public ErrorState canWork() {
return (this.actionCancelTask == 0.0f) ? null : new ErrorState(BinnieCore.getBinnieProxy().localise("machine.errors.task.cancelled.desc"), BinnieCore.getBinnieProxy().localise("machine.errors.task.cancelled.info"));
if (this.actionCancelTask == 0.0f) {
return null;
} else {
return new ErrorState(BinnieCore.getBinnieProxy().localise("machine.errors.task.cancelled.desc"), BinnieCore.getBinnieProxy().localise("machine.errors.task.cancelled.info"));
}
}
@Override
@Nullable
public ErrorState canProgress() {
if (this.actionPauseProcess != 0.0f) {
return new ErrorState(BinnieCore.getBinnieProxy().localise("machine.errors.task.process.paused.desc"), BinnieCore.getBinnieProxy().localise("machine.errors.task.process.paused.info"));
} else if (this.getPower().getInterface().getEnergy(PowerSystem.RF) < this.getEnergyPerTick()) {
return new ErrorState.InsufficientPower();
} else {
return null;
}
return (this.getPower().getInterface().getEnergy(PowerSystem.RF) < this.getEnergyPerTick()) ? new ErrorState.InsufficientPower() : null;
}
@Override
@@ -1,7 +1,11 @@
package binnie.core.machines.power;
import javax.annotation.Nullable;
public interface IErrorStateSource {
@Nullable
ErrorState canWork();
@Nullable
ErrorState canProgress();
}
@@ -6,16 +6,19 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.fluids.capability.IFluidHandler;
import javax.annotation.Nullable;
public interface ITankMachine extends IValidatedTankContainer {
TankInfo[] getTankInfos();
IFluidTank[] getTanks();
TankSlot addTank(final int p0, final String p1, final int p2);
TankSlot addTank(final int index, final String p1, final int p2);
IFluidTank getTank(final int p0);
IFluidTank getTank(final int index);
TankSlot getTankSlot(final int p0);
@Nullable
TankSlot getTankSlot(final int index);
IFluidHandler getHandler(EnumFacing from);
}
@@ -56,7 +56,7 @@ class CompartmentTab implements INbtWritable, INbtReadable {
}
public void setName(final String name) {
this.name = ((name == null) ? "" : name);
this.name = name;
}
public void setIcon(final ItemStack icon) {
@@ -50,6 +50,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -70,7 +71,7 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh
return new WindowCompartment(player, inventory, side);
}
public WindowCompartment(final EntityPlayer player, final IInventory inventory, final Side side) {
public WindowCompartment(final EntityPlayer player, @Nullable final IInventory inventory, final Side side) {
super(320, 226, player, inventory, side);
this.panels = new HashMap<>();
this.currentTab = 0;
@@ -3,6 +3,7 @@ package binnie.core.machines.transfer;
import binnie.core.machines.Machine;
import binnie.core.machines.inventory.IInventorySlots;
import binnie.core.machines.inventory.IValidatedTankContainer;
import binnie.core.machines.inventory.InventorySlot;
import binnie.core.machines.power.ITankMachine;
import com.google.common.base.Preconditions;
import net.minecraft.inventory.IInventory;
@@ -19,9 +20,13 @@ import java.util.ArrayList;
import java.util.List;
public class TransferRequest {
@Nullable
private ItemStack itemToTransfer;
@Nullable
private ItemStack returnItem;
@Nullable
private IInventory origin;
@Nullable
private IInventory destination;
private int[] targetSlots;
private int[] targetTanks;
@@ -78,39 +83,41 @@ public class TransferRequest {
@Nullable
public static ItemStack transferToInventory(ItemStack item, final IInventory destination, final int[] targetSlots, final boolean doAdd, final boolean ignoreValidation) {
ItemStack returnItem = item;
for (final int i : targetSlots) {
if (destination.isItemValidForSlot(i, item) || ignoreValidation) {
if (destination.getStackInSlot(i) == null) {
if (destination.isItemValidForSlot(i, returnItem) || ignoreValidation) {
ItemStack stackInSlot = destination.getStackInSlot(i);
if (stackInSlot == null) {
if (doAdd) {
destination.setInventorySlotContents(i, item.copy());
destination.setInventorySlotContents(i, returnItem.copy());
}
return null;
}
if (item.isStackable()) {
final ItemStack merged = destination.getStackInSlot(i).copy();
final ItemStack[] newStacks = mergeStacks(item.copy(), merged.copy());
item = newStacks[0];
if (returnItem.isStackable()) {
final ItemStack merged = stackInSlot.copy();
final ItemStack[] newStacks = mergeStacks(returnItem.copy(), merged.copy());
returnItem = newStacks[0];
if (doAdd) {
destination.setInventorySlotContents(i, newStacks[1]);
}
if (item == null) {
if (returnItem == null) {
return null;
}
}
}
}
return item;
return returnItem;
}
private void setItemToTransfer(final ItemStack itemToTransfer) {
this.itemToTransfer = itemToTransfer;
}
private void setReturnItem(final ItemStack returnItem) {
private void setReturnItem(@Nullable final ItemStack returnItem) {
this.returnItem = returnItem;
}
public TransferRequest setOrigin(final IInventory origin) {
public TransferRequest setOrigin(@Nullable final IInventory origin) {
this.origin = origin;
return this;
}
@@ -134,13 +141,15 @@ public class TransferRequest {
return this;
}
@Nullable
public ItemStack getReturnItem() {
return this.returnItem;
}
@Nullable
public ItemStack transfer(final boolean doAdd) {
ItemStack item = this.returnItem;
if (item == null || this.destination == null) {
if (item == null || this.destination == null || this.origin == null) {
return null;
}
if (this.transferLiquids && this.destination instanceof ITankMachine) {
@@ -160,21 +169,26 @@ public class TransferRequest {
if (item != null) {
for (final int slot : this.targetSlots) {
if (this.destination.isItemValidForSlot(slot, item) || this.ignoreReadOnly) {
if (!(this.destination instanceof IInventorySlots) || ((IInventorySlots) this.destination).getSlot(slot) == null || !((IInventorySlots) this.destination).getSlot(slot).isRecipe()) {
if (this.destination.getStackInSlot(slot) != null) {
if (item.isStackable()) {
final ItemStack merged = this.destination.getStackInSlot(slot).copy();
final ItemStack[] newStacks = mergeStacks(item.copy(), merged.copy());
item = newStacks[0];
if (!areItemsEqual(merged, newStacks[1])) {
this.insertedSlots.add(new TransferSlot(slot, this.destination));
}
if (doAdd) {
this.destination.setInventorySlotContents(slot, newStacks[1]);
}
if (item == null) {
return null;
}
if (this.destination instanceof IInventorySlots) {
InventorySlot inventorySlot = ((IInventorySlots) this.destination).getSlot(slot);
if (inventorySlot != null && inventorySlot.isRecipe()) {
continue;
}
}
ItemStack stackInSlot = this.destination.getStackInSlot(slot);
if (stackInSlot != null) {
if (item.isStackable()) {
final ItemStack merged = stackInSlot.copy();
final ItemStack[] newStacks = mergeStacks(item.copy(), merged.copy());
item = newStacks[0];
if (!areItemsEqual(merged, newStacks[1])) {
this.insertedSlots.add(new TransferSlot(slot, this.destination));
}
if (doAdd) {
this.destination.setInventorySlotContents(slot, newStacks[1]);
}
if (item == null) {
return null;
}
}
}
@@ -184,15 +198,19 @@ public class TransferRequest {
if (item != null) {
for (final int slot : this.targetSlots) {
if (this.destination.isItemValidForSlot(slot, item) || this.ignoreReadOnly) {
if (!(this.destination instanceof IInventorySlots) || ((IInventorySlots) this.destination).getSlot(slot) == null || !((IInventorySlots) this.destination).getSlot(slot).isRecipe()) {
if (this.destination.getStackInSlot(slot) == null && item != null) {
this.insertedSlots.add(new TransferSlot(slot, this.destination));
if (doAdd) {
this.destination.setInventorySlotContents(slot, item.copy());
}
return null;
if (this.destination instanceof IInventorySlots) {
InventorySlot inventorySlot = ((IInventorySlots) this.destination).getSlot(slot);
if (inventorySlot != null && inventorySlot.isRecipe()) {
continue;
}
}
if (this.destination.getStackInSlot(slot) == null) {
this.insertedSlots.add(new TransferSlot(slot, this.destination));
if (doAdd) {
this.destination.setInventorySlotContents(slot, item.copy());
}
return null;
}
}
}
}
@@ -209,8 +227,7 @@ public class TransferRequest {
final int space = merged.getMaxStackSize() - merged.stackSize;
if (space > 0) {
if (itemstack.stackSize > space) {
final ItemStack itemStack = itemstack;
itemStack.stackSize -= space;
itemstack.stackSize -= space;
merged.stackSize += space;
} else if (itemstack.stackSize <= space) {
merged.stackSize += itemstack.stackSize;
@@ -267,6 +284,7 @@ public class TransferRequest {
return itemStack;
}
@Nullable
private static ItemStack transferFromTank(ItemStack itemStack, final IInventory origin, final ITankMachine destination, final int tankID, final boolean doAdd) {
Preconditions.checkNotNull(itemStack);
Preconditions.checkArgument(itemStack.stackSize >= 1);
@@ -309,25 +327,6 @@ public class TransferRequest {
return itemStack;
}
private ItemStack transferFromTankUsingFluidContainer(final ItemStack item, final IInventory origin, final ITankMachine destination, final int tankID, final boolean doAdd) {
if (item == null || !(item.getItem() instanceof IFluidContainerItem)) {
return item;
}
final IFluidContainerItem fluidContainer = (IFluidContainerItem) item.getItem();
final IFluidTank tank = destination.getTanks()[tankID];
final FluidStack fluid = tank.getFluid();
if (fluid == null) {
return item;
}
int amount = fluidContainer.fill(item, fluid, false);
amount = Math.min(amount, (tank.drain(amount, false) == null) ? 0 : tank.drain(amount, false).amount);
if (amount <= 0) {
return item;
}
fluidContainer.fill(item, tank.drain(amount, doAdd), doAdd);
return item;
}
public List<TransferSlot> getInsertedSlots() {
return this.insertedSlots;
}
@@ -336,14 +335,17 @@ public class TransferRequest {
return this.insertedTanks;
}
@Nullable
public IInventory getOrigin() {
return this.origin;
}
@Nullable
public IInventory getDestination() {
return this.destination;
}
@Nullable
public ItemStack getItemToTransfer() {
return this.itemToTransfer;
}
@@ -3,8 +3,11 @@ package binnie.core.network.packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import javax.annotation.Nullable;
interface IPacketLocation {
TileEntity getTarget(final World p0);
@Nullable
TileEntity getTarget(final World world);
int getX();
@@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -27,6 +28,7 @@ public class MessageBase {
return new MessageBinnie(this.id, this);
}
@Nullable
protected NBTTagCompound readNBTTagCompound(final ByteBuf data) throws IOException {
final short length = data.readShort();
if (length < 0) {
@@ -37,7 +39,7 @@ public class MessageBase {
return CompressedStreamTools.readCompressed(new ByteArrayInputStream(compressed));
}
protected void writeNBTTagCompound(final NBTTagCompound nbttagcompound, final ByteBuf data) throws IOException {
protected void writeNBTTagCompound(@Nullable final NBTTagCompound nbttagcompound, final ByteBuf data) throws IOException {
if (nbttagcompound == null) {
data.writeShort(-1);
} else {
@@ -3,11 +3,14 @@ package binnie.core.network.packet;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
import java.io.IOException;
public class MessageNBT extends MessageBase {
@Nullable
NBTTagCompound nbt;
@Nullable
public NBTTagCompound getTagCompound() {
return this.nbt;
}
@@ -6,6 +6,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.io.IOException;
public class MessageTileNBT extends MessageNBT implements IPacketLocation {
@@ -42,6 +43,7 @@ public class MessageTileNBT extends MessageNBT implements IPacketLocation {
}
@Override
@Nullable
public TileEntity getTarget(final World world) {
return world.getTileEntity(new BlockPos(this.posX, this.posY, this.posZ));
}
@@ -77,16 +77,12 @@ public class BinnieProxy extends BinnieModProxy implements IBinnieProxy {
@Override
public World getWorld() {
return null;
}
public void throwException(final String message, final Throwable e) {
FMLCommonHandler.instance().raiseException(e, message, true);
return getServer().getEntityWorld();
}
@Override
public Minecraft getMinecraftInstance() {
return null;
throw new UnsupportedOperationException("Cannot call getMinecraftInstance on server side");
}
@Override
@@ -155,16 +155,15 @@ public final class BinnieProxyClient extends BinnieProxy implements IBinnieProxy
@Override
public Object createObject(final String renderer) {
Object object = null;
try {
final Class<?> rendererClass = Class.forName(renderer);
if (rendererClass != null) {
object = rendererClass.newInstance();
return rendererClass.newInstance();
}
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw Throwables.propagate(e);
}
return object;
throw new IllegalArgumentException("Could not create object for class name " + renderer);
}
// @Override
@@ -3,12 +3,16 @@ package binnie.core.resource;
import binnie.Binnie;
import binnie.core.AbstractMod;
import com.google.common.base.Preconditions;
import forestry.core.render.TextureManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
public class BinnieSprite extends BinnieResource {
@Nullable
private TextureAtlasSprite sprite;
public BinnieSprite(final AbstractMod mod, final ResourceType type, final String path) {
@@ -19,6 +23,7 @@ public class BinnieSprite extends BinnieResource {
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getSprite() {
Preconditions.checkState(this.sprite != null, "Tried to get sprite before it is registered.");
return this.sprite;
}
@@ -1,5 +1,5 @@
package binnie.core.util;
public interface IValidator<T> {
boolean isValid(final T p0);
boolean isValid(final T value);
}
@@ -35,6 +35,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -53,9 +54,10 @@ public class WindowFieldKit extends Window {
private float analyseProgress;
private boolean isAnalysing;
private Map<IChromosomeType, String> info;
@Nullable
private ItemStack prev;
public WindowFieldKit(final EntityPlayer player, final IInventory inventory, final Side side) {
public WindowFieldKit(final EntityPlayer player, @Nullable final IInventory inventory, final Side side) {
super(280, 230, player, inventory, side);
this.glassOffsetX = 0;
this.glassOffsetY = 0;
@@ -35,6 +35,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -46,7 +47,7 @@ public class WindowGenesis extends Window {
private ControlListBox<Gene> geneOptions;
private Panel panelPickup;
public WindowGenesis(final EntityPlayer player, final IInventory inventory, final Side side) {
public WindowGenesis(final EntityPlayer player, @Nullable final IInventory inventory, final Side side) {
super(342, 228, player, inventory, side);
}
@@ -149,7 +150,7 @@ public class WindowGenesis extends Window {
this.refreshTemplate(null);
}
private void refreshTemplate(final IChromosomeType selection) {
private void refreshTemplate(@Nullable final IChromosomeType selection) {
final List<Gene> genes = new ArrayList<>();
final IChromosomeType[] arr$;
final IChromosomeType[] chromos = arr$ = Binnie.GENETICS.getChromosomeMap(this.root).keySet().toArray(new IChromosomeType[0]);
@@ -51,18 +51,15 @@ public class ControlList<T> extends Control implements IControlValue<T> {
final IWidget child = this.optionWidgets.get(value);
this.parent.ensureVisible(child.y(), child.y() + child.h(), this.h());
}
this.getParent().callEvent(new EventValueChanged<Object>(this.getParent(), value));
this.parent.callEvent(new EventValueChanged<Object>(this.parent, value));
}
public void setOptions(final Collection<T> options) {
this.deleteAllChildren();
this.allOptions.clear();
for (final T option : options) {
@SuppressWarnings("unchecked")
final IWidget optionWidget = ((ControlListBox<T>) this.getParent()).createOption(option, 0);
if (optionWidget != null) {
this.allOptions.put(option, optionWidget);
}
final IWidget optionWidget = this.parent.createOption(option, 0);
this.allOptions.put(option, optionWidget);
}
this.filterOptions();
}
@@ -16,7 +16,10 @@ public class ControlListBox<T> extends ControlScrollableContent<ControlList<T>>
@Override
public void initialise() {
this.setScrollableContent(new ControlList<>(this, 1, 1, this.w() - 2 - this.scrollBarSize, this.h() - 2, this.getContent().getDefaultValue()));
ControlList<T> content = this.getContent();
T defaultValue = content.getDefaultValue();
ControlList<T> child = new ControlList<>(this, 1, 1, this.w() - 2 - this.scrollBarSize, this.h() - 2, defaultValue);
this.setScrollableContent(child);
this.addEventHandler(new EventKey.Down.Handler() {
@Override
public void onEvent(final EventKey.Down event) {
@@ -2,15 +2,20 @@ package binnie.craftgui.core;
import binnie.craftgui.core.geometry.IPoint;
import javax.annotation.Nullable;
public interface ITopLevelWidget extends IWidget {
void setMousePosition(final int p0, final int p1);
IPoint getAbsoluteMousePosition();
@Nullable
IWidget getFocusedWidget();
@Nullable
IWidget getMousedOverWidget();
@Nullable
IWidget getDraggedWidget();
boolean isFocused(final IWidget p0);
@@ -5,9 +5,11 @@ import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.events.Event;
import binnie.craftgui.events.EventHandler;
import javax.annotation.Nullable;
import java.util.List;
public interface IWidget {
@Nullable
IWidget getParent();
void deleteChild(final IWidget p0);
@@ -98,8 +100,10 @@ public interface IWidget {
void onDelete();
<T> T getWidget(final Class<T> p0);
@Nullable
<T> T getWidget(final Class<T> widgetClass);
@Nullable
IArea getCroppedZone();
void setCroppedZone(final IWidget p0, final IArea p1);
@@ -1,10 +1,12 @@
package binnie.craftgui.core;
import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.events.EventWidget;
import org.lwjgl.input.Mouse;
import javax.annotation.Nullable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
@@ -13,8 +15,11 @@ import java.util.List;
import java.util.ListIterator;
public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
@Nullable
IWidget mousedOverWidget;
@Nullable
IWidget draggedWidget;
@Nullable
IWidget focusedWidget;
protected IPoint mousePosition;
IPoint dragStart;
@@ -47,7 +52,7 @@ public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
});
}
public void setMousedOverWidget(final IWidget widget) {
public void setMousedOverWidget(@Nullable final IWidget widget) {
if (this.mousedOverWidget == widget) {
return;
}
@@ -60,11 +65,11 @@ public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
}
}
public void setDraggedWidget(final IWidget widget) {
public void setDraggedWidget(@Nullable final IWidget widget) {
this.setDraggedWidget(widget, -1);
}
public void setDraggedWidget(final IWidget widget, final int button) {
public void setDraggedWidget(@Nullable final IWidget widget, final int button) {
if (this.draggedWidget == widget) {
return;
}
@@ -77,7 +82,7 @@ public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
}
}
public void setFocusedWidget(final IWidget widget) {
public void setFocusedWidget(@Nullable final IWidget widget) {
IWidget newWidget = widget;
if (this.focusedWidget == newWidget) {
return;
@@ -95,16 +100,19 @@ public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
}
@Override
@Nullable
public IWidget getMousedOverWidget() {
return this.mousedOverWidget;
}
@Override
@Nullable
public IWidget getDraggedWidget() {
return this.draggedWidget;
}
@Override
@Nullable
public IWidget getFocusedWidget() {
return this.focusedWidget;
}
@@ -137,6 +145,7 @@ public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
}
}
@Nullable
private IWidget calculateMousedOverWidget() {
final Deque<IWidget> queue = this.calculateMousedOverWidgets();
while (!queue.isEmpty()) {
@@ -167,8 +176,9 @@ public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
private Collection<IWidget> getQueuedWidgets(final IWidget widget) {
final List<IWidget> widgets = new ArrayList<>();
boolean addChildren = true;
if (widget.isCroppedWidet()) {
addChildren = widget.getCroppedZone().contains(widget.getCropWidget().getRelativeMousePosition());
IArea croppedZone = widget.getCroppedZone();
if (croppedZone != null) {
addChildren = croppedZone.contains(widget.getCropWidget().getRelativeMousePosition());
}
if (addChildren) {
final ListIterator<IWidget> li = widget.getWidgets().listIterator(widget.getWidgets().size());
+34 -23
View File
@@ -6,19 +6,23 @@ import binnie.craftgui.events.Event;
import binnie.craftgui.events.EventHandler;
import binnie.craftgui.events.EventWidget;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.List;
public class Widget implements IWidget {
@Nullable
private final IWidget parent;
private List<IWidget> subWidgets;
private List<IWidgetAttribute> attributes;
private IPoint position;
private IPoint size;
private IPoint offset;
@Nullable
IArea cropArea;
@Nullable
IWidget cropWidget;
boolean cropped;
int colour;
@@ -26,7 +30,7 @@ public class Widget implements IWidget {
private boolean enabled;
private boolean visible;
public Widget(final IWidget parent) {
public Widget(@Nullable final IWidget parent) {
this.subWidgets = new ArrayList<>();
this.attributes = new ArrayList<>();
this.position = IPoint.ZERO;
@@ -38,7 +42,9 @@ public class Widget implements IWidget {
this.enabled = true;
this.visible = true;
this.parent = parent;
parent.addWidget(this);
if (parent != null) {
parent.addWidget(this);
}
}
@Override
@@ -73,13 +79,14 @@ public class Widget implements IWidget {
}
@Override
@Nullable
public final IWidget getParent() {
return this.parent;
}
@Override
public final ITopLevelWidget getSuperParent() {
return (ITopLevelWidget) (this.isTopLevel() ? this : this.parent.getSuperParent());
return (ITopLevelWidget) (this.parent == null ? this : this.parent.getSuperParent());
}
@Override
@@ -137,6 +144,7 @@ public class Widget implements IWidget {
}
@Override
@Nullable
public IArea getCroppedZone() {
return this.cropArea;
}
@@ -150,12 +158,14 @@ public class Widget implements IWidget {
@Override
public final IPoint getAbsolutePosition() {
return this.isTopLevel() ? this.getPosition() : this.getParent().getAbsolutePosition().add(this.getPosition());
IWidget parent = this.getParent();
return parent == null ? this.getPosition() : parent.getAbsolutePosition().add(this.getPosition());
}
@Override
public final IPoint getOriginalAbsolutePosition() {
return this.isTopLevel() ? this.getOriginalPosition() : this.getParent().getOriginalPosition().sub(this.getOriginalPosition());
IWidget parent = this.getParent();
return parent == null ? this.getOriginalPosition() : parent.getOriginalPosition().sub(this.getOriginalPosition());
}
@Override
@@ -238,11 +248,8 @@ public class Widget implements IWidget {
((EventHandler<Event>)handler).onEvent(event);
}
}
try {
for (final IWidget child : this.getWidgets()) {
child.recieveEvent(event);
}
} catch (ConcurrentModificationException e) {
for (final IWidget child : this.getWidgets()) {
child.recieveEvent(event);
}
}
@@ -253,7 +260,8 @@ public class Widget implements IWidget {
@Override
public final IPoint getRelativeMousePosition() {
return this.isTopLevel() ? this.getMousePosition() : this.getParent().getRelativeMousePosition().sub(this.getPosition());
IWidget parent = this.getParent();
return parent == null ? this.getMousePosition() : parent.getRelativeMousePosition().sub(this.getPosition());
}
@Override
@@ -309,7 +317,7 @@ public class Widget implements IWidget {
@Override
public final boolean calculateIsMouseOver() {
final IPoint mouse = this.getRelativeMousePosition();
if (!this.cropped) {
if (!this.cropped || this.cropArea == null) {
return this.isMouseOverWidget(mouse);
}
final IWidget cropRelative = (this.cropWidget != null) ? this.cropWidget : this;
@@ -351,8 +359,9 @@ public class Widget implements IWidget {
@Override
public boolean isEnabled() {
if (this.enabled) {
if (!this.isTopLevel()) {
if (!this.getParent().isEnabled() || !this.getParent().isChildEnabled(this)) {
IWidget parent = this.getParent();
if (parent != null) {
if (!parent.isEnabled() || !parent.isChildEnabled(this)) {
return false;
}
}
@@ -364,8 +373,9 @@ public class Widget implements IWidget {
@Override
public final boolean isVisible() {
if (this.visible) {
if (!this.isTopLevel()) {
if (!this.getParent().isVisible() || !this.getParent().isChildVisible(this)) {
IWidget parent = this.getParent();
if (parent != null) {
if (!parent.isVisible() || !parent.isChildVisible(this)) {
return false;
}
}
@@ -437,12 +447,13 @@ public class Widget implements IWidget {
@Override
@SuppressWarnings("unchecked")
public <T> T getWidget(final Class<T> x) {
@Nullable
public <T> T getWidget(final Class<T> widgetClass) {
for (final IWidget child : this.getWidgets()) {
if (x.isInstance(child)) {
if (widgetClass.isInstance(child)) {
return (T) child;
}
final T found = child.getWidget(x);
final T found = child.getWidget(widgetClass);
if (found != null) {
return found;
}
@@ -468,10 +479,10 @@ public class Widget implements IWidget {
@Override
public boolean isDescendant(final IWidget widget) {
IWidget clss = this;
while (clss != widget) {
clss = clss.getParent();
if (clss == null) {
IWidget parentWidget = this;
while (parentWidget != widget) {
parentWidget = parentWidget.getParent();
if (parentWidget == null) {
return false;
}
}
@@ -20,6 +20,7 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.client.config.GuiUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class RenderUtil {
@@ -158,7 +159,7 @@ public class RenderUtil {
}
}
public static void drawFluid(IPoint pos, FluidStack fluid) {
public static void drawFluid(IPoint pos, @Nullable FluidStack fluid) {
GlStateManager.enableBlend();
GlStateManager.enableAlpha();
@@ -14,6 +14,8 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraftforge.fml.client.config.GuiUtils;
import org.lwjgl.opengl.GL11;
import javax.annotation.Nullable;
public class TextureRenderer {
private static void renderTexturePadded(final IArea area, final IArea texture, final IBorder padding) {
int borderLeft = padding.l();
@@ -117,7 +119,7 @@ public class TextureRenderer {
return this.styleSheet.getTexture(key);
}
public void setTexture(final Texture texture) {
public void setTexture(@Nullable final Texture texture) {
if (texture != null) {
BinnieCore.getBinnieProxy().bindTexture(texture.getFilename());
}
@@ -127,7 +129,7 @@ public class TextureRenderer {
this.texture(this.getTexture(texture), position);
}
public void texture(final Texture texture, final IPoint position) {
public void texture(@Nullable final Texture texture, final IPoint position) {
if (texture == null) {
return;
}
@@ -141,7 +143,7 @@ public class TextureRenderer {
this.texture(this.getTexture(window), area);
}
public void texture(final Texture texture, final IArea area) {
public void texture(@Nullable final Texture texture, final IArea area) {
if (texture == null) {
return;
}
@@ -45,6 +45,7 @@ public class ContainerCraftGUI extends Container {
private PowerInfo syncedPower;
private ProcessInfo syncedProcess;
private int errorType;
@Nullable
private ErrorState error;
private int mousedOverSlotNumber;
private final Set<EntityPlayer> crafters = Sets.newConcurrentHashSet();
@@ -79,25 +80,28 @@ public class ContainerCraftGUI extends Container {
}
@Override
public Slot getSlot(final int par1) {
if (par1 < 0 || par1 >= this.inventorySlots.size()) {
@Nullable
public Slot getSlot(final int index) {
if (index < 0 || index >= this.inventorySlots.size()) {
return null;
}
return this.inventorySlots.get(par1);
return this.inventorySlots.get(index);
}
@Override
public void putStackInSlot(final int par1, final ItemStack par2ItemStack) {
if (this.getSlot(par1) != null) {
this.getSlot(par1).putStack(par2ItemStack);
public void putStackInSlot(final int index, final ItemStack par2ItemStack) {
Slot slot = this.getSlot(index);
if (slot != null) {
slot.putStack(par2ItemStack);
}
}
@Override
public void putStacksInSlots(final ItemStack[] par1ArrayOfItemStack) {
for (int i = 0; i < par1ArrayOfItemStack.length; ++i) {
if (this.getSlot(i) != null) {
this.getSlot(i).putStack(par1ArrayOfItemStack[i]);
Slot slot = this.getSlot(i);
if (slot != null) {
slot.putStack(par1ArrayOfItemStack[i]);
}
}
}
@@ -111,7 +115,8 @@ public class ContainerCraftGUI extends Container {
if (inventory.dispenseOnClose(i)) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack != null) {
stack = new TransferRequest(stack, par1EntityPlayer.inventory).transfer(true);
TransferRequest transferRequest = new TransferRequest(stack, par1EntityPlayer.inventory);
stack = transferRequest.transfer(true);
if (stack != null) {
par1EntityPlayer.dropItem(stack, false);
}
@@ -22,6 +22,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +31,7 @@ import java.util.List;
public class GuiCraftGUI extends GuiContainer {
IPoint mousePos;
private Window window;
@Nullable
private ItemStack draggedItem;
@Override
@@ -63,6 +65,7 @@ public class GuiCraftGUI extends GuiContainer {
this.window.initGui();
}
@Nullable
public ItemStack getDraggedItem() {
return this.draggedItem;
}
@@ -46,9 +46,11 @@ import java.util.ArrayList;
import java.util.Deque;
public abstract class Window extends TopLevelWidget implements INetwork.RecieveGuiNBT {
@Nullable
private GuiCraftGUI gui;
private ContainerCraftGUI container;
private WindowInventory windowInventory;
@Nullable
private ControlText title;
protected int titleButtonLeft;
protected int titleButtonRight;
@@ -57,6 +59,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
@Nullable
private StandardTexture bgText2;
private boolean hasBeenInitialised;
@Nullable
private EntityPlayer player;
@Nullable
private IInventory entityInventory;
@@ -118,6 +121,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
return Machine.getInterface(IInventoryMachine.class, this.getInventory()) != null;
}
@Nullable
public String showInfoButton() {
IMachineInformation machineInformation = Machine.getInterface(IMachineInformation.class, this.getInventory());
if (machineInformation != null) {
@@ -126,7 +130,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
return null;
}
public Window(final int width, final int height, final EntityPlayer player, final IInventory inventory, final Side side) {
public Window(final int width, final int height, final EntityPlayer player, @Nullable final IInventory inventory, final Side side) {
this.titleButtonLeft = 8;
this.titleButtonRight = 8;
this.bgText1 = null;
@@ -150,8 +154,9 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
if (this.showHelpButton()) {
new ControlHelp(this, this.titleButtonLeft += 22, 8);
}
if (this.showInfoButton() != null) {
new ControlInfo(this, this.titleButtonLeft += 22, 8, this.showInfoButton());
String showInfoButton = this.showInfoButton();
if (showInfoButton != null) {
new ControlInfo(this, this.titleButtonLeft += 22, 8, showInfoButton);
}
this.addSelfEventHandler(new EventWidget.ChangeSize.Handler() {
@Override
@@ -171,6 +176,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
}
@SideOnly(Side.CLIENT)
@Nullable
public final GuiCraftGUI getGui() {
return this.gui;
}
@@ -231,6 +237,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
return this.getPlayer().getGameProfile();
}
@Nullable
public ItemStack getHeldItemStack() {
if (this.player != null) {
return this.player.inventory.getItemStack();
@@ -243,7 +250,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
return this.entityInventory;
}
public void setInventories(final EntityPlayer player2, final IInventory inventory) {
public void setInventories(final EntityPlayer player2, @Nullable final IInventory inventory) {
this.player = player2;
this.entityInventory = inventory;
}
@@ -302,10 +309,12 @@ public abstract class Window extends TopLevelWidget implements INetwork.RecieveG
public void onWindowInventoryChanged() {
}
@Nullable
public Texture getBackground1() {
return this.bgText1;
}
@Nullable
public Texture getBackground2() {
return this.bgText2;
}
@@ -11,7 +11,6 @@ public class ControlImage extends Control {
public ControlImage(final IWidget parent, final int x, final int y, final Texture text) {
super(parent, x, y, text.w(), text.h());
this.key = null;
this.key = text;
}
@@ -11,7 +11,10 @@ import binnie.craftgui.minecraft.Window;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public class ControlItemDisplay extends Control implements ITooltip {
@Nullable
private ItemStack itemStack;
public boolean hastooltip;
private boolean rotating;
@@ -68,6 +71,7 @@ public class ControlItemDisplay extends Control implements ITooltip {
this.itemStack = itemStack;
}
@Nullable
public ItemStack getItemStack() {
return this.itemStack;
}
@@ -16,6 +16,7 @@ import binnie.craftgui.core.geometry.IArea;
import binnie.craftgui.core.geometry.IPoint;
import binnie.craftgui.core.renderer.RenderUtil;
import binnie.craftgui.events.EventMouse;
import binnie.craftgui.minecraft.GuiCraftGUI;
import binnie.craftgui.minecraft.MinecraftTooltip;
import binnie.craftgui.minecraft.Window;
import binnie.craftgui.resource.minecraft.CraftGUITexture;
@@ -26,6 +27,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
import org.lwjgl.opengl.GL11;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -75,17 +77,20 @@ public class ControlLiquidTank extends Control implements ITooltip {
@Override
public void onRenderBackground(int guiWidth, int guiHeight) {
CraftGUI.render.texture(this.horizontal ? CraftGUITexture.HorizontalLiquidTank : CraftGUITexture.LiquidTank, IPoint.ZERO);
if (this.isMouseOver() && Window.get(this).getGui().isHelpMode()) {
final int c = -1442840576 + MinecraftTooltip.getOutline(Tooltip.Type.Help);
RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
} else if (ControlLiquidTank.tankError.contains(this.tankID)) {
final int c = -1442840576 + MinecraftTooltip.getOutline(MinecraftTooltip.Type.Error);
RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
} else if (this.getSuperParent().getMousedOverWidget() == this) {
if (Window.get(this).getGui().getDraggedItem() != null) {
RenderUtil.drawGradientRect(this.getArea().inset(1), -1426089575, -1426089575);
} else {
RenderUtil.drawGradientRect(this.getArea().inset(1), -2130706433, -2130706433);
GuiCraftGUI gui = Window.get(this).getGui();
if (gui != null) {
if (this.isMouseOver() && gui.isHelpMode()) {
final int c = -1442840576 + MinecraftTooltip.getOutline(Tooltip.Type.Help);
RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
} else if (ControlLiquidTank.tankError.contains(this.tankID)) {
final int c = -1442840576 + MinecraftTooltip.getOutline(MinecraftTooltip.Type.Error);
RenderUtil.drawGradientRect(this.getArea().inset(1), c, c);
} else if (this.getSuperParent().getMousedOverWidget() == this) {
if (gui.getDraggedItem() != null) {
RenderUtil.drawGradientRect(this.getArea().inset(1), -1426089575, -1426089575);
} else {
RenderUtil.drawGradientRect(this.getArea().inset(1), -2130706433, -2130706433);
}
}
}
if (this.isTankValid()) {
@@ -128,7 +133,8 @@ public class ControlLiquidTank extends Control implements ITooltip {
@Override
public void onRenderForeground(int guiWidth, int guiHeight) {
CraftGUI.render.texture(this.horizontal ? CraftGUITexture.HorizontalLiquidTankOverlay : CraftGUITexture.LiquidTankOverlay, IPoint.ZERO);
if (this.isMouseOver() && Window.get(this).getGui().isHelpMode()) {
GuiCraftGUI gui = Window.get(this).getGui();
if (this.isMouseOver() && gui != null && gui.isHelpMode()) {
final IArea area = this.getArea();
RenderUtil.setColour(MinecraftTooltip.getOutline(Tooltip.Type.Help));
CraftGUI.render.texture(CraftGUITexture.Outline, area.outset(1));
@@ -167,6 +173,7 @@ public class ControlLiquidTank extends Control implements ITooltip {
tooltip.add("Empty");
}
@Nullable
private TankSlot getTankSlot() {
final ITankMachine tank = Machine.getInterface(ITankMachine.class, Window.get(this).getInventory());
return (tank != null) ? tank.getTankSlot(this.tankID) : null;
@@ -14,7 +14,10 @@ import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.ISpeciesRoot;
import javax.annotation.Nullable;
public class ControlDatabaseIndividualDisplay extends ControlItemDisplay implements ITooltip {
@Nullable
private IAlleleSpecies species;
EnumDiscoveryState discovered;
@@ -24,7 +27,7 @@ public class ControlDatabaseIndividualDisplay extends ControlItemDisplay impleme
public void setSpecies(final IAlleleSpecies species, EnumDiscoveryState state) {
final ISpeciesRoot speciesRoot = Binnie.GENETICS.getSpeciesRoot(species);
final BreedingSystem system = Binnie.GENETICS.getSystem(speciesRoot.getUID());
final BreedingSystem system = Binnie.GENETICS.getSystem(speciesRoot);
final IIndividual ind = system.getSpeciesRoot().templateAsIndividual(system.getSpeciesRoot().getTemplate(species.getUID()));
super.setItemStack(system.getSpeciesRoot().getMemberStack(ind, system.getDefaultType()));
this.species = species;
@@ -17,6 +17,8 @@ import forestry.api.apiculture.IHiveFrame;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import javax.annotation.Nullable;
public class AlvearyFrame {
public static int slotFrame = 0;
@@ -66,6 +68,7 @@ public class AlvearyFrame {
this.getInventory().setInventorySlotContents(AlvearyFrame.slotFrame, this.getHiveFrame().frameUsed(((TileExtraBeeAlveary) this.getMachine().getTileEntity()).getMultiblockLogic().getController(), this.getInventory().getStackInSlot(AlvearyFrame.slotFrame), null, wear));
}
@Nullable
public IHiveFrame getHiveFrame() {
ItemStack stackInSlot = this.getInventory().getStackInSlot(AlvearyFrame.slotFrame);
if (stackInSlot != null) {
@@ -28,7 +28,7 @@ public class AlvearyMutator {
return getMutationMult(item) > 0.0f;
}
public static float getMutationMult(final ItemStack item) {
public static float getMutationMult(@Nullable final ItemStack item) {
if (item == null) {
return 1.0f;
}
@@ -23,6 +23,7 @@ import forestry.api.circuits.ICircuitBoard;
import forestry.api.circuits.ICircuitLayout;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -84,6 +85,7 @@ public class AlvearyStimulator {
this.powered = this.getUtil().hasEnergyMJ(this.powerUsage);
}
@Nullable
public ICircuitBoard getHiveFrame() {
if (!this.getUtil().isSlotEmpty(AlvearyStimulator.slotCircuit)) {
return ChipsetManager.circuitRegistry.getCircuitBoard(this.getUtil().getStack(AlvearyStimulator.slotCircuit));
@@ -84,7 +84,7 @@ public enum Cocktail {
}
public static boolean isIngredient(final String name) {
return name != null && Cocktail.cocktailIngredients.containsKey(name.toLowerCase());
return Cocktail.cocktailIngredients.containsKey(name.toLowerCase());
}
static {
@@ -22,7 +22,7 @@ public class DrinkManager {
}
public static IDrinkLiquid getLiquid(final FluidStack fluid) {
return (fluid != null) ? getLiquid(fluid.getFluid()) : null;
return getLiquid(fluid.getFluid());
}
}
@@ -2,13 +2,14 @@ package binnie.extratrees.api;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
public interface ICarpentryInterface {
boolean registerCarpentryWood(final int p0, final IDesignMaterial p1);
boolean registerCarpentryWood(final int index, final IDesignMaterial material);
int getCarpentryWoodIndex(final IDesignMaterial p0);
int getCarpentryWoodIndex(final IDesignMaterial material);
IDesignMaterial getWoodMaterial(final int p0);
@@ -20,7 +21,8 @@ public interface ICarpentryInterface {
ILayout getLayout(final IPattern p0, final boolean p1);
IDesignMaterial getWoodMaterial(final ItemStack p0);
@Nullable
IDesignMaterial getWoodMaterial(final ItemStack stack);
boolean registerDesignCategory(final IDesignCategory p0);
@@ -3,15 +3,20 @@ package binnie.extratrees.api;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public interface IDesignSystem {
@Nullable
TextureAtlasSprite getPrimarySprite(final IPattern pattern);
@Nullable
TextureAtlasSprite getSecondarySprite(final IPattern pattern);
void registerSprites();
IDesignMaterial getDefaultMaterial();
@Nullable
IDesignMaterial getMaterial(final int p0);
int getMaterialIndex(final IDesignMaterial p0);
@@ -241,9 +241,6 @@ public abstract class BlockETDecorativeLeaves extends Block implements IItemMode
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) {
ETTreeDefinition treeDefinition = state.getValue(getVariant());
if (treeDefinition == null) {
return PluginArboriculture.proxy.getFoliageColorBasic();
}
ITreeGenome genome = treeDefinition.getGenome();
@@ -39,9 +39,7 @@ public class BlockETFenceGate extends BlockFenceGate implements IBlockMetadata {
public void getSubBlocks(final Item itemIn, final CreativeTabs par2CreativeTabs, final List<ItemStack> itemList) {
for (final IPlankType type : WoodManager.getAllPlankTypes()) {
final ItemStack gate = WoodManager.getGate(type);
if (gate != null) {
itemList.add(gate);
}
itemList.add(gate);
}
}
@@ -4,7 +4,6 @@ import binnie.Binnie;
import binnie.core.block.BlockMetadata;
import binnie.core.block.TileEntityMetadata;
import binnie.extratrees.ExtraTrees;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
@@ -15,6 +14,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.List;
public class BlockCarpentryPanel extends BlockCarpentry {
@@ -80,13 +80,13 @@ public class BlockCarpentryPanel extends BlockCarpentry {
return ModuleCarpentry.getCarpentryPanel(this.getDesignSystem(), TileEntityMetadata.getTileMetadata(world, pos));
}
public static boolean isValidPanelPlacement(IBlockAccess world, BlockPos pos, EnumFacing facing) {
public static boolean isValidPanelPlacement(IBlockAccess world, BlockPos pos, @Nullable EnumFacing facing) {
if (facing == null) {
return false;
}
pos = pos.offset(facing);
IBlockState state = world.getBlockState(pos);
return state != null && state.isSideSolid(world, pos, facing.getOpposite());
return state.isSideSolid(world, pos, facing.getOpposite());
}
@Override
@@ -75,7 +75,7 @@ public abstract class BlockDesign extends BlockMetadata implements IMultipassBlo
}
final DesignBlock block = blockC.getCarpentryBlock(world, pos);
final TileEntityMetadata tile = TileUtil.getTile(world, pos, TileEntityMetadata.class);
if (tile != null) {
if (tile != null && event.getFace() != null) {
block.rotate(event.getFace(), item, player, world, pos);
final int meta = block.getBlockMetadata(blockC.getDesignSystem());
tile.setTileMetadata(meta, true);
@@ -8,6 +8,7 @@ import binnie.extratrees.api.ILayout;
import binnie.extratrees.api.IPattern;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -22,7 +23,7 @@ public class CarpentryInterface implements ICarpentryInterface {
@Override
public boolean registerCarpentryWood(final int index, final IDesignMaterial wood) {
return wood != null && CarpentryInterface.woodMap.put(index, wood) == null;
return CarpentryInterface.woodMap.put(index, wood) == null;
}
@Override
@@ -42,7 +43,7 @@ public class CarpentryInterface implements ICarpentryInterface {
@Override
public boolean registerDesign(final int index, final IDesign wood) {
return wood != null && CarpentryInterface.designMap.put(index, wood) == null;
return CarpentryInterface.designMap.put(index, wood) == null;
}
@Override
@@ -67,7 +68,7 @@ public class CarpentryInterface implements ICarpentryInterface {
@Override
public boolean registerDesignCategory(final IDesignCategory category) {
return category != null && category.getId() != null && CarpentryInterface.designCategories.put(category.getId(), category) == null;
return CarpentryInterface.designCategories.put(category.getId(), category) == null;
}
@Override
@@ -96,16 +97,11 @@ public class CarpentryInterface implements ICarpentryInterface {
}
@Override
@Nullable
public IDesignMaterial getWoodMaterial(final ItemStack stack) {
if (stack == null) {
return null;
}
for (final Map.Entry<Integer, IDesignMaterial> entry : CarpentryInterface.woodMap.entrySet()) {
for(boolean fireproof : new boolean[]{true, false}){
final ItemStack key = entry.getValue().getStack(fireproof);
if (key == null) {
continue;
}
if (key.isItemEqual(stack)) {
return entry.getValue();
}
@@ -14,6 +14,8 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
public class DesignBlock {
IDesign design;
IDesignMaterial primaryMaterial;
@@ -39,27 +41,32 @@ public class DesignBlock {
return this.secondaryMaterial;
}
DesignBlock(final IDesignSystem system, final IDesignMaterial primaryWood, final IDesignMaterial secondaryWood, final IDesign design, final int rotation, final EnumFacing dir) {
DesignBlock(final IDesignSystem system, @Nullable final IDesignMaterial primaryWood, @Nullable final IDesignMaterial secondaryWood, @Nullable final IDesign design, final int rotation, @Nullable final EnumFacing dir) {
this.panel = false;
this.design = design;
this.primaryMaterial = primaryWood;
this.secondaryMaterial = secondaryWood;
this.rotation = rotation;
this.facing = dir;
if (design == null) {
this.design = EnumDesign.Blank;
} else {
this.design = design;
}
if (primaryWood == null) {
this.primaryMaterial = system.getDefaultMaterial();
} else {
this.primaryMaterial = primaryWood;
}
if (secondaryWood == null) {
this.secondaryMaterial = system.getDefaultMaterial();
} else {
this.secondaryMaterial = secondaryWood;
}
if (this.rotation > 3 || this.rotation < 0) {
this.rotation = 0;
}
if (this.facing == null) {
if (dir == null) {
this.facing = EnumFacing.UP;
} else {
this.facing = dir;
}
}
@@ -379,13 +386,13 @@ public class DesignBlock {
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getPrimarySprite(IDesignSystem system, EnumFacing facing) {
ILayout layout = this.getLayout(facing);
return (layout == null) ? null : layout.getPrimarySprite(system);
return layout.getPrimarySprite(system);
}
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getSecondarySprite(IDesignSystem system, EnumFacing facing) {
ILayout layout = this.getLayout(facing);
return (layout == null) ? null : layout.getSecondarySprite(system);
return layout.getSecondarySprite(system);
}
@SideOnly(Side.CLIENT)
@@ -13,6 +13,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
@@ -60,6 +61,7 @@ public enum DesignSystem implements IDesignSystem {
}
@Override
@Nullable
public IDesignMaterial getMaterial(final int id) {
switch (this) {
case Glass: {
@@ -134,6 +136,7 @@ public enum DesignSystem implements IDesignSystem {
}
@Override
@Nullable
public TextureAtlasSprite getPrimarySprite(final IPattern pattern) {
if (pattern instanceof EnumPattern) {
return this.primary.get(((EnumPattern) pattern).ordinal());
@@ -142,6 +145,7 @@ public enum DesignSystem implements IDesignSystem {
}
@Override
@Nullable
public TextureAtlasSprite getSecondarySprite(final IPattern pattern) {
if (pattern instanceof EnumPattern) {
return this.secondary.get(((EnumPattern) pattern).ordinal());
@@ -138,10 +138,12 @@ public class AlleleETFruit extends AlleleCategorized implements IAlleleFruit, IF
private IFruitFamily family;
private boolean isRipening;
private int diffR, diffG, diffB;
@Nullable
private FruitPod pod;
private int ripeningPeriod;
private int colourUnripe;
private int colour;
@Nullable
private FruitSprite sprite;
private Map<ItemStack, Float> products;
@@ -15,9 +15,12 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.client.FMLClientHandler;
import javax.annotation.Nullable;
public class ControlFluidDisplay extends Control implements ITooltip {
FluidStack itemStack;
public boolean hastooltip;
@Nullable
private FluidStack fluidStack;
private boolean hastooltip;
public void setTooltip() {
this.hastooltip = true;
@@ -30,7 +33,7 @@ public class ControlFluidDisplay extends Control implements ITooltip {
public ControlFluidDisplay(final IWidget parent, final int x, final int y, final FluidStack stack, final boolean tooltip) {
this(parent, x, y, 16);
this.setItemStack(stack);
this.setFluidStack(stack);
if (tooltip) {
this.setTooltip();
}
@@ -38,26 +41,26 @@ public class ControlFluidDisplay extends Control implements ITooltip {
public ControlFluidDisplay(final IWidget parent, final int x, final int y, final int size) {
super(parent, x, y, size, size);
this.itemStack = null;
this.fluidStack = null;
this.hastooltip = false;
}
@Override
public void onRenderForeground(int guiWidth, int guiHeight) {
if (this.itemStack == null) {
if (this.fluidStack == null) {
return;
}
final IPoint relativeToWindow = this.getAbsolutePosition().sub(this.getSuperParent().getPosition());
if (relativeToWindow.x() > Window.get(this).getSize().x() + 100 || relativeToWindow.y() > Window.get(this).getSize().y() + 100) {
return;
}
if (this.itemStack != null) {
final Fluid fluid = this.itemStack.getFluid();
final int hex = fluid.getColor(this.itemStack);
if (this.fluidStack != null) {
final Fluid fluid = this.fluidStack.getFluid();
final int hex = fluid.getColor(this.fluidStack);
final int r = (hex & 0xFF0000) >> 16;
final int g = (hex & 0xFF00) >> 8;
final int b = hex & 0xFF;
final ResourceLocation iconRL = this.itemStack.getFluid().getStill();
final ResourceLocation iconRL = this.fluidStack.getFluid().getStill();
TextureAtlasSprite icon = FMLClientHandler.instance().getClient().getTextureMapBlocks().getAtlasSprite(iconRL.toString());
GlStateManager.color(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
GlStateManager.enableBlend();
@@ -75,14 +78,14 @@ public class ControlFluidDisplay extends Control implements ITooltip {
}
}
public void setItemStack(final FluidStack itemStack) {
this.itemStack = itemStack;
public void setFluidStack(final FluidStack fluidStack) {
this.fluidStack = fluidStack;
}
@Override
public void getTooltip(final Tooltip tooltip) {
if (this.hastooltip && this.itemStack != null) {
tooltip.add(this.itemStack.getLocalizedName());
if (this.hastooltip && this.fluidStack != null) {
tooltip.add(this.fluidStack.getLocalizedName());
}
}
}
@@ -48,7 +48,7 @@ public class ControlSlotFluid extends Control implements ITooltip {
@Override
public void onUpdateClient() {
super.onUpdateClient();
this.itemDisplay.setItemStack(this.getFluidStack());
this.itemDisplay.setFluidStack(this.getFluidStack());
}
@Override
@@ -20,6 +20,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
import java.util.Map;
public abstract class Designer {
@@ -63,12 +64,9 @@ public abstract class Designer {
public void createMachine(final Machine machine) {
new ExtraTreeMachine.ComponentExtraTreeGUI(machine, ExtraTreesGUID.Woodworker);
final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
inventory.addSlot(Designer.beeswaxSlot, "polish");
inventory.addSlot(Designer.design1Slot, "wood");
inventory.addSlot(Designer.design2Slot, "wood");
inventory.getSlot(Designer.beeswaxSlot).setValidator(new Validators.SlotValidatorBeeswax(this.type));
inventory.getSlot(Designer.design1Slot).setValidator(new Validators.SlotValidatorPlanks(this.type));
inventory.getSlot(Designer.design2Slot).setValidator(new Validators.SlotValidatorPlanks(this.type));
inventory.addSlot(Designer.beeswaxSlot, "polish").setValidator(new Validators.SlotValidatorBeeswax(this.type));
inventory.addSlot(Designer.design1Slot, "wood").setValidator(new Validators.SlotValidatorPlanks(this.type));
inventory.addSlot(Designer.design2Slot, "wood").setValidator(new Validators.SlotValidatorPlanks(this.type));
new ComponentWoodworkerRecipe(machine, this.type);
}
}
@@ -102,6 +100,7 @@ public abstract class Designer {
}
@Override
@Nullable
public ItemStack getProduct() {
final ItemStack plank1 = this.getUtil().getStack(Designer.design1Slot);
final ItemStack plank2 = this.getUtil().getStack(Designer.design2Slot);
@@ -111,11 +110,11 @@ public abstract class Designer {
final IDesignMaterial type1 = this.type.getSystem().getMaterial(plank1);
final IDesignMaterial type2 = this.type.getSystem().getMaterial(plank2);
final IDesign design = this.getDesign();
final ItemStack stack = this.type.getBlock(type1, type2, design);
return stack;
return this.type.getBlock(type1, type2, design);
}
@Override
@Nullable
public ItemStack doRecipe(final boolean takeItem) {
if (!this.isRecipe()) {
return null;
@@ -145,23 +144,21 @@ public abstract class Designer {
if (name.equals("recipe")) {
final InventoryPlayer playerInv = player.inventory;
final ItemStack recipe = this.doRecipe(false);
if (recipe == null) {
return;
}
if (playerInv.getItemStack() == null) {
playerInv.setItemStack(this.doRecipe(true));
} else if (playerInv.getItemStack().isItemEqual(recipe) && ItemStack.areItemStackTagsEqual(playerInv.getItemStack(), recipe)) {
final int fit = recipe.getMaxStackSize() - (recipe.stackSize + playerInv.getItemStack().stackSize);
if (fit >= 0) {
final ItemStack doRecipe;
final ItemStack rec = doRecipe = this.doRecipe(true);
doRecipe.stackSize += playerInv.getItemStack().stackSize;
playerInv.setItemStack(rec);
if (recipe != null) {
if (playerInv.getItemStack() == null) {
playerInv.setItemStack(this.doRecipe(true));
} else if (playerInv.getItemStack().isItemEqual(recipe) && ItemStack.areItemStackTagsEqual(playerInv.getItemStack(), recipe)) {
final int fit = recipe.getMaxStackSize() - (recipe.stackSize + playerInv.getItemStack().stackSize);
if (fit >= 0) {
this.doRecipe(true);
recipe.stackSize += playerInv.getItemStack().stackSize;
playerInv.setItemStack(recipe);
}
}
player.openContainer.detectAndSendChanges();
if (player instanceof EntityPlayerMP) {
((EntityPlayerMP) player).updateHeldItem();
}
}
player.openContainer.detectAndSendChanges();
if (player instanceof EntityPlayerMP) {
((EntityPlayerMP) player).updateHeldItem();
}
} else if (name.equals("design")) {
this.setDesign(CarpentryManager.carpentryInterface.getDesign(nbt.getShort("d")));
@@ -8,7 +8,6 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
@@ -42,34 +41,24 @@ public class BrewedGrainRecipe implements IBreweryRecipe {
}
@Override
@Nullable
public FluidStack getOutput(final BreweryCrafting crafting) {
if (!WATER.isFluidEqual(crafting.inputFluid)) {
return null;
}
if (!isIngredient(crafting.ingredient)) {
return null;
}
if (!yeast.isItemEqual(crafting.yeast)) {
return null;
}
int grainCount = 0;
for (final ItemStack stack : crafting.inputGrains) {
if (stack == null) {
return null;
if (WATER.isFluidEqual(crafting.inputFluid) && isIngredient(crafting.ingredient) && yeast.isItemEqual(crafting.yeast)) {
int grainCount = 0;
for (final ItemStack stack : crafting.inputGrains) {
if (stack == null) {
return null;
}
if (isGrain(stack)) {
grainCount++;
}
}
if (isGrain(stack)) {
grainCount++;
if (grainCount >= 2) {
return output.copy();
}
}
if (grainCount >= 2) {
return output.copy();
} else {
return null;
}
return null;
}
@Override
@@ -51,7 +51,7 @@ public class BreweryCrafting implements INbtWritable {
return nbt;
}
private NBTTagCompound getNBT(final ItemStack ingr) {
private NBTTagCompound getNBT(@Nullable final ItemStack ingr) {
if (ingr == null) {
return new NBTTagCompound();
}
@@ -29,6 +29,7 @@ public class BreweryRecipe implements IBreweryRecipe {
}
@Override
@Nullable
public FluidStack getOutput(final BreweryCrafting crafting) {
if (!this.yeast.isItemEqual(crafting.yeast)) {
return null;
@@ -38,6 +38,7 @@ public class BreweryRecipes {
return false;
}
@Nullable
public static FluidStack getOutput(final FluidStack stack) {
final BreweryCrafting crafting = new BreweryCrafting(stack, null, null, null);
for (final IBreweryRecipe recipe : recipes) {
@@ -3,10 +3,11 @@ package binnie.extratrees.machines.brewery;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public interface IBreweryRecipe {
@Nullable
FluidStack getOutput(final BreweryCrafting crafting);
FluidStack getInput();
@@ -61,6 +61,7 @@ public class DistilleryLogic extends ComponentProcessSetCost implements IProcess
}
@Override
@Nullable
public ErrorState canWork() {
if (this.getUtil().isTankEmpty(DistilleryMachine.TANK_INPUT) && this.currentFluid == null) {
return new ErrorState.InsufficientLiquid("No Input Liquid", DistilleryMachine.TANK_INPUT);
@@ -89,7 +90,9 @@ public class DistilleryLogic extends ComponentProcessSetCost implements IProcess
@Override
protected void onFinishTask() {
final FluidStack output = DistilleryRecipes.getOutput(this.currentFluid, this.level);
this.getUtil().fillTank(DistilleryMachine.TANK_OUTPUT, output);
if (output != null) {
this.getUtil().fillTank(DistilleryMachine.TANK_OUTPUT, output);
}
this.currentFluid = null;
}
@@ -21,11 +21,13 @@ import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IIndividual;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
public class AnalystPageDatabase extends ControlAnalystPage {
@Nullable
ControlScrollableContent scroll;
boolean isMaster;
@@ -121,7 +121,7 @@ public class AnalystPageProducts extends AnalystPageProduce {
ItemStack container = getContainer(soilStack2);
if (container == null) {
final ControlFluidDisplay display2 = new ControlFluidDisplay(this, biomeListX + dx, y + dy);
display2.setItemStack(soilStack2);
display2.setFluidStack(soilStack2);
display2.setTooltip();
} else {
final ControlItemDisplay display3 = new ControlItemDisplay(this, biomeListX + dx, y + dy);
@@ -7,13 +7,14 @@ import binnie.craftgui.core.Tooltip;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.BiomeDictionary;
import javax.annotation.Nullable;
public class ControlBiome extends Control implements ITooltip {
Biome biome;
String iconCategory;
private final Biome biome;
private String iconCategory;
public ControlBiome(final IWidget parent, final int x, final int y, final int w, final int h, final Biome biome) {
super(parent, x, y, w, h);
this.biome = null;
this.iconCategory = "plains";
this.biome = biome;
}
@@ -16,12 +16,16 @@ import forestry.api.genetics.IChromosomeType;
import forestry.api.genetics.ISpeciesRoot;
import forestry.api.lepidopterology.EnumButterflyChromosome;
import javax.annotation.Nullable;
public class ControlChromosome extends Control implements IControlValue<IChromosomeType> {
Texture BeeTexture;
Texture TreeTexture;
Texture MothTexture;
Texture FlowerTexture;
@Nullable
IChromosomeType chromo;
@Nullable
ISpeciesRoot species;
public ControlChromosome(final IWidget parent, final int x, final int y) {
@@ -34,11 +38,12 @@ public class ControlChromosome extends Control implements IControlValue<IChromos
this.species = null;
}
@Nullable
public ISpeciesRoot getRoot() {
return this.species;
}
public void setRoot(final ISpeciesRoot root) {
public void setRoot(@Nullable final ISpeciesRoot root) {
if (root != this.species) {
this.species = root;
this.deleteAllChildren();
@@ -122,6 +127,7 @@ public class ControlChromosome extends Control implements IControlValue<IChromos
CraftGUI.render.texture(text, IPoint.ZERO);
}
@Nullable
private Texture getTypeTexture() {
if (this.species == Binnie.GENETICS.getBeeRoot()) {
return this.BeeTexture;
@@ -33,7 +33,7 @@ public class Acclimatiser {
private static Map<ItemStack, Float> humidityItems = new HashMap<>();
@Nullable
private static ToleranceSystem getToleranceSystem(final ItemStack stack, final ItemStack acclim) {
private static ToleranceSystem getToleranceSystem(@Nullable final ItemStack stack, final ItemStack acclim) {
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
if (root != null) {
for (final ToleranceSystem system : Acclimatiser.toleranceSystems) {
@@ -67,14 +67,14 @@ public class Acclimatiser {
return 0.0f;
}
public static void addTemperatureItem(final ItemStack itemstack, final float amount) {
public static void addTemperatureItem(@Nullable final ItemStack itemstack, final float amount) {
if (itemstack == null) {
return;
}
Acclimatiser.temperatureItems.put(itemstack, amount);
}
public static void addHumidityItem(final ItemStack itemstack, final float amount) {
public static void addHumidityItem(@Nullable final ItemStack itemstack, final float amount) {
if (itemstack == null) {
return;
}
@@ -109,7 +109,7 @@ public class Acclimatiser {
addHumidityItem(FluidContainerType.CAPSULE.getFilled(FluidRegistry.WATER), 0.75f);
}
public static boolean canAcclimatise(final ItemStack stack, final List<ItemStack> acclimatisers) {
public static boolean canAcclimatise(@Nullable final ItemStack stack, final List<ItemStack> acclimatisers) {
if (stack == null || acclimatisers.isEmpty()) {
return true;
}
@@ -136,7 +136,7 @@ public class Acclimatiser {
public static Tolerance alterTolerance(final Tolerance tol, final float effect) {
final int[] is = tol.getBounds();
int[] range = new int[2];
int[] range;
if (effect < 0.0f) {
range = new int[]{is[0] - 1, is[1]};
} else {
@@ -48,21 +48,24 @@ public class AcclimatiserLogic extends ComponentProcessIndefinate {
protected void attemptAcclimatisation() {
final List<ItemStack> acclms = new ArrayList<>();
ItemStack target = this.getUtil().getStack(Acclimatiser.SLOT_TARGET);
if (target == null) {
return;
}
for (final ItemStack s : this.getUtil().getNonNullStacks(Acclimatiser.SLOT_ACCLIMATISER)) {
if (Acclimatiser.canAcclimatise(this.getUtil().getStack(Acclimatiser.SLOT_TARGET), s)) {
if (Acclimatiser.canAcclimatise(target, s)) {
acclms.add(s);
}
}
final ItemStack acc = acclms.get(this.getUtil().getRandom().nextInt(acclms.size()));
final ItemStack acclimed = Acclimatiser.acclimatise(this.getUtil().getStack(Acclimatiser.SLOT_TARGET), acc);
if (acclimed != null) {
this.getUtil().setStack(Acclimatiser.SLOT_TARGET, acclimed);
boolean removed = false;
for (final int i : Acclimatiser.SLOT_ACCLIMATISER) {
if (!removed && this.getUtil().getStack(i) != null && this.getUtil().getStack(i).isItemEqual(acc)) {
this.getUtil().decreaseStack(i, 1);
removed = true;
}
final ItemStack acclimed = Acclimatiser.acclimatise(target, acc);
this.getUtil().setStack(Acclimatiser.SLOT_TARGET, acclimed);
for (final int i : Acclimatiser.SLOT_ACCLIMATISER) {
ItemStack stack = this.getUtil().getStack(i);
if (stack != null && stack.isItemEqual(acc)) {
this.getUtil().decreaseStack(i, 1);
break;
}
}
}
@@ -8,6 +8,8 @@ import forestry.api.genetics.ISpeciesRoot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
public class Analyser {
public static final int[] SLOT_RESERVE = new int[]{0, 1, 2, 3, 4, 5};
public static final int SLOT_TARGET = 6;
@@ -27,7 +29,7 @@ public class Analyser {
return stack.getItem() instanceof IItemAnalysable && ((IItemAnalysable) stack.getItem()).isAnalysed(stack);
}
public static ItemStack analyse(ItemStack stack) {
public static ItemStack analyse(@Nullable ItemStack stack) {
final ItemStack conv = Binnie.GENETICS.getConversionStack(stack);
if (conv != null) {
stack = conv;
@@ -5,8 +5,10 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
public abstract class WindowMachine extends Window {
public WindowMachine(final int width, final int height, final EntityPlayer player, final IInventory inventory, final Side side) {
public WindowMachine(final int width, final int height, final EntityPlayer player, @Nullable final IInventory inventory, final Side side) {
super(width, height, player, inventory, side);
}