Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. public class TileEntitySolarPanel extends TileEntity implements ITickable {
  2.  
  3. public int powerTransfer;
  4. public int tier;
  5. public boolean seesSun = false;
  6. public boolean active = false;
  7.  
  8. public TileEntitySolarPanel(int tier) {
  9. this.tier = tier;
  10. switchTier();
  11. }
  12.  
  13. public int getPowerTransfer() {
  14. return powerTransfer;
  15. }
  16.  
  17. @Override
  18. @SuppressWarnings("unchecked")
  19. public <T> T getCapability (Capability<T> capability, EnumFacing facing) {
  20.  
  21. if (capability == TeslaCapabilities.CAPABILITY_PRODUCER)
  22. return (T) new InfiniteTeslaProducer();
  23.  
  24. return super.getCapability(capability, facing);
  25. }
  26.  
  27. @Override
  28. public boolean hasCapability (Capability<?> capability, EnumFacing facing) {
  29.  
  30. if (capability == TeslaCapabilities.CAPABILITY_PRODUCER)
  31. return true;
  32.  
  33. return super.hasCapability(capability, facing);
  34. }
  35.  
  36. @Override
  37. public void update () {
  38.  
  39. if(!worldObj.isRemote)
  40. {
  41. if(worldObj.isDaytime() && ((!worldObj.isRaining() && !worldObj.isThundering()) || isDesert()) && !worldObj.provider.getHasNoSky() && worldObj.canSeeSky(getPos().add(0, 4, 0)))
  42. {
  43. seesSun = true;
  44. }
  45. else {
  46. seesSun = false;
  47. }
  48. }
  49.  
  50. if (seesSun)
  51. {
  52. active = true;
  53. TeslaUtils.distributePowerToAllFaces(this.worldObj, this.pos, powerTransfer, false);
  54. }
  55. else
  56. {
  57. active = false;
  58. }
  59. }
  60.  
  61. public void switchTier() {
  62. switch (tier) {
  63. case 1:
  64. powerTransfer = 1;
  65. break;
  66.  
  67. case 2:
  68. powerTransfer = 2;
  69. break;
  70.  
  71. case 3:
  72. powerTransfer = 4;
  73. break;
  74.  
  75. case 4:
  76. powerTransfer = 8;
  77. break;
  78. case 5:
  79. powerTransfer = 16;
  80. break;
  81.  
  82. default:
  83. powerTransfer = 1;
  84. break;
  85. }
  86. }
  87.  
  88. public boolean isDesert()
  89. {
  90. return worldObj.provider.getBiomeForCoords(getPos()).getBiomeClass() == BiomeDesert.class;
  91. }
  92.  
  93. @Override
  94. public void readFromNBT(NBTTagCompound compound) {
  95. super.readFromNBT(compound);
  96. //this.readFromNBT(compound);
  97. //powerTransfer = compound.getInteger("counter");
  98. }
  99.  
  100. @Override
  101. public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  102. super.writeToNBT(compound);
  103. //compound.setInteger("counter", powerTransfer);
  104. //this.writeToNBT(compound);
  105. return compound;
  106. }
  107.  
  108.  
  109.  
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement