TileEntityCrop

私はこのコードについて真に驚くべき解説ができるが、ここに記すには@Wikiの制限容量が少なすぎる。

バージョン: industrialcraft-2-2.2.828-experimental

package ic2.core.crop;
 
import ic2.api.crops.BaseSeed;
import ic2.api.crops.CropCard;
import ic2.api.crops.Crops;
import ic2.api.crops.ICropTile;
import ic2.api.network.INetworkDataProvider;
import ic2.api.network.INetworkUpdateListener;
import ic2.core.IC2;
import ic2.core.Ic2Items;
import ic2.core.block.machine.tileentity.TileEntityCropmatron;
import ic2.core.item.ItemCropSeed;
import ic2.core.network.NetworkManager;
import ic2.core.util.StackUtil;
import ic2.core.util.Util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.StatCollector;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
 
publicclass TileEntityCrop extends TileEntity implements INetworkDataProvider, INetworkUpdateListener, ICropTile {
   publicbytehumidity = -1;
   publicbytenutrients = -1;
   publicbyteairQuality = -1;
   privatestaticfinalbooleandebug = false;
   private CropCard crop = null;
   publicintsize = 0;
   publicintstatGrowth = 0;
   publicintstatGain = 0;
   publicintstatResistance = 0;
   publicintscanLevel = 0;
   public NBTTagCompound customData = new NBTTagCompound();
   publicintnutrientStorage = 0;
   publicintwaterStorage = 0;
   publicintexStorage = 0;
   publicintgrowthPoints = 0;
   publicbooleanupgraded = false;
   publiccharticker;
   publicbooleandirty;
   publicstaticinttickRate = 256;
   publicintweedlevel;
   publicintInfestedlevel;
 
   public TileEntityCrop() {
      this.ticker = (char)IC2.random.nextInt(tickRate);
      this.dirty = true;
      this.weedlevel = 0;
      this.Infestedlevel = 0;
   }
 
   publicvoid readFromNBT(NBTTagCompound nbt) {
      super.readFromNBT(nbt);
      if (nbt.hasKey("cropOwner") && nbt.hasKey("cropName")) {
         this.crop = Crops.instance.getCropCard(nbt.getString("cropOwner"), nbt.getString("cropName"));
      } elseif (nbt.hasKey("cropid")) {
         this.crop = IC2Crops.getCropFromId(nbt.getShort("cropid"));
      }
 
      this.size = nbt.getByte("size");
      this.statGrowth = nbt.getByte("statGrowth");
      this.statGain = nbt.getByte("statGain");
      this.statResistance = nbt.getByte("statResistance");
      if (nbt.hasKey("data0")) {
         for(intx = 0; x < 16; ++x) {
            this.customData.setShort("legacy" + x, nbt.getShort("data" + x));
         }
      } elseif (nbt.hasKey("customData")) {
         this.customData = nbt.getCompoundTag("customData");
      }
 
      this.growthPoints = nbt.getInteger("growthPoints");
      this.nutrientStorage = nbt.getInteger("nutrientStorage");
      this.waterStorage = nbt.getInteger("waterStorage");
      this.exStorage = nbt.getInteger("exStorage");
      this.upgraded = nbt.getBoolean("upgraded");
      this.scanLevel = nbt.getByte("scanLevel");
      this.weedlevel = nbt.getInteger("weedlevel");
      this.Infestedlevel = nbt.getInteger("Infestedlevel");
   }
 
   publicvoid writeToNBT(NBTTagCompound nbt) {
      super.writeToNBT(nbt);
      if (this.crop != null) {
         nbt.setString("cropOwner", this.crop.owner());
         nbt.setString("cropName", this.crop.name());
      }
 
      nbt.setByte("size", (byte)this.size);
      nbt.setByte("statGrowth", (byte)this.statGrowth);
      nbt.setByte("statGain", (byte)this.statGain);
      nbt.setByte("statResistance", (byte)this.statResistance);
      nbt.setTag("customData", this.customData);
      nbt.setInteger("growthPoints", this.growthPoints);
      nbt.setInteger("nutrientStorage", this.nutrientStorage);
      nbt.setInteger("waterStorage", this.waterStorage);
      nbt.setInteger("exStorage", this.exStorage);
      nbt.setBoolean("upgraded", this.upgraded);
      nbt.setByte("scanLevel", (byte)this.scanLevel);
      nbt.setInteger("weedlevel", this.weedlevel);
      nbt.setInteger("Infestedlevel", this.Infestedlevel);
   }
 
   publicvoidupdateEntity() {
      super.updateEntity();
      ++this.ticker;
      if (this.ticker % tickRate == 0) {
         this.tick();// 256MinecraftTickに1回呼ばれる
      }
 
      if (this.dirty) {// 更新が必要なら更新する
         this.dirty = false;
         this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
         this.worldObj.updateLightByType(EnumSkyBlock.Block, this.xCoord, this.yCoord, this.zCoord);
         if (IC2.platform.isSimulating()) {
            Iterator var1 = this.getNetworkedFields().iterator();
 
            while(var1.hasNext()) {
               String field = (String)var1.next();
               ((NetworkManager)IC2.network.get()).updateTileEntityField(this, field);
            }
         }
      }
 
   }
 
   public List getNetworkedFields() {
      List ret = new ArrayList(4);
      ret.add("crop");
      ret.add("size");
      ret.add("upgraded");
      ret.add("customData");
      ret.add("weedlevel");
      ret.add("Infestedlevel");
      returnret;
   }
 
   publicvoidtick() {
      if (IC2.platform.isSimulating()) {
         if (this.ticker % (tickRate << 2) == 0) {// 1024Minecraftに1度、位相そのまま
            this.humidity = this.updateHumidity();
         }
 
         if ((this.ticker + tickRate) % (tickRate << 2) == 0) {// 1024Minecraftに1度、上の256tick前
            this.nutrients = this.updateNutrients();
         }
 
         if ((this.ticker + tickRate * 2) % (tickRate << 2) == 0) {// 1024Minecraftに1度、上の256tick前
            this.airQuality = this.updateAirQuality();
         }
 
         if (this.crop == null) {
            if (!this.upgraded || !this.attemptCrossing()) {// upgradedなら何もしない、upgradedでないなら交配試行して成功したらスルー、交配失敗だと内部を実行
               if (IC2.random.nextInt(100) != 0 || this.hasEx()) {
                  if (this.exStorage > 0 && IC2.random.nextInt(10) == 0) {
                     --this.exStorage;
                  }
 
                  return;
               }
 
               this.reset();
               this.crop = IC2Crops.weed;
               this.size = 1;
            }
 
            assertthis.crop != null;
         }
 
         this.crop.tick(this);
         if (this.crop.canGrow(this)) {
            this.growthPoints += this.calcGrowthRate();
            if (this.crop == null) {
               return;
            }
 
            if (this.growthPoints >= this.crop.growthDuration(this)) {
               this.growthPoints = 0;
               ++this.size;
               this.dirty = true;
            }
         }
 
         if (this.nutrientStorage > 0) {
            --this.nutrientStorage;
         }
 
         if (this.waterStorage > 0) {
            --this.waterStorage;
         }
 
         if (this.crop.isWeed(this) && IC2.random.nextInt(50) - this.statGrowth <= 2) {
            this.generateWeed();
         }
 
      }
   }
 
   publicvoidgenerateWeed() {
      intx = this.xCoord;
      inty = this.yCoord;
      intz = this.zCoord;
      switch(IC2.random.nextInt(4)) {
      case 0:
         ++x;// breakが足りない
      case 1:
         --x;// breakが足りない
      case 2:
         ++z;// breakが足りない
      case 3:
         --z;
      }
 
      if (this.worldObj.getTileEntity(x, y, z) instanceof TileEntityCrop) {
         TileEntityCrop teCrop = (TileEntityCrop)this.worldObj.getTileEntity(x, y, z);
         CropCard neighborCrop = teCrop.getCrop();
         if (neighborCrop == null || !neighborCrop.isWeed(teCrop) && IC2.random.nextInt(32) >= teCrop.statResistance && !teCrop.hasEx()) {
            intnewGrowth = Math.max(this.statGrowth, teCrop.statGrowth);
            if (newGrowth < 31 && IC2.random.nextBoolean()) {
               ++newGrowth;
            }
 
            teCrop.reset();
            teCrop.crop = IC2Crops.weed;
            teCrop.size = 1;
            teCrop.statGrowth = (byte)newGrowth;
         }
      } elseif (this.worldObj.isAirBlock(x, y, z)) {
         Block block = this.worldObj.getBlock(x, y - 1, z);
         if (block == Blocks.dirt || block == Blocks.grass || block == Blocks.farmland) {
            this.worldObj.setBlock(x, y - 1, z, Blocks.grass, 0, 7);
            this.worldObj.setBlock(x, y, z, Blocks.tallgrass, 1, 7);
         }
      }
 
   }
 
   publicboolean hasEx() {
      if (this.exStorage > 0) {
         this.exStorage -= 5;
         returntrue;
      } else {
         returnfalse;
      }
   }
 
   publicbooleanattemptCrossing() {
      if (IC2.random.nextInt(3) != 0) {// 確率で無条件失敗
         returnfalse;
      } else {
         List cropTes = new ArrayList(4);// 交配参加可能植物を列挙
         this.askCropJoinCross(this.xCoord - 1, this.yCoord, this.zCoord, cropTes);
         this.askCropJoinCross(this.xCoord + 1, this.yCoord, this.zCoord, cropTes);
         this.askCropJoinCross(this.xCoord, this.yCoord, this.zCoord - 1, cropTes);
         this.askCropJoinCross(this.xCoord, this.yCoord, this.zCoord + 1, cropTes);
         if (cropTes.size() < 2) {// 参加可能が2個未満で失敗
            returnfalse;
         } else {
            CropCard[] crops = (CropCard[])Crops.instance.getCrops().toArray(new CropCard[0]);// 全植物を列挙
            if (crops.length == 0) {// 植物がないときは失敗
               returnfalse;
            } else {
               int[] ratios = newint[crops.length];// ここまでの累積交配比重
               inttotal = 0;
 
               intsearch;// 全植物の交配比重の合計を計算
               for(search = 0; search < ratios.length; ++search) {
                  CropCard crop = crops[search];
                  TileEntityCrop te;
                  if (crop.canGrow(this)) {
                     for(Iterator var7 = cropTes.iterator(); var7.hasNext(); total += this.calculateRatioFor(crop, te.getCrop())) {
                        te = (TileEntityCrop)var7.next();
                     }
                  }
 
                  ratios[search] = total;
               }
 
               search = IC2.random.nextInt(total);// 累積交配比重に準じた乱数
               intmin = 0;
               intmax = ratios.length - 1;
 
               intcount;
               while(min < max) {// minをsearchに対応したcropsのインデックスにする
                  count = (min + max) / 2;
                  intvalue = ratios[count];
                  if (search < value) {
                     max = count;
                  } else {
                     min = count + 1;
                  }
               }
 
               assertmin == max;
 
               assertmin >= 0 && min < ratios.length;
 
               assertratios[min] > search;
 
               assertmin == 0 || ratios[min - 1] <= search;
 
               this.upgraded = false;
               this.crop = crops[min];
               this.dirty = true;
               this.size = 1;
               this.statGrowth = 0;
               this.statResistance = 0;
               this.statGain = 0;
 
               TileEntityCrop te;// 交配参加した作物の合計計算
               for(Iterator var13 = cropTes.iterator(); var13.hasNext(); this.statGain += te.statGain) {
                  te = (TileEntityCrop)var13.next();
                  this.statGrowth += te.statGrowth;
                  this.statResistance += te.statResistance;
               }
 
               count = cropTes.size();
               this.statGrowth /= count;
               this.statResistance /= count;
               this.statGain /= count;// ここまででGGRが交配参加した作物の平均になっている
               this.statGrowth += IC2.random.nextInt(1 + 2 * count) - count;// -count~count
               this.statGain += IC2.random.nextInt(1 + 2 * count) - count;
               this.statResistance += IC2.random.nextInt(1 + 2 * count) - count;
               this.statGrowth = Util.limit(this.statGrowth, 0, 31);
               this.statGain = Util.limit(this.statGain, 0, 31);
               this.statResistance = Util.limit(this.statResistance, 0, 31);
               returntrue;
            }
         }
      }
   }
 
   publicintcalculateRatioFor(CropCard newCrop, CropCard oldCrop) {
      if (newCrop == oldCrop) {// 同一植物だと500
         return 500;
      } else {
         intvalue = 0;// 交配比重、初期値0
 
         intdiff;// statが完全に同一の時+10、statが1ずれるごとに-1のペナルティ
         intdelta;
         for(diff = 0; diff < 5; ++diff) {
            delta = Math.abs(newCrop.stat(diff) - oldCrop.stat(diff));
            value += -delta + 2;
         }
 
         String[] var12 = newCrop.attributes();// 属性が大文字小文字無視で一致するごとに+5
         delta = var12.length;
 
         for(intvar6 = 0; var6 < delta; ++var6) {
            String attributeNew = var12[var6];
            String[] var8 = oldCrop.attributes();
            intvar9 = var8.length;
 
            for(intvar10 = 0; var10 < var9; ++var10) {
               String attributeOld = var8[var10];
               if (attributeNew.equalsIgnoreCase(attributeOld)) {
                  value += 5;
               }
            }
         }
 
         diff = newCrop.tier() - oldCrop.tier();// Tier増分が正の場合2倍ペナルティ、負の場合1倍ペナルティ
         if (diff > 1) {
            value -= 2 * diff;
         }
 
         if (diff < -3) {
            value -= -diff;
         }
 
         return Math.max(value, 0);
      }
   }
 
   publicvoidaskCropJoinCross(intx, inty, intz, List crops) {
      TileEntity te = this.worldObj.getTileEntity(x, y, z);
      if (teinstanceof TileEntityCrop) {// ブロックが支柱で、
         TileEntityCrop sideCrop = (TileEntityCrop)te;
         CropCard neighborCrop = sideCrop.getCrop();
         if (neighborCrop != null) {// 植物が存在し、
            if (neighborCrop.canGrow(this) && neighborCrop.canCross(sideCrop)) {// その植物種が交配後の位置で成長可能であり、交配前の位置で交配可能である場合、
               intbase = 4;// 初期値4
               if (sideCrop.statGrowth >= 16) {// Gr16で1のボーナス
                  ++base;
               }
 
               if (sideCrop.statGrowth >= 30) {// Gr30で1のボーナス
                  ++base;
               }
 
               if (sideCrop.statResistance >= 28) {// Re28以降1ずつペナルティ
                  base += 27 - sideCrop.statResistance;
               }
 
               if (base >= IC2.random.nextInt(20)) {// (base + 1) / 20が交配参加確率。
                  crops.add(sideCrop);
               }
 
            }
         }
      }
   }
 
   publicboolean leftClick(EntityPlayer player) {
      if (this.crop == null) {
         if (this.upgraded) {
            this.upgraded = false;
            this.dirty = true;
            if (IC2.platform.isSimulating()) {
               StackUtil.dropAsEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord, new ItemStack(Ic2Items.crop.getItem()));
            }
 
            returntrue;
         } else {
            returnfalse;
         }
      } else {
         returnthis.crop.leftclick(this, player);
      }
   }
 
   publicboolean pick(booleanmanual) {
      if (this.crop == null) {
         returnfalse;
      } else {
         booleanbonus = this.harvest(false);
         floatfirstchance = this.crop.dropSeedChance(this);
 
         intdrop;
         for(drop = 0; drop < this.statResistance; ++drop) {
            firstchance *= 1.1F;
         }
 
         drop = 0;
         intx;
         if (bonus) {
            if (IC2.random.nextFloat() <= (firstchance + 1.0F) * 0.8F) {
               ++drop;
            }
 
            floatchance = this.crop.dropSeedChance(this) + (float)this.statGrowth / 100.0F;
            if (!manual) {
               chance *= 0.8F;
            }
 
            for(x = 23; x < this.statGain; ++x) {
               chance *= 0.95F;
            }
 
            if (IC2.random.nextFloat() <= chance) {
               ++drop;
            }
         } elseif (IC2.random.nextFloat() <= firstchance * 1.5F) {
            ++drop;
         }
 
         ItemStack[] re = new ItemStack[drop];
 
         for(x = 0; x < drop; ++x) {
            re[x] = this.crop.getSeeds(this);
         }
 
         this.reset();
         if (IC2.platform.isSimulating() && re.length > 0) {
            for(x = 0; x < re.length; ++x) {
               if (re[x].getItem() != Ic2Items.cropSeed.getItem()) {
                  re[x].stackTagCompound = null;
               }
 
               StackUtil.dropAsEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord, re[x]);
            }
         }
 
         returntrue;
      }
   }
 
   publicboolean rightClick(EntityPlayer player) {
      ItemStack current = player.getCurrentEquippedItem();
      booleancreative = player.capabilities.isCreativeMode;
      if (current != null) {
         if (this.crop == null) {
            if (current.getItem() == Ic2Items.crop.getItem() && !this.upgraded) {
               if (!creative) {
                  --current.stackSize;
                  if (current.stackSize <= 0) {
                     player.inventory.mainInventory[player.inventory.currentItem] = null;
                  }
               }
 
               this.upgraded = true;
               this.dirty = true;
               returntrue;
            }
 
            if (this.applyBaseSeed(player)) {
               returntrue;
            }
         }
 
         if (current.getItem() == Items.water_bucket || current.getItem() == Ic2Items.waterCell.getItem()) {
            if (this.waterStorage < 10) {
               this.waterStorage = 10;
               returntrue;
            }
 
            returncurrent.getItem() == Items.water_bucket;
         }
 
         if (current.getItem() == Items.wheat_seeds) {
            if (this.nutrientStorage <= 50) {
               this.nutrientStorage += 25;
               --current.stackSize;
               if (current.stackSize <= 0) {
                  player.inventory.mainInventory[player.inventory.currentItem] = null;
               }
 
               returntrue;
            }
 
            returnfalse;
         }
 
         if (current.getItem() == Items.dye && current.getItemDamage() == 15 || current.getItem() == Ic2Items.fertilizer.getItem()) {
            if (this.applyFertilizer(true)) {
               if (creative) {
                  returntrue;
               } else {
                  --current.stackSize;
                  if (current.stackSize <= 0) {
                     player.inventory.mainInventory[player.inventory.currentItem] = null;
                  }
 
                  returntrue;
               }
            } else {
               returnfalse;
            }
         }
 
         if (current.getItem() == Ic2Items.hydratingCell.getItem()) {
            if (this.applyHydration(true, current, player)) {
               if (current.stackSize <= 0) {
                  player.inventory.mainInventory[player.inventory.currentItem] = null;
               }
 
               returntrue;
            }
 
            returnfalse;
         }
 
         if (current.getItem() == Ic2Items.weedEx.getItem() && this.applyWeedEx(true)) {
            current.damageItem(1, player);
            if (current.stackSize <= 0) {
               player.inventory.mainInventory[player.inventory.currentItem] = null;
            }
 
            returntrue;
         }
      }
 
      if (this.crop == null) {
         returnfalse;
      } else {
         returnthis.crop.rightclick(this, player);
      }
   }
 
   publicboolean applyBaseSeed(EntityPlayer player) {
      ItemStack current = player.getCurrentEquippedItem();
      BaseSeed seed = Crops.instance.getBaseSeed(current);
      if (seed != null) {
         if (current.stackSize < seed.stackSize) {
            returnfalse;
         }
 
         if (this.tryPlantIn(seed.crop, seed.size, seed.statGrowth, seed.statGain, seed.statResistance, 1)) {
            if (player.capabilities.isCreativeMode) {
               returntrue;
            }
 
            if (current.getItem().hasContainerItem(current)) {
               if (current.stackSize > 1) {
                  returnfalse;
               }
 
               player.inventory.mainInventory[player.inventory.currentItem] = current.getItem().getContainerItem(current);
            } else {
               current.stackSize -= seed.stackSize;
               if (current.stackSize <= 0) {
                  player.inventory.mainInventory[player.inventory.currentItem] = null;
               }
            }
 
            returntrue;
         }
      }
 
      returnfalse;
   }
 
   publicboolean tryPlantIn(CropCard crop, intsi, intstatGr, intstatGa, intstatRe, intscan) {
      if (crop != null && crop != IC2Crops.weed && !this.upgraded) {
         if (!crop.canGrow(this)) {
            returnfalse;
         } else {
            this.reset();
            this.crop = crop;
            this.size = (byte)si;
            this.statGrowth = (byte)statGr;
            this.statGain = (byte)statGa;
            this.statResistance = (byte)statRe;
            this.scanLevel = (byte)scan;
            returntrue;
         }
      } else {
         returnfalse;
      }
   }
 
   publicboolean applyFertilizer(booleanmanual) {
      if (this.nutrientStorage >= 100) {
         returnfalse;
      } else {
         this.nutrientStorage += manual ? 100 : 90;
         returntrue;
      }
   }
 
   publicboolean applyHydration(TileEntityCropmatron cropmatron) {
      if (this.waterStorage >= 200) {
         returnfalse;
      } else {
         intapply = 200 - this.waterStorage;
         FluidStack drain = cropmatron.getFluidTank().drain(apply, true);
         if (drain != null) {
            this.waterStorage += drain.amount;
            returntrue;
         } else {
            returnfalse;
         }
      }
   }
 
   publicboolean applyHydration(booleanmanual, ItemStack itemStack, EntityPlayer player) {
      if ((manual || this.waterStorage < 180) && this.waterStorage < 200) {
         intapply = manual ? 200 - this.waterStorage : 180 - this.waterStorage;
         apply = Math.min(apply, itemStack.getMaxDamage() - itemStack.getItemDamage());
         if (!player.capabilities.isCreativeMode && itemStack.attemptDamageItem(apply, IC2.random)) {
            player.inventory.mainInventory[player.inventory.currentItem] = Ic2Items.cell;
         }
 
         this.waterStorage += apply;
         returntrue;
      } else {
         returnfalse;
      }
   }
 
   publicboolean applyWeedEx(booleanmanual) {
      if ((this.exStorage < 100 || !manual) && this.exStorage < 150) {
         this.exStorage += 50;
         booleantriggerDecline;
         if (manual) {
            triggerDecline = this.worldObj.rand.nextInt(5) == 0;
         } else {
            triggerDecline = this.worldObj.rand.nextInt(3) == 0;
         }
 
         if (this.crop != null && this.crop.isWeed(this) && this.exStorage >= 75 && triggerDecline) {
            switch(this.worldObj.rand.nextInt(5)) {
            case 0:
               if (this.statGrowth > 0) {
                  --this.statGrowth;
               }
            case 1:
               if (this.statGain > 0) {
                  --this.statGain;
               }
            default:
               if (this.statResistance > 0) {
                  --this.statResistance;
               }
            }
         }
 
         returntrue;
      } else {
         returnfalse;
      }
   }
 
   public ItemStack[] harvest_automated(booleanoptimal) {
      if (this.crop == null) {
         returnnull;
      } elseif (!this.crop.canBeHarvested(this)) {
         returnnull;
      } elseif (optimal && this.size != this.crop.getOptimalHavestSize(this)) {
         returnnull;
      } else {
         doublechance = (double)this.crop.dropGainChance();
         chance *= Math.pow(1.03D, (double)this.statGain);
         intdropCount = (int)Math.max(0L, Math.round(IC2.random.nextGaussian() * chance * 0.6827D + chance));
         ItemStack[] ret = new ItemStack[dropCount];
 
         for(inti = 0; i < dropCount; ++i) {
            ret[i] = this.crop.getGain(this);
            if (ret[i] != null && IC2.random.nextInt(100) <= this.statGain) {
               ++ret[i].stackSize;
            }
         }
 
         this.size = this.crop.getSizeAfterHarvest(this);
         this.dirty = true;
         returnret;
      }
   }
 
   publicboolean harvest(booleanmanual) {
      ItemStack[] drops = this.harvest_automated(false);
      if (drops == null) {
         returnfalse;
      } else {
         if (IC2.platform.isSimulating() && drops.length > 0) {
            ItemStack[] var3 = drops;
            intvar4 = drops.length;
 
            for(intvar5 = 0; var5 < var4; ++var5) {
               ItemStack drop = var3[var5];
               StackUtil.dropAsEntity(this.worldObj, this.xCoord, this.yCoord, this.zCoord, drop);
            }
         }
 
         returntrue;
      }
   }
 
   publicvoid onNeighbourChange() {
      if (this.crop != null) {
         this.crop.onNeighbourChange(this);
      }
   }
 
   publicint emitRedstone() {
      returnthis.crop == null ? 0 : this.crop.emitRedstone(this);
   }
 
   publicvoid onBlockDestroyed() {
      if (this.crop != null) {
         this.crop.onBlockDestroyed(this);
      }
   }
 
   publicint getEmittedLight() {
      returnthis.crop == null ? 0 : this.crop.getEmittedLight(this);
   }
 
   publicbyte getHumidity() {
      if (this.humidity == -1) {
         this.humidity = this.updateHumidity();
      }
 
      returnthis.humidity;
   }
 
   publicbyte getNutrients() {
      if (this.nutrients == -1) {
         this.nutrients = this.updateNutrients();
      }
 
      returnthis.nutrients;
   }
 
   publicbyte getAirQuality() {
      if (this.airQuality == -1) {
         this.airQuality = this.updateAirQuality();
      }
 
      returnthis.airQuality;
   }
 
   publicbyteupdateHumidity() {
      intvalue = 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;
   }
 
   publicbyteupdateNutrients() {
      intvalue = Crops.instance.getNutrientBiomeBonus(this.worldObj.getBiomeGenForCoords(this.xCoord, this.zCoord));
 
      for(inti = 2; i < 5 && this.worldObj.getBlock(this.xCoord, this.yCoord - i, this.zCoord) == Blocks.dirt; ++i) {
         ++value;
      }
 
      value += (this.nutrientStorage + 19) / 20;
      return (byte)value;
   }
 
   publicbyteupdateAirQuality() {
      intvalue = 0;
      intheight = (this.yCoord - 64) / 15;
      if (height > 4) {
         height = 4;
      }
 
      if (height < 0) {
         height = 0;
      }
 
      intvalue = value + height;
      intfresh = 9;
 
      for(intx = this.xCoord - 1; x <= this.xCoord + 1 && fresh > 0; ++x) {
         for(intz = 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;
   }
 
   publicint updateMultiCulture() {
      Set crops = new HashSet();
 
      for(intx = -1; x < 1; ++x) {
         for(intz = -1; z < 1; ++z) {
            TileEntity te = this.worldObj.getTileEntity(x + this.xCoord, this.yCoord, z + this.zCoord);
            if (teinstanceof TileEntityCrop) {
               CropCard neighborCrop = ((TileEntityCrop)te).getCrop();
               if (neighborCrop != null) {
                  crops.add(neighborCrop);
               }
            }
         }
      }
 
      returncrops.size() - 1;
   }
 
   publicvoid addIfNotPresent(CropCard crop, LinkedList crops) {
      for(inti = 0; i < crops.size(); ++i) {
         if (crop == crops.get(i)) {
            return;
         }
      }
 
      crops.add(crop);
   }
 
   publicint calcGrowthRate() {
      if (this.crop == null) {
         return 0;
      } else {
         intbase = 3 + IC2.random.nextInt(7) + this.statGrowth;
         intneed = (this.crop.tier() - 1) * 4 + this.statGrowth + this.statGain + this.statResistance;
         if (need < 0) {
            need = 0;
         }
 
         inthave = this.crop.weightInfluences(this, (float)this.getHumidity(), (float)this.getNutrients(), (float)this.getAirQuality()) * 5;
         if (have >= need) {
            base = base * (100 + (have - need)) / 100;
         } else {
            intneg = (need - have) * 4;
            if (neg > 100 && IC2.random.nextInt(32) > this.statResistance) {
               this.reset();
               base = 0;
            } else {
               base = base * (100 - neg) / 100;
               if (base < 0) {
                  base = 0;
               }
            }
         }
 
         returnbase;
      }
   }
 
   publicvoid calcTrampling() {
      if (IC2.platform.isSimulating()) {
         if (IC2.random.nextInt(100) == 0 && IC2.random.nextInt(40) > this.statResistance) {
            this.reset();
            this.worldObj.setBlock(this.xCoord, this.yCoord - 1, this.zCoord, Blocks.dirt, 0, 7);
         }
 
      }
   }
 
   publicvoid onEntityCollision(Entity entity) {
      if (this.crop != null) {
         if (this.crop.onEntityCollision(this, entity)) {
            this.calcTrampling();
         }
 
      }
   }
 
   publicvoid reset() {
      this.crop = null;
      this.size = 0;
      this.customData = new NBTTagCompound();
      this.dirty = true;
      this.statGain = 0;
      this.statResistance = 0;
      this.statGrowth = 0;
      this.nutrients = -1;
      this.airQuality = -1;
      this.humidity = -1;
      this.growthPoints = 0;
      this.upgraded = false;
      this.scanLevel = 0;
   }
 
   publicvoid updateState() {
      this.dirty = true;
   }
 
   public String getScanned() {
      if (this.crop == null) {
         returnnull;
      } elseif (this.scanLevel <= 0) {
         returnnull;
      } else {
         String name = StatCollector.translateToLocal(this.crop.displayName());
         returnthis.scanLevel >= 4 ? String.format("%s - Gr: %d Ga: %d Re: %d S: %d/%d", name, this.statGrowth, this.statGain, this.statResistance, this.size, this.crop.maxSize()) : String.format("%s - Size: %d/%d", name, this.size, this.crop.maxSize());
      }
   }
 
   publicboolean isBlockBelow(Block reqBlock) {
      if (this.crop == null) {
         returnfalse;
      } else {
         for(inti = 1; i < this.crop.getrootslength(this); ++i) {
            Block block = this.worldObj.getBlock(this.xCoord, this.yCoord - i, this.zCoord);
            if (block.isAir(this.worldObj, this.xCoord, this.yCoord - i, this.zCoord)) {
               returnfalse;
            }
 
            if (block == reqBlock) {
               returntrue;
            }
         }
 
         returnfalse;
      }
   }
 
   publicboolean isBlockBelow(String oreDictionaryName) {
      if (this.crop == null) {
         returnfalse;
      } else {
         for(inti = 1; i < this.crop.getrootslength(this); ++i) {
            Block block = this.worldObj.getBlock(this.xCoord, this.yCoord - i, this.zCoord);
            intmetaData = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord - i, this.zCoord);
            if (block.isAir(this.worldObj, this.xCoord, this.yCoord - i, this.zCoord)) {
               returnfalse;
            }
 
            for(intaux = 0; aux < OreDictionary.getOres(oreDictionaryName).size(); ++aux) {
               ItemStack itemStack = (ItemStack)OreDictionary.getOres(oreDictionaryName).get(aux);
               if (itemStack.getItem() == Item.getItemFromBlock(block) && itemStack.getItemDamage() == metaData) {
                  returntrue;
               }
            }
         }
 
         returnfalse;
      }
   }
 
   public ItemStack generateSeeds(CropCard crop, bytegrowth, bytegain, byteresis, bytescan) {
      return ItemCropSeed.generateItemStackFromValues(crop, growth, gain, resis, scan);
   }
 
   public ItemStack generateSeeds(shortplant, bytegrowth, bytegain, byteresis, bytescan) {
      returnthis.generateSeeds(IC2Crops.getCropFromId(plant), growth, gain, resis, scan);
   }
 
   publicvoid onNetworkUpdate(String field) {
      this.dirty = true;
   }
 
   public CropCard getCrop() {
      returnthis.crop;
   }
 
   publicshort getID() {
      return (short)Crops.instance.getIdFor(this.crop);
   }
 
   publicbyte getSize() {
      return (byte)this.size;
   }
 
   publicbyte getGrowth() {
      return (byte)this.statGrowth;
   }
 
   publicbyte getGain() {
      return (byte)this.statGain;
   }
 
   publicbyte getResistance() {
      return (byte)this.statResistance;
   }
 
   publicbyte getScanLevel() {
      return (byte)this.scanLevel;
   }
 
   public NBTTagCompound getCustomData() {
      returnthis.customData;
   }
 
   publicint getNutrientStorage() {
      returnthis.nutrientStorage;
   }
 
   publicint getHydrationStorage() {
      returnthis.waterStorage;
   }
 
   publicint getWeedExStorage() {
      returnthis.exStorage;
   }
 
   publicint getLightLevel() {
      returnthis.worldObj.getBlockLightValue(this.xCoord, this.yCoord, this.zCoord);
   }
 
   publicvoid setCrop(CropCard cropCard) {
      this.crop = cropCard;
      this.dirty = true;
   }
 
   publicvoid setID(shortid) {
      this.setCrop(IC2Crops.getCropFromId(id));
   }
 
   publicvoid setSize(bytesize1) {
      this.size = size1;
      this.dirty = true;
   }
 
   publicvoid setGrowth(bytegrowth) {
      this.statGrowth = growth;
   }
 
   publicvoid setGain(bytegain) {
      this.statGain = gain;
   }
 
   publicvoid setResistance(byteresistance) {
      this.statResistance = resistance;
   }
 
   publicvoid setScanLevel(bytescanLevel1) {
      this.scanLevel = scanLevel1;
   }
 
   publicvoid setNutrientStorage(intnutrientStorage1) {
      this.nutrientStorage = nutrientStorage1;
   }
 
   publicvoid setHydrationStorage(inthydrationStorage) {
      this.waterStorage = hydrationStorage;
   }
 
   publicvoid setWeedExStorage(intweedExStorage) {
      this.exStorage = weedExStorage;
   }
 
   public World getWorld() {
      returnthis.worldObj;
   }
 
   public ChunkCoordinates getLocation() {
      returnnew ChunkCoordinates(this.xCoord, this.yCoord, this.zCoord);
   }
 
   publicint getvisualweedlevel() {
      returnthis.weedlevel;
   }
 
   publicint getvisualInfestedlevel() {
      if (this.Infestedlevel < 10) {
         return 0;
      } elseif (this.Infestedlevel < 30) {
         return 1;
      } elseif (this.Infestedlevel < 50) {
         return 2;
      } elseif (this.Infestedlevel < 70) {
         return 3;
      } else {
         returnthis.Infestedlevel < 90 ? 4 : 5;
      }
   }
}
 
最終更新:2017年11月06日 19:05