Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //村人AI(EntityVillager.java)
- protected void updateAITasks()
- {
- if (--this.randomTickDivider <= 0) //ランダムティックが0までカウントされたら
- {
- BlockPos blockpos = new BlockPos(this); //村人の位置
- this.world.getVillageCollection().addToVillagerPositionList(blockpos); //村人位置リストにセット
- this.randomTickDivider = 70 + this.rand.nextInt(50); //ランダムティックのタイマーを再セット
- this.village = this.world.getVillageCollection().getNearestVillage(blockpos, 32); //いちばん近い村を取得
- if (this.village == null) //村がねえだ
- {
- this.detachHome(); //村から脱退
- }
- else
- {
- BlockPos blockpos1 = this.village.getCenter(); //村の中心を取得
- this.setHomePosAndDistance(blockpos1, this.village.getVillageRadius()); //村の位置と半径をセット
- if (this.isLookingForHome) //帰宅中フラグ
- {
- this.isLookingForHome = false; //帰宅おわり
- this.village.setDefaultPlayerReputation(5); //村の評判値を5に
- }
- }
- }
- if (!this.isTrading() && this.timeUntilReset > 0) //取引中ではない且つ商品の更新タイマーが0位上
- {
- --this.timeUntilReset; //タイマー更新
- if (this.timeUntilReset <= 0) //タイマーが0になった
- {
- if (this.needsInitilization) //取引後の更新が必要
- {
- for (MerchantRecipe merchantrecipe : this.buyingList)
- {
- if (merchantrecipe.isRecipeDisabled())
- {
- merchantrecipe.increaseMaxTradeUses(this.rand.nextInt(6) + this.rand.nextInt(6) + 2);
- }
- }
- this.populateBuyingList();
- this.needsInitilization = false;
- if (this.village != null && this.lastBuyingPlayer != null)
- {
- this.world.setEntityState(this, (byte)14);
- this.village.modifyPlayerReputation(this.lastBuyingPlayer, 1); //評判アップ
- }
- }
- this.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 0)); //くさそうなぐるぐる表示
- }
- }
- super.updateAITasks();
- }
- //村人AIでの過疎チェック
- private boolean checkSufficientDoorsPresentForNewVillager()
- {
- if (!this.village.isMatingSeason()) //やる時間か?(村全体で村人のインベントリ消費タイマーチェック)
- {
- return false;
- }
- else
- {
- int i = (int)((double)((float)this.village.getNumVillageDoors()) * 0.35D); //ドアの数×0.35
- return this.village.getNumVillagers() < i; //村人の数が(ドアの数×0.35)未満なら、過疎フラグ
- }
- }
- //村人が一番近くの村を探す処理(VillageCollection.java)
- public Village getNearestVillage(BlockPos doorBlock, int radius)
- {
- Village village = null;
- double d0 = 0x7F7FFFFF; //デフォの距離doubleの最大値
- for (Village village1 : this.villageList) //村リスト(ワールド全部)を検索
- {
- double d1 = village1.getCenter().distanceSq(doorBlock); //村の中心から村人の距離(distanseSq()平方根返すので球形)
- if (d1 < d0) //前回より近いか?
- {
- float f = (float)(radius + village1.getVillageRadius()); //村の半径取得
- if (d1 <= (double)(f * f)) //村の半径に入ってる?
- {
- village = village1; //みっけ!
- d0 = d1;
- }
- }
- }
- return village;
- }
- //村のティックタイマー
- public void tick()
- {
- ++this.tickCounter;
- for (Village village : this.villageList)
- {
- village.tick(this.tickCounter);
- }
- this.removeAnnihilatedVillages(); //無効な村を削除
- this.dropOldestVillagerPosition(); //村人の位置をいったん初期化&ドアの存在チェック
- this.addNewDoorsToVillageOrCreateVillage(); //村の再ロード
- if (this.tickCounter % 400 == 0)
- {
- this.markDirty();
- }
- }
- //村人の位置をいったん初期化&ドアの存在チェック
- private void dropOldestVillagerPosition()
- {
- if (!this.villagerPositionsList.isEmpty()) //村人リストが空っぽじゃないなら
- {
- this.addDoorsAround(this.villagerPositionsList.remove(0)); //村人位置からドアチェック&村人の位置を削除
- }
- }
- //村人の周りにドアが存在するかチェック(VillageCollection.java)
- private void addDoorsAround(BlockPos central)
- {
- int i = 16;
- int j = 4;
- int k = 16;
- for (int l = -16; l < 16; ++l) //X
- {
- for (int i1 = -4; i1 < 4; ++i1) //Y
- {
- for (int j1 = -16; j1 < 16; ++j1) //Z
- {
- BlockPos blockpos = central.add(l, i1, j1); //中心からの相対位置(X Y Z)から絶対位置を取得
- if (this.isWoodDoor(blockpos)) //ここにドアがあるならば
- {
- VillageDoorInfo villagedoorinfo = this.checkDoorExistence(blockpos); //既知のドアか?
- if (villagedoorinfo == null) //ちゃう
- {
- this.addToNewDoorsList(blockpos); //追加しとこ
- }
- else
- {
- villagedoorinfo.setLastActivityTimestamp(this.tickCounter); //村はいきとるで
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement