Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.15 KB | None | 0 0
  1. package ak.EnchantChanger.tileentity;
  2.  
  3. import ak.EnchantChanger.EnchantChanger;
  4. import ak.EnchantChanger.api.MakoUtils;
  5. import ak.EnchantChanger.block.EcBlockLifeStreamFluid;
  6. import ak.EnchantChanger.fluid.EcMakoReactorTank;
  7. import ak.EnchantChanger.modcoop.CoopSS;
  8. import ak.EnchantChanger.modcoop.CoopTE;
  9. import ak.EnchantChanger.utils.ConfigurationUtils;
  10. import ak.EnchantChanger.utils.EnchantmentUtils;
  11. import cofh.api.energy.IEnergyConnection;
  12. import cofh.api.energy.IEnergyHandler;
  13. import cofh.api.tileentity.IEnergyInfo;
  14. import com.google.common.collect.Range;
  15. import cpw.mods.fml.common.Optional;
  16. import cpw.mods.fml.relauncher.Side;
  17. import cpw.mods.fml.relauncher.SideOnly;
  18. import net.minecraft.block.Block;
  19. import net.minecraft.enchantment.EnchantmentData;
  20. import net.minecraft.entity.player.EntityPlayer;
  21. import net.minecraft.entity.player.EntityPlayerMP;
  22. import net.minecraft.init.Blocks;
  23. import net.minecraft.inventory.ISidedInventory;
  24. import net.minecraft.item.ItemBucket;
  25. import net.minecraft.item.ItemStack;
  26. import net.minecraft.item.crafting.FurnaceRecipes;
  27. import net.minecraft.nbt.NBTTagCompound;
  28. import net.minecraft.nbt.NBTTagList;
  29. import net.minecraft.network.NetworkManager;
  30. import net.minecraft.network.Packet;
  31. import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
  32. import net.minecraft.tileentity.TileEntity;
  33. import net.minecraft.world.ChunkPosition;
  34. import net.minecraftforge.common.util.Constants;
  35. import net.minecraftforge.common.util.ForgeDirection;
  36. import net.minecraftforge.fluids.Fluid;
  37. import net.minecraftforge.fluids.FluidStack;
  38. import net.minecraftforge.fluids.FluidTankInfo;
  39. import net.minecraftforge.fluids.IFluidHandler;
  40. import net.minecraftforge.oredict.OreDictionary;
  41. import shift.sextiarysector.api.gearforce.tileentity.IGearForceHandler;
  42.  
  43. import java.util.ArrayList;
  44. import java.util.List;
  45.  
  46. /**
  47. * Created by A.K. on 14/03/11.
  48. */
  49. @Optional.InterfaceList(
  50. {@Optional.Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHCore"),
  51. @Optional.Interface(iface = "cofh.api.tileentity.IEnergyInfo", modid = "CoFHCore"),
  52. @Optional.Interface(iface = "shift.sextiarysector.api.gearforce.tileentity.IGearForceHandler", modid = "SextiarySector")}
  53. )
  54. public class EcTileEntityMakoReactor extends EcTileMultiPass implements ISidedInventory, IFluidHandler, IEnergyHandler, IEnergyInfo, IGearForceHandler{
  55. public static final int MAX_SMELTING_TIME = 200;
  56. public static final int SMELTING_MAKO_COST = 5;
  57. public static final int MAX_GENERATING_RF_TIME = 200;
  58. public static final int GENERATING_RF_MAKO_COST = 5;
  59. public static final int[] SLOTS_MATERIAL = new int[]{0, 1, 2};
  60. public static final int[] SLOTS_FUEL = new int[]{3};
  61. public static final int[] SLOTS_RESULT = new int[]{4, 5, 6, 7};
  62. public static final int SUM_OF_ALLSLOTS = SLOTS_MATERIAL.length + SLOTS_FUEL.length + SLOTS_RESULT.length;
  63. public static final Range<Integer> RANGE_MATERIAL_SLOTS = Range.closedOpen(0, 3);
  64. public static final Range<Integer> RANGE_FUEL_SLOTS = Range.closedOpen(3, 4);
  65. private static final int MAX_HM_CREATING_COST = 1000 * 1024;
  66. private static final int[][] CONSTRUCTING_BLOCKS_INFO = new int[][]{
  67. {1, 1, 1, 1, 1, 1, 1, 1, 1},
  68. {1, 1, 1, 1, 2, 1, 1, 1, 1},
  69. {1, 1, 1, 1, 2, 1, 1, 1, 1},
  70. {0, 1, 0, 1, 2, 1, 0, 1, 0},
  71. {0, 0, 0, 0, 1, 0, 0, 0, 0}
  72. };
  73. public static final int STEP_RF_VALUE = 10;
  74. public static final int MAX_OUTPUT_RF_VALUE = 100000;
  75. public static final int MAX_RF_CAPACITY = 100000000;
  76. public static final int GF_POWER = 3;
  77. private ItemStack[] items = new ItemStack[SUM_OF_ALLSLOTS];
  78. private ItemStack[] smeltingItems = new ItemStack[SLOTS_MATERIAL.length];
  79. public int smeltingTime;
  80. public int generatingRFTime = MAX_GENERATING_RF_TIME;
  81. private int creatingHugeMateriaPoint;
  82. public EcMakoReactorTank tank = new EcMakoReactorTank(1000 * 10);
  83. private ChunkPosition HMCoord = null;
  84. private int outputMaxRFValue = 100;
  85. private int storedRFEnergy;
  86.  
  87. // public static final Range<Integer> rangeResultSlot = Range.closedOpen(4, 7);
  88. public byte face;
  89.  
  90. @Override
  91. public void markDirty() {
  92. super.markDirty();
  93. if (!this.worldObj.isRemote) {
  94. @SuppressWarnings("unchecked")
  95. List<EntityPlayer> list= this.worldObj.playerEntities;
  96. for (EntityPlayer player : list) {
  97. if (player instanceof EntityPlayerMP) {
  98. ((EntityPlayerMP)player).playerNetServerHandler.sendPacket(this.getDescriptionPacket());
  99. }
  100. }
  101. }
  102. }
  103.  
  104. @Override
  105. public void writeToNBT(NBTTagCompound nbt) {
  106. super.writeToNBT(nbt);
  107. nbt.setByte("face", face);
  108. nbt.setShort("SmeltingTime", (short)smeltingTime);
  109. nbt.setInteger("createHugeMateria", creatingHugeMateriaPoint);
  110. NBTTagList nbtTagList = new NBTTagList();
  111. for (int i = 0; i < items.length; i++) {
  112. if (items[i] != null) {
  113. NBTTagCompound nbtTagCompound = new NBTTagCompound();
  114. nbtTagCompound.setByte("Slot", (byte)i);
  115. items[i].writeToNBT(nbtTagCompound);
  116. nbtTagList.appendTag(nbtTagCompound);
  117. }
  118. }
  119. nbt.setTag("Items", nbtTagList);
  120.  
  121. NBTTagList nbtTagList2 = new NBTTagList();
  122. for (int i = 0; i < smeltingItems.length; i++) {
  123. if (smeltingItems[i] != null) {
  124. NBTTagCompound nbtTagCompound = new NBTTagCompound();
  125. nbtTagCompound.setByte("Slot", (byte)i);
  126. smeltingItems[i].writeToNBT(nbtTagCompound);
  127. nbtTagList2.appendTag(nbtTagCompound);
  128. }
  129. }
  130. nbt.setTag("SmeltingItems", nbtTagList2);
  131.  
  132. nbt.setTag("makoTank", tank.writeToNBT(new NBTTagCompound()));
  133. nbt.setInteger("hmcoordx", HMCoord.chunkPosX);
  134. nbt.setInteger("hmcoordy", HMCoord.chunkPosY);
  135. nbt.setInteger("hmcoordz", HMCoord.chunkPosZ);
  136.  
  137. nbt.setInteger("outputMaxRFValue", outputMaxRFValue);
  138. nbt.setInteger("storedRFEnergy", storedRFEnergy);
  139. nbt.setInteger("generatingRFTime", generatingRFTime);
  140. nbt.setInteger("nowRF", nowRF);
  141. }
  142.  
  143. @Override
  144. public void readFromNBT(NBTTagCompound nbt) {
  145. super.readFromNBT(nbt);
  146. face = nbt.getByte("face");
  147. smeltingTime = nbt.getShort("SmeltingTime");
  148. creatingHugeMateriaPoint = nbt.getInteger("createHugeMateria");
  149. NBTTagList nbtTagList = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
  150. for (int i = 0; i < nbtTagList.tagCount(); i++) {
  151. NBTTagCompound nbtTagCompound = nbtTagList.getCompoundTagAt(i);
  152. byte slot = nbtTagCompound.getByte("Slot");
  153. if (slot >= 0 && slot < items.length) {
  154. items[slot] = ItemStack.loadItemStackFromNBT(nbtTagCompound);
  155. }
  156. }
  157.  
  158. NBTTagList nbtTagList2 = nbt.getTagList("SmeltingItems", Constants.NBT.TAG_COMPOUND);
  159. for (int j = 0; j < smeltingItems.length ; j++) {
  160. smeltingItems[j] = null;
  161. }
  162. for (int i = 0; i < nbtTagList2.tagCount(); i++) {
  163. NBTTagCompound nbtTagCompound = nbtTagList2.getCompoundTagAt(i);
  164. byte slot = nbtTagCompound.getByte("Slot");
  165. if (slot >= 0 && slot < smeltingItems.length) {
  166. smeltingItems[slot] = ItemStack.loadItemStackFromNBT(nbtTagCompound);
  167. }
  168. }
  169.  
  170. tank.readFromNBT(nbt.getCompoundTag("makoTank"));
  171. int hmcoordx = nbt.getInteger("hmcoordx");
  172. int hmcoordy = nbt.getInteger("hmcoordy");
  173. int hmcoordz = nbt.getInteger("hmcoordz");
  174. HMCoord = new ChunkPosition(hmcoordx, hmcoordy, hmcoordz);
  175.  
  176. outputMaxRFValue = nbt.getInteger("outputMaxRFValue");
  177. storedRFEnergy = nbt.getInteger("storedRFEnergy");
  178. generatingRFTime = nbt.getInteger("generatingRFTime");
  179. nowRF = nbt.getInteger("nowRF");
  180. }
  181.  
  182. @Override
  183. public void updateEntity() {
  184. boolean upToDate = false;
  185. if (!this.worldObj.isRemote && isActivated()) {
  186.  
  187. //RFの生成と出力
  188. if (isGenerating()) {
  189. if (tank.getFluidAmount() >= GENERATING_RF_MAKO_COST * getGeneratingRFMakoCost()) {
  190. generatingRF();
  191. upToDate = true;
  192. }
  193. if (extractRF()) upToDate = true;
  194.  
  195. if (extractGF()) upToDate = true;
  196. }
  197.  
  198. //HugeMateria生成処理
  199. if (canMakeHugeMateria()) {
  200. creatingHugeMateriaPoint -= MAX_HM_CREATING_COST;
  201. setHugeMateria(HMCoord.chunkPosX, HMCoord.chunkPosY, HMCoord.chunkPosZ);
  202. }
  203.  
  204. //魔晄バケツ・マテリアからの搬入処理
  205. if (!tank.isFull() && items[SLOTS_FUEL[0]] != null && MakoUtils.isMako(items[SLOTS_FUEL[0]])) {
  206. int makoAmount = MakoUtils.getMakoFromItem(items[SLOTS_FUEL[0]]);
  207. if (tank.getFluidAmount() + makoAmount <= tank.getCapacity()) {
  208. tank.fill(new FluidStack(EnchantChanger.fluidLifeStream, makoAmount), true);
  209. items[SLOTS_FUEL[0]].stackSize--;
  210. if (items[SLOTS_FUEL[0]].stackSize <= 0) {
  211. setInventorySlotContents(SLOTS_FUEL[0], items[SLOTS_FUEL[0]].getItem().getContainerItem(items[SLOTS_FUEL[0]]));
  212. }
  213. upToDate = true;
  214. }
  215. }
  216.  
  217. if (canSmelting()) {
  218. for (int i = 0; i < SLOTS_MATERIAL.length; i++) {
  219. if (smeltingItems[i] == null && canSmeltThisItem(items[SLOTS_MATERIAL[i]])) {
  220. smeltingItems[i] = decrStackSize(SLOTS_MATERIAL[i], 1);
  221. upToDate = true;
  222. }
  223. }
  224. }
  225.  
  226. if (isSmelting()) {
  227. ++smeltingTime;
  228. if (smeltingTime == MAX_SMELTING_TIME) {
  229. smeltItems();
  230. smeltingTime = 0;
  231. upToDate = true;
  232. }
  233. } else {
  234. smeltingTime = 0;
  235. }
  236. }
  237. if (upToDate) {
  238. this.markDirty();
  239. }
  240. }
  241. @Override
  242. public Packet getDescriptionPacket() {
  243. return super.getDescriptionPacket();
  244. }
  245.  
  246. @Override
  247. public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
  248. super.onDataPacket(net, pkt);
  249. }
  250.  
  251. private void smeltItems() {
  252. tank.drain(SMELTING_MAKO_COST, true);
  253. creatingHugeMateriaPoint += SMELTING_MAKO_COST;
  254. ItemStack smelted;
  255. for (int i = 0; i < smeltingItems.length; i++) {
  256. if (smeltingItems[i] != null) {
  257. smelted = getSmeltedItem(smeltingItems[i]);
  258. if (items[SLOTS_RESULT[i]] == null) {
  259. items[SLOTS_RESULT[i]] = smelted.copy();
  260. smeltingItems[i] = null;
  261. } else {
  262. if (items[SLOTS_RESULT[i]].isItemEqual(smelted)
  263. && ItemStack.areItemStackTagsEqual(items[SLOTS_RESULT[i]], smelted)
  264. && items[SLOTS_RESULT[i]].stackSize < items[SLOTS_RESULT[i]].getMaxStackSize()) {
  265. items[SLOTS_RESULT[i]].stackSize += smelted.stackSize;
  266. smeltingItems[i] = null;
  267. }
  268. }
  269. }
  270. }
  271. if (this.worldObj.rand.nextInt(ConfigurationUtils.materiaGeneratingRatio) == 0 && items[SLOTS_RESULT[SLOTS_RESULT.length - 1]] == null) {
  272. ItemStack materia = new ItemStack(EnchantChanger.itemMateria);
  273. EnchantmentData enchantmentData = EnchantmentUtils.getEnchantmentData(this.worldObj.rand);
  274. EnchantmentUtils.addEnchantmentToItem(materia, enchantmentData.enchantmentobj, enchantmentData.enchantmentLevel);
  275. items[SLOTS_RESULT[SLOTS_RESULT.length - 1]] = materia;
  276. }
  277. this.markDirty();
  278. }
  279.  
  280. public void generatingRF() {
  281. --generatingRFTime;
  282. addRFEnergy(getOutputMaxRFValue());
  283. if (generatingRFTime <= 0) {
  284. tank.drain(GENERATING_RF_MAKO_COST * getGeneratingRFMakoCost(), true);
  285. generatingRFTime = MAX_GENERATING_RF_TIME;
  286. creatingHugeMateriaPoint += getGeneratingRFMakoCost();
  287. }
  288. }
  289.  
  290. public boolean extractRF() {
  291. boolean upToDate = false;
  292. int needToExtract;
  293. TileEntity neighborTile;
  294. int extractable;
  295. for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
  296. extractable = Math.min(getOutputMaxRFValue(), getStoredRFEnergy());
  297. if (extractable <= 0) break;
  298. neighborTile = this.worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
  299. if (CoopTE.isIEnergyHandler(neighborTile)) {
  300. needToExtract = CoopTE.getNeedRF(neighborTile, direction, extractable);
  301. extractEnergy(direction, needToExtract, false);
  302. if (needToExtract > 0) {
  303. upToDate = true;
  304. }
  305. }
  306. }
  307. return upToDate;
  308. }
  309.  
  310. public boolean extractGF() {
  311. boolean upToDate = false;
  312. int needToExtract;
  313. TileEntity neighborTile;
  314. int extractable;
  315. for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
  316. extractable = Math.min(getOutputMaxRFValue(), getStoredRFEnergy());
  317. if (extractable <= 0) break;
  318. neighborTile = this.worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
  319. if (CoopSS.isGFEnergyHandler(neighborTile)) {
  320. needToExtract = CoopSS.getNeedGF(neighborTile, direction, extractable);
  321. drawEnergy(direction, GF_POWER, needToExtract, false);
  322. if (needToExtract > 0) {
  323. upToDate = true;
  324. }
  325. }
  326. }
  327. return upToDate;
  328. }
  329.  
  330. public boolean canSmelting() {
  331. return tank.getFluidAmount() >= SMELTING_MAKO_COST;
  332. }
  333.  
  334. public boolean isSmelting() {
  335. for (ItemStack itemStack : smeltingItems) {
  336. if (itemStack != null) {
  337. return true;
  338. }
  339. }
  340. return false;
  341. }
  342.  
  343. public boolean isActivated() {
  344. if (HMCoord == null) {
  345. return false;
  346. }
  347. Block checkBlock;
  348. int checkBlockMeta;
  349. int index;
  350. String blockName;
  351. for (int y = -1 ; y <= 3; y++) {
  352. for (int x = -1 ; x <= 1; x++) {
  353. for (int z = -1; z <= 1; z++) {
  354. checkBlock = worldObj.getBlock(HMCoord.chunkPosX + x, HMCoord.chunkPosY + y, HMCoord.chunkPosZ + z);
  355. checkBlockMeta = worldObj.getBlockMetadata(HMCoord.chunkPosX + x, HMCoord.chunkPosY + y, HMCoord.chunkPosZ + z);
  356. index = (x + 1) + (z + 1) * 3;
  357. if (CONSTRUCTING_BLOCKS_INFO[y + 1][index] == 1 && !isBaseBlock(checkBlock, checkBlockMeta)) {
  358. return false;
  359. }
  360.  
  361. if (CONSTRUCTING_BLOCKS_INFO[y + 1][index] == 2 && !checkBlock.equals(Blocks.air)) {
  362. return false;
  363. }
  364. }
  365. }
  366. }
  367. return true;
  368. }
  369.  
  370. public boolean isBaseBlock(Block checkBlock, int checkMeta) {
  371. int[] oreIDs = OreDictionary.getOreIDs(getBaseBlockItemStack());
  372. ItemStack checkStack = new ItemStack(checkBlock, 1, checkMeta);
  373. if (oreIDs.length > 0) {
  374. for (int oreid : oreIDs) {
  375. ArrayList<ItemStack> oreList = OreDictionary.getOres(OreDictionary.getOreName(oreid));
  376. for (ItemStack itemStack : oreList) {
  377. if (itemStack.isItemEqual(checkStack)) {
  378. return true;
  379. }
  380. }
  381. }
  382. }
  383. return getBaseBlock().equals(checkBlock) && getBlockMetadata() == checkMeta;
  384. }
  385.  
  386. public boolean isGenerating() {
  387. return isEnergyNetworkModLoaded() && isPowered() && getStoredRFEnergy() + getOutputMaxRFValue() <= MAX_RF_CAPACITY;
  388. }
  389.  
  390. public boolean isEnergyNetworkModLoaded() {
  391. return EnchantChanger.loadTE || EnchantChanger.loadSS;
  392. }
  393.  
  394. public boolean isPowered() {
  395. return this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
  396. }
  397.  
  398.  
  399.  
  400. public int getGeneratingRFMakoCost() {
  401. return getOutputMaxRFValue() / STEP_RF_VALUE;
  402. }
  403.  
  404. public boolean canMakeHugeMateria() {
  405. if (HMCoord == null) return false;
  406. for (int i = 0; i < 3 ; i++) {
  407. if (!worldObj.getBlock(HMCoord.chunkPosX, HMCoord.chunkPosY + i, HMCoord.chunkPosZ).equals(Blocks.air)) {
  408. return false;
  409. }
  410. }
  411. return creatingHugeMateriaPoint > MAX_HM_CREATING_COST;
  412. }
  413.  
  414. public boolean canSmeltThisItem(ItemStack itemStack) {
  415. return itemStack != null && getSmeltedItem(itemStack) != null;
  416. }
  417.  
  418. public ItemStack getSmeltedItem(ItemStack itemStack) {
  419. return FurnaceRecipes.smelting().getSmeltingResult(itemStack);
  420. }
  421.  
  422. public void setFace(byte var1) {
  423. this.face = var1;
  424. ForgeDirection direction = ForgeDirection.VALID_DIRECTIONS[ForgeDirection.OPPOSITES[face]];
  425. HMCoord = new ChunkPosition(xCoord + direction.offsetX * 2, yCoord, zCoord + direction.offsetZ * 2);
  426. }
  427.  
  428. public void setHugeMateria(int x, int y, int z) {
  429. Block hugeMateria = EnchantChanger.blockHugeMateria;
  430. worldObj.setBlock(x, y, z, hugeMateria, 0, 1);
  431. worldObj.setBlock(x, y + 1, z, hugeMateria, 1, 1);
  432. worldObj.setBlock(x, y + 2, z, hugeMateria, 2, 1);
  433. worldObj.notifyBlocksOfNeighborChange(x, y, z, hugeMateria);
  434. worldObj.notifyBlocksOfNeighborChange(x, y + 1, z, hugeMateria);
  435. worldObj.notifyBlocksOfNeighborChange(x, y + 2, z, hugeMateria);
  436. }
  437.  
  438. @Override
  439. public int[] getAccessibleSlotsFromSide(int side) {
  440. if (side == 0) {
  441. return SLOTS_RESULT;
  442. }
  443.  
  444. if (side == 1) {
  445. return SLOTS_MATERIAL;
  446. }
  447.  
  448. return SLOTS_FUEL;
  449. }
  450.  
  451. @Override
  452. public boolean canInsertItem(int slot, ItemStack item, int side) {
  453. return this.isItemValidForSlot(slot, item);
  454. }
  455.  
  456. @Override
  457. public boolean canExtractItem(int slot, ItemStack item, int side) {
  458. return side != 1 || RANGE_FUEL_SLOTS.contains(slot) || item.getItem() instanceof ItemBucket;
  459. }
  460.  
  461. @Override
  462. public int getSizeInventory() {
  463. return items.length;
  464. }
  465.  
  466. @Override
  467. public ItemStack getStackInSlot(int slot) {
  468. if (slot < items.length) {
  469. return items[slot];
  470. }
  471. return null;
  472. }
  473.  
  474. @Override
  475. public ItemStack decrStackSize(int slot, int size) {
  476. if (slot < items.length && items[slot] != null) {
  477. ItemStack returnStack;
  478. if (items[slot].stackSize <= size) {
  479. returnStack = items[slot];
  480. items[slot] = null;
  481. return returnStack;
  482. } else {
  483. returnStack = items[slot].splitStack(size);
  484. if (items[slot].stackSize <= 0) {
  485. items[slot] = null;
  486. }
  487. return returnStack;
  488. }
  489. }
  490. return null;
  491. }
  492.  
  493. @Override
  494. public ItemStack getStackInSlotOnClosing(int slot) {
  495. ItemStack stack = getStackInSlot(slot);
  496. if (stack != null) {
  497. setInventorySlotContents(slot, null);
  498. }
  499. return stack;
  500. }
  501.  
  502. @Override
  503. public void setInventorySlotContents(int slot, ItemStack item) {
  504. if (slot < items.length) {
  505. items[slot] = item;
  506. if (items[slot] != null && items[slot].stackSize > this.getInventoryStackLimit()) {
  507. items[slot].stackSize = this.getInventoryStackLimit();
  508. }
  509. }
  510. }
  511.  
  512. @Override
  513. public String getInventoryName() {
  514. return "container.makoreactor";
  515. }
  516.  
  517. @Override
  518. public boolean hasCustomInventoryName() {
  519. return false;
  520. }
  521.  
  522. @Override
  523. public int getInventoryStackLimit() {
  524. return 64;
  525. }
  526.  
  527. @Override
  528. public boolean isUseableByPlayer(EntityPlayer player) {
  529. return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this && player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64;
  530. }
  531.  
  532. @Override
  533. public void openInventory() {
  534.  
  535. }
  536.  
  537. @Override
  538. public void closeInventory() {
  539.  
  540. }
  541.  
  542. @SideOnly(Side.CLIENT)
  543. public int getFluidAmountScaled(int scale) {
  544. return this.tank.getFluidAmount() * scale / this.tank.getCapacity();
  545. }
  546.  
  547. @SideOnly(Side.CLIENT)
  548. public int getSmeltingTimeScaled(int scale) {
  549. return this.smeltingTime * scale / MAX_SMELTING_TIME;
  550. }
  551.  
  552. @Override
  553. public boolean isItemValidForSlot(int slot, ItemStack item) {
  554. if (slot < items.length) {
  555. if (RANGE_MATERIAL_SLOTS.contains(slot)) {
  556. return canSmeltThisItem(item);
  557. }
  558.  
  559. if (RANGE_FUEL_SLOTS.contains(slot)) {
  560. return item != null && MakoUtils.isMako(item);
  561. }
  562. }
  563. return false;
  564. }
  565.  
  566. @Override
  567. public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
  568. if (resource == null || resource.getFluid() == null) {
  569. return 0;
  570. }
  571. FluidStack currentFluidStack = tank.getFluid();
  572. if (currentFluidStack != null && currentFluidStack.amount > 0 && !currentFluidStack.isFluidEqual(resource)) {
  573. return 0;
  574. }
  575.  
  576. int used = tank.fill(resource, doFill);
  577. resource.amount -= used;
  578. return used;
  579. }
  580.  
  581. @Override
  582. public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
  583. if (resource == null) {
  584. return null;
  585. }
  586. if (resource.getFluid().equals(tank.getFluidType())) {
  587. return tank.drain(resource.amount, doDrain);
  588. }
  589. return null;
  590. }
  591.  
  592. @Override
  593. public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
  594. return tank.drain(maxDrain, doDrain);
  595. }
  596.  
  597. @Override
  598. public boolean canFill(ForgeDirection from, Fluid fluid) {
  599. return fluid.getBlock() instanceof EcBlockLifeStreamFluid && !tank.isFull();
  600. }
  601.  
  602. @Override
  603. public boolean canDrain(ForgeDirection from, Fluid fluid) {
  604. return fluid.getBlock() instanceof EcBlockLifeStreamFluid && !tank.isEmpty();
  605. }
  606.  
  607. @Override
  608. public FluidTankInfo[] getTankInfo(ForgeDirection from) {
  609. return new FluidTankInfo[]{tank.getInfo()};
  610. }
  611.  
  612. @Optional.Method(modid = "CoFHCore")
  613. @Override
  614. public int receiveEnergy(ForgeDirection forgeDirection, int i, boolean b) {
  615. return 0;//発電のみ
  616. }
  617.  
  618. private int nowRF;
  619.  
  620. @Optional.Method(modid = "CoFHCore")
  621. @Override
  622. public int extractEnergy(ForgeDirection forgeDirection, int i, boolean b) {
  623. int extract = Math.min(getStoredRFEnergy(), Math.min(getOutputMaxRFValue(), i));
  624. if (!b) {
  625. addRFEnergy(-extract);
  626. nowRF = extract;
  627. }
  628. return extract;
  629. }
  630.  
  631. @Optional.Method(modid = "CoFHCore")
  632. @Override
  633. public int getEnergyStored(ForgeDirection forgeDirection) {
  634. return getStoredRFEnergy();
  635. }
  636.  
  637. @Optional.Method(modid = "CoFHCore")
  638. @Override
  639. public int getMaxEnergyStored(ForgeDirection forgeDirection) {
  640. return MAX_RF_CAPACITY;
  641. }
  642.  
  643. @Optional.Method(modid = "CoFHCore")
  644. @Override
  645. public boolean canConnectEnergy(ForgeDirection forgeDirection) {
  646. TileEntity tile = this.worldObj.getTileEntity(xCoord + forgeDirection.offsetX, yCoord + forgeDirection.offsetY, zCoord + forgeDirection.offsetZ);
  647. return tile instanceof IEnergyConnection;
  648. }
  649.  
  650. public int getOutputMaxRFValue() {
  651. return outputMaxRFValue;
  652. }
  653.  
  654. public void setOutputMaxRFValue(int outputMaxRFValue) {
  655. this.outputMaxRFValue = outputMaxRFValue;
  656. }
  657.  
  658. public void stepOutputMaxRFValue(int stepValue) {
  659. if (this.outputMaxRFValue + stepValue >= 10 && this.outputMaxRFValue + stepValue <= MAX_OUTPUT_RF_VALUE) {
  660. this.outputMaxRFValue += stepValue;
  661. }
  662. }
  663.  
  664. public int getStoredRFEnergy() {
  665. return storedRFEnergy;
  666. }
  667.  
  668. public void setStoredRFEnergy(int storedRFEnergy) {
  669. this.storedRFEnergy = storedRFEnergy;
  670. }
  671.  
  672. public void addRFEnergy(int add) {
  673. this.storedRFEnergy += add;
  674. }
  675.  
  676. @Optional.Method(modid = "CoFHCore")
  677. @Override
  678. public int getInfoEnergyPerTick() {
  679. return nowRF;
  680. }
  681.  
  682. @Optional.Method(modid = "CoFHCore")
  683. @Override
  684. public int getInfoMaxEnergyPerTick() {
  685. return getOutputMaxRFValue();
  686. }
  687.  
  688. @Optional.Method(modid = "CoFHCore")
  689. @Override
  690. public int getInfoEnergyStored() {
  691. return getStoredRFEnergy();
  692. }
  693.  
  694. @Optional.Method(modid = "CoFHCore")
  695. @Override
  696. public int getInfoMaxEnergyStored() {
  697. return MAX_RF_CAPACITY;
  698. }
  699.  
  700. @Optional.Method(modid = "SextiarySector")
  701. @Override
  702. public int addEnergy(ForgeDirection from, int power, int speed, boolean simulate) {
  703. return 0;
  704. }
  705.  
  706. @Optional.Method(modid = "SextiarySector")
  707. @Override
  708. public int drawEnergy(ForgeDirection from, int power, int speed, boolean simulate) {
  709. int extract = Math.min(getStoredRFEnergy(), Math.min(getOutputMaxRFValue(), speed));
  710. if (!simulate) {
  711. addRFEnergy(-extract);
  712. nowRF = extract;
  713. }
  714. return extract;
  715. }
  716.  
  717. @Optional.Method(modid = "SextiarySector")
  718. @Override
  719. public boolean canInterface(ForgeDirection from) {
  720. return true;
  721. }
  722.  
  723. @Optional.Method(modid = "SextiarySector")
  724. @Override
  725. public int getPowerStored(ForgeDirection from) {
  726. return 3;
  727. }
  728.  
  729. @Optional.Method(modid = "SextiarySector")
  730. @Override
  731. public int getSpeedStored(ForgeDirection from) {
  732. return getStoredRFEnergy();
  733. }
  734.  
  735. @Optional.Method(modid = "SextiarySector")
  736. @Override
  737. public int getMaxPowerStored(ForgeDirection from) {
  738. return 3;
  739. }
  740.  
  741. @Optional.Method(modid = "SextiarySector")
  742. @Override
  743. public long getMaxSpeedStored(ForgeDirection from) {
  744. return MAX_RF_CAPACITY;
  745. }
  746. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement