Advertisement
Guest User

Untitled

a guest
Aug 13th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. package com.jolteffect.justsolars.tileentity;
  2.  
  3.  
  4.  
  5. import com.jolteffect.justsolars.block.BlockSolarPanel;
  6. import com.jolteffect.justsolars.init.ModBlocks;
  7. import com.jolteffect.justsolars.utility.EnumSolarTier;
  8. import com.jolteffect.justsolars.utility.LogHelper;
  9.  
  10. import net.darkhax.tesla.api.implementation.BaseTeslaContainer;
  11. import net.darkhax.tesla.api.implementation.InfiniteTeslaProducer;
  12. import net.darkhax.tesla.capability.TeslaCapabilities;
  13. import net.darkhax.tesla.lib.TeslaUtils;
  14. import net.minecraft.block.properties.PropertyEnum;
  15. import net.minecraft.block.state.IBlockState;
  16. import net.minecraft.nbt.NBTTagCompound;
  17. import net.minecraft.tileentity.TileEntity;
  18. import net.minecraft.util.EnumFacing;
  19. import net.minecraft.util.ITickable;
  20. import net.minecraft.world.biome.BiomeDesert;
  21. import net.minecraftforge.common.capabilities.Capability;
  22.  
  23.  
  24. public class TileEntitySolarPanel extends TileEntity implements ITickable {
  25.  
  26. public BaseTeslaContainer container;
  27. public boolean seesSun = false;
  28. public boolean active = false;
  29.  
  30.  
  31.  
  32.  
  33. public TileEntitySolarPanel() {
  34.  
  35. // Initializes the container. Very straight forward.
  36.  
  37. this.container = new BaseTeslaContainer();
  38.  
  39.  
  40. }
  41.  
  42. @Override
  43. public void readFromNBT(NBTTagCompound compound) {
  44.  
  45. super.readFromNBT(compound);
  46.  
  47. // It is important for the power being stored to be persistent. The
  48. // BaseTeslaContainer
  49. // includes a method to make reading one from a compound tag very easy.
  50. // This method is
  51. // completely optional though, you can handle saving however you prefer.
  52. // You could even
  53. // choose not to, but then power won't be saved when you close the game.
  54. this.container = new BaseTeslaContainer(
  55. compound.getCompoundTag("TeslaContainer"));
  56. }
  57.  
  58. @Override
  59. public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  60.  
  61. // It is important for the power being stored to be persistent. The
  62. // BaseTeslaContainer
  63. // includes a method to make writing one to a compound tag very easy.
  64. // This method is
  65. // completely optional though, you can handle saving however you prefer.
  66. // You could even
  67. // choose not to, but then power won't be saved when you close the game.
  68. compound.setTag("TeslaContainer", this.container.serializeNBT());
  69. return super.writeToNBT(compound);
  70. }
  71.  
  72. @Override
  73. @SuppressWarnings("unchecked")
  74. public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
  75.  
  76. // This method is where other things will try to access your
  77. // TileEntity's Tesla
  78. // capability. In the case of the analyzer, is a consumer, producer and
  79. // holder so we
  80. // can allow requests that are looking for any of those things. This
  81. // example also does
  82. // not care about which side is being accessed, however if you wanted to
  83. // restrict which
  84. // side can be used, for example only allow power input through the
  85. // back, that could be
  86. // done here.
  87. if (capability == TeslaCapabilities.CAPABILITY_PRODUCER)
  88. return (T) this.container;
  89.  
  90. return super.getCapability(capability, facing);
  91. }
  92.  
  93. @Override
  94. public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
  95.  
  96. // This method replaces the instanceof checks that would be used in an
  97. // interface based
  98. // system. It can be used by other things to see if the TileEntity uses
  99. // a capability or
  100. // not. This example is a Consumer, Producer and Holder, so we return
  101. // true for all
  102. // three. This can also be used to restrict access on certain sides, for
  103. // example if you
  104. // only accept power input from the bottom of the block, you would only
  105. // return true for
  106. // Consumer if the facing parameter was down.
  107. if (capability == TeslaCapabilities.CAPABILITY_PRODUCER)
  108. return true;
  109.  
  110. return super.hasCapability(capability, facing);
  111. }
  112.  
  113. @Override
  114. public void update() {
  115. //EnumSolarTier solarTiers =
  116. LogHelper.logInfo("JUSTSOLARS --------------Get Value = " + this.worldObj.getBlockState(pos).getValue(BlockSolarPanel.TIER));
  117. LogHelper.logInfo("JUSTSOLARS --------------Get Value = " + this.worldObj.getBlockState(pos).getValue());
  118.  
  119. if (!worldObj.isRemote) {
  120. if (worldObj.isDaytime()
  121. && ((!worldObj.isRaining() && !worldObj.isThundering()) || isDesert())
  122. && !worldObj.provider.getHasNoSky()
  123. && worldObj.canSeeSky(getPos().add(0, 4, 0))) {
  124. seesSun = true;
  125. } else {
  126. seesSun = false;
  127. }
  128. }
  129.  
  130. if (seesSun) {
  131. active = true;
  132.  
  133. //EnumSolarTier solarTier = this.worldObj.getBlockState(this.pos).getValue(BlockSolarPanel.TIER);
  134. //TeslaUtils.distributePowerToAllFaces(this.worldObj, this.pos, solarTiers.getPowerTransferLimit(), false);
  135.  
  136. } else {
  137. active = false;
  138. }
  139. }
  140.  
  141. public boolean isDesert() {
  142. return worldObj.provider.getBiomeForCoords(getPos()).getBiomeClass() == BiomeDesert.class;
  143. }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement