// 如果复合作物成长环境,每1tick都会计算一次作物成长值
public int calcGrowthRate()
{
if (this.crop == null) {
return 0;
}
// 作物本tick成长基础点数 = 固定3+ 0到6的随机数
int base = 3 + IC2.random.nextInt(7) + this.statGrowth;
// 成长需求成长率 = (当前作物等级-1)*4 + 当前种子成长值 + 当前种子产量值 + 当前种子抗性值
int need = (this.crop.tier() - 1) * 4 + this.statGrowth + this.statGain + this.statResistance;
// 成长需求成长率最小为0
if (need < 0) {
need = 0;
}
/* 当前环境所能提供的作物成长率计算,主要通过【湿度】,【养分】,【空气质量】点数计算;
* 可可,咖啡,西瓜,南瓜,小麦,粘性甘蔗有重写此方法计算公式,如有需要请自行翻阅对应作物类中的weightInfluences方法
* 其他作物:
* 环境所能提供的作物成长率 = (当前作物湿度点数 + 当前作物养分点数 + 当前作物空气质量点数)*5
*/
int have = this.crop.weightInfluences(this, getHumidity(), getNutrients(), getAirQuality()) * 5;
/* 作物本tick成长点数 =(当前环境所能提供的作物成长率 - 成长需求成长率)* 100% * 作物本tick成长基础点数;
* 如果【当前环境所能提供的作物成长率】比【成长需求成长率】低26(包含),作物不会成长,
* 并且有(31 - 种子抗性值)/ 31 * 100% 几率清空作物架(看起来抗性值基本没啥用,高了反而增加作物成长需求)
*/
if (have >= need)
{
base = base * (100 + (have - need)) / 100;
}
else
{
int neg = (need - have) * 4;
if ((neg > 100) && (IC2.random.nextInt(32) > this.statResistance))
{
reset();
base = 0;
}
else
{
base = base * (100 - neg) / 100;
if (base < 0) {
base = 0;
}
}
}
return base;
}
// 湿度点数的计算
public byte updateHumidity()
{
int value = Crops.instance.getHumidityBiomeBonus(this.worldObj.getBiomeGenForCoords(this.xCoord, this.zCoord));
if (this.worldObj.getBlockMetadata(this.xCoord, this.yCoord - 1, this.zCoord) >= 7) {
value += 2;
}
if (this.waterStorage >= 5) {
value += 2;
}
value += (this.waterStorage + 24) / 25;
return (byte)value;
}
// 养分点数计算
public byte updateNutrients()
{
/* 生物群系提供的点数:
* JUNGLE, 10
* SWAMP, 10
* MUSHROOM, 5
* FOREST, 5
* RIVER, 2
* PLAINS, 0
* SAVANNA, -2
* HILLS, -5
* MOUNTAIN, -5
* WASTELAND, -8
* END, -10
* NETHER, -10
* DEAD, -10
*/
int value = Crops.instance.getNutrientBiomeBonus(this.worldObj.getBiomeGenForCoords(this.xCoord, this.zCoord));
for (int i = 2; i < 5; i++)
{
if (this.worldObj.getBlock(this.xCoord, this.yCoord - i, this.zCoord) != Blocks.dirt) {
break;
}
value++;
}
value += (this.nutrientStorage + 19) / 20;
return (byte)value;
}
// 空气质量点数计算
public byte updateAirQuality()
{
int value = 0;
int height = (this.yCoord - 64) / 15;
if (height > 4) {
height = 4;
}
if (height < 0) {
height = 0;
}
value += height;
int fresh = 9;
for (int x = this.xCoord - 1; (x <= this.xCoord + 1) && (fresh > 0); x++) {
for (int z = this.zCoord - 1; (z <= this.zCoord + 1) && (fresh > 0); z++) {
if ((this.worldObj.isBlockNormalCubeDefault(x, this.yCoord, z, false)) ||
((this.worldObj.getTileEntity(x, this.yCoord, z) instanceof TileEntityCrop))) {
fresh--;
}
}
}
value += fresh / 2;
if (this.worldObj.canBlockSeeTheSky(this.xCoord, this.yCoord + 1, this.zCoord)) {
value += 2;
}
return (byte)value;
}