|
| 1 | +/** |
| 2 | + * Copyright 2013 Yamato |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package net.minecraft.src; |
| 17 | + |
| 18 | +import java.util.Random; |
| 19 | +import mod.ymt.sugar.SugarBiomeCore; |
| 20 | + |
| 21 | +/** |
| 22 | + * @author Yamato |
| 23 | + * |
| 24 | + */ |
| 25 | +public class SBLMMEntityMode_SugarHunter extends LMM_EntityMode_Basic { |
| 26 | + public final int mmode_SugarHunter = 0x3201; |
| 27 | + private final Random rand = new Random(); |
| 28 | + private boolean modeSearchChest = false; |
| 29 | + private int coolTime = 0; |
| 30 | + private boolean speedUp = false; |
| 31 | + private double lastdistance = 0; |
| 32 | + private int moveRetryCount = 0; |
| 33 | + |
| 34 | + static { |
| 35 | + SugarBiomeCore.getInstance().debugPrint("initializing SBLMMEntityMode_SugarHunter"); |
| 36 | + } |
| 37 | + |
| 38 | + public SBLMMEntityMode_SugarHunter(LMM_EntityLittleMaid owner) { |
| 39 | + super(owner); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public void addEntityMode(EntityAITasks pDefaultMove, EntityAITasks pDefaultTargeting) { |
| 44 | + if (isModeEnable()) { |
| 45 | + EntityAITasks[] ltasks = new EntityAITasks[2]; |
| 46 | + ltasks[0] = pDefaultMove; |
| 47 | + ltasks[1] = pDefaultTargeting; |
| 48 | + owner.addMaidMode(ltasks, "SugarHunter", mmode_SugarHunter); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public boolean changeMode(EntityPlayer pentityplayer) { |
| 54 | + if (isModeEnable()) { |
| 55 | + ItemStack litemstack = owner.maidInventory.getStackInSlot(0); |
| 56 | + if (litemstack != null) { |
| 57 | + if (litemstack.itemID == Item.reed.itemID) { |
| 58 | + owner.setMaidMode("SugarHunter"); |
| 59 | + return true; |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + return false; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public boolean checkBlock(int pMode, int px, int py, int pz) { |
| 68 | + if (modeSearchChest) { |
| 69 | + return super.checkBlock(pMode, px, py, pz); |
| 70 | + } |
| 71 | + // サトウキビの探索 |
| 72 | + World w = owner.worldObj; |
| 73 | + int blockId = w.getBlockId(px, py, pz); |
| 74 | + if (blockId == Block.reed.blockID) { |
| 75 | + if (w.getBlockId(px, py - 1, pz) == Block.reed.blockID) { |
| 76 | + speedUp = true; |
| 77 | + SugarBiomeCore.getInstance().debugPrint("find reed %d, %d, %d", px, py, pz); |
| 78 | + return true; |
| 79 | + } |
| 80 | + // 伸びていなければ離れた場所に移動してみる |
| 81 | + if (rand.nextInt(800) == 0 && 5 * 5 < owner.getDistanceSq(px + 0.5, py + 0.5, pz + 0.5)) { |
| 82 | + SugarBiomeCore.getInstance().debugPrint("move far %d, %d, %d", px, py, pz); |
| 83 | + return true; |
| 84 | + } |
| 85 | + } |
| 86 | + // 植え付け可能場所の探索 |
| 87 | + else if (blockId == Block.dirt.blockID || blockId == Block.grass.blockID || blockId == Block.sand.blockID) { |
| 88 | + Material mm = w.getBlockMaterial(px, py + 1, pz); |
| 89 | + if (mm == null || (mm.isReplaceable() && !mm.isLiquid())) { |
| 90 | + if (Block.reed.canPlaceBlockAt(w, px, py + 1, pz) && owner.maidInventory.hasItem(Item.reed.itemID)) { |
| 91 | + speedUp = 2 * 2 < owner.getDistanceSq(px + 0.5, py + 0.5, pz + 0.5); |
| 92 | + SugarBiomeCore.getInstance().debugPrint("find point %d, %d, %d", px, py, pz); |
| 93 | + return true; |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + return false; |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + public boolean checkItemStack(ItemStack pItemStack) { |
| 102 | + return true; // インベントリに空きがあればアイテムは拾いに行く。けど AICollectItem 内でも判定しているみたい |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + public boolean executeBlock(int pMode, int px, int py, int pz) { |
| 107 | + if (modeSearchChest) { |
| 108 | + boolean result = super.executeBlock(pMode, px, py, pz); |
| 109 | + if (!result) { |
| 110 | + modeSearchChest = false; |
| 111 | + } |
| 112 | + return result; |
| 113 | + } |
| 114 | + World w = owner.worldObj; |
| 115 | + int blockId = w.getBlockId(px, py, pz); |
| 116 | + |
| 117 | + // さとうきびの刈り取り |
| 118 | + if (blockId == Block.reed.blockID && w.getBlockId(px, py - 1, pz) == Block.reed.blockID) { |
| 119 | + owner.setSwing(10, LMM_EnumSound.Null); |
| 120 | + Block.blocksList[blockId].dropBlockAsItem(w, px, py, pz, 0, 0); |
| 121 | + w.setBlockWithNotify(px, py, pz, 0); |
| 122 | + w.playSoundEffect(px + 0.5F, py + 0.5F, pz + 0.5F, Block.reed.stepSound.getPlaceSound(), (Block.reed.stepSound.getVolume() + 1.0F) / 2.0F, |
| 123 | + Block.reed.stepSound.getPitch() * 0.8F); |
| 124 | + coolTime = 10; |
| 125 | + speedUp = false; |
| 126 | + } |
| 127 | + // 植え付け |
| 128 | + else if (blockId == Block.dirt.blockID || blockId == Block.grass.blockID || blockId == Block.sand.blockID) { |
| 129 | + Material mm = w.getBlockMaterial(px, py + 1, pz); |
| 130 | + if (mm == null || mm.isReplaceable()) { |
| 131 | + if (Block.reed.canPlaceBlockAt(w, px, py + 1, pz) && owner.maidInventory.consumeInventoryItem(Item.reed.itemID)) { |
| 132 | + w.setBlockWithNotify(px, py + 1, pz, Block.reed.blockID); |
| 133 | + owner.setSwing(10, LMM_EnumSound.Null); |
| 134 | + w.playSoundEffect(px + 0.5F, py + 0.5F, pz + 0.5F, Block.reed.stepSound.getPlaceSound(), (Block.reed.stepSound.getVolume() + 1.0F) / 2.0F, |
| 135 | + Block.reed.stepSound.getPitch() * 0.8F); |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + return false; |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public int getNextEquipItem(int pMode) { |
| 144 | + if (pMode == mmode_SugarHunter) { |
| 145 | + for (int i = 0; i < owner.maidInventory.maxInventorySize; i++) { |
| 146 | + ItemStack item = owner.maidInventory.getStackInSlot(i); |
| 147 | + if (item != null && item.itemID == Item.reed.itemID) { |
| 148 | + return i; |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + return -1; |
| 153 | + } |
| 154 | + |
| 155 | + @Override |
| 156 | + public void init() { |
| 157 | + if (isModeEnable()) { |
| 158 | + // 登録モードの名称追加 |
| 159 | + ModLoader.addLocalization("littleMaidMob.mode.SugarHunter", "SugarHunter"); |
| 160 | + ModLoader.addLocalization("littleMaidMob.mode.SugarHunter", "ja_JP", "シュガーハンター"); |
| 161 | + ModLoader.addLocalization("littleMaidMob.mode.F-SugarHunter", "F-SugarHunter"); |
| 162 | + ModLoader.addLocalization("littleMaidMob.mode.T-SugarHunter", "T-SugarHunter"); |
| 163 | + ModLoader.addLocalization("littleMaidMob.mode.D-SugarHunter", "D-SugarHunter"); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + @Override |
| 168 | + public boolean isSearchBlock() { |
| 169 | + if (owner.maidInventory.getFirstEmptyStack() == -1) { |
| 170 | + modeSearchChest = true; // アイテムいっぱいならチェスト探索モード |
| 171 | + return !super.shouldBlock(mmode_Escorter); // ほんとは mytile == null したいけど代用として |
| 172 | + } |
| 173 | + if (0 < coolTime) { |
| 174 | + return false; // クールタイム中は立ち止まる |
| 175 | + } |
| 176 | + return true; // サトウキビ探索 |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public void onUpdate(int pMode) { |
| 181 | + super.onUpdate(pMode); |
| 182 | + if (0 < coolTime) { |
| 183 | + coolTime--; |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + @Override |
| 188 | + public boolean outrangeBlock(int pMode, int pX, int pY, int pZ) { |
| 189 | + if (modeSearchChest) { |
| 190 | + return super.outrangeBlock(pMode, pX, pY, pZ); |
| 191 | + } |
| 192 | + boolean result = false; |
| 193 | + if (!owner.isMaidWaitEx()) { |
| 194 | + double distance = owner.getDistanceSq(pX + 0.5, pY + 0.5, pZ + 0.5); |
| 195 | + if (distance == lastdistance) { |
| 196 | + owner.updateWanderPath(); |
| 197 | + SugarBiomeCore.getInstance().debugPrint("updateWanderPath(%s)", ++moveRetryCount); |
| 198 | + result = moveRetryCount < 40; // 40回までリトライ可能 |
| 199 | + } |
| 200 | + else { |
| 201 | + result = owner.getNavigator().tryMoveToXYZ(pX, pY, pZ, speedUp ? 0.3F : 0.23F); |
| 202 | + } |
| 203 | + lastdistance = distance; |
| 204 | + } |
| 205 | + return result; |
| 206 | + } |
| 207 | + |
| 208 | + @Override |
| 209 | + public int priority() { |
| 210 | + return 5999; // IC2だとサトウキビが燃えるようになるので、LMM_EntityMode_Cooking より優先度を上げる |
| 211 | + } |
| 212 | + |
| 213 | + @Override |
| 214 | + public void resetBlock(int pMode) { |
| 215 | + super.resetBlock(pMode); |
| 216 | + speedUp = false; |
| 217 | + moveRetryCount = 0; |
| 218 | + } |
| 219 | + |
| 220 | + @Override |
| 221 | + public boolean setMode(int pMode) { |
| 222 | + switch (pMode) { |
| 223 | + case mmode_SugarHunter: |
| 224 | + owner.setBloodsuck(false); |
| 225 | + owner.aiWander.setEnable(true); |
| 226 | + owner.aiJumpTo.setEnable(false); |
| 227 | + owner.aiFollow.setEnable(false); |
| 228 | + owner.aiAvoidPlayer.setEnable(false); |
| 229 | + return true; |
| 230 | + } |
| 231 | + return false; |
| 232 | + } |
| 233 | + |
| 234 | + @Override |
| 235 | + public boolean shouldBlock(int pMode) { |
| 236 | + if (modeSearchChest) { |
| 237 | + return super.shouldBlock(pMode); |
| 238 | + } |
| 239 | + return false; |
| 240 | + } |
| 241 | + |
| 242 | + private static boolean isModeEnable() { |
| 243 | + return SugarBiomeCore.getInstance().isRunning(); |
| 244 | + } |
| 245 | +} |
0 commit comments