Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. package astreaInfinitum.tileEntities.eco;
  2.  
  3. import astreaInfinitum.api.IEcoAltarBlock;
  4. import astreaInfinitum.api.utils.TileEntityClientServer;
  5. import astreaInfinitum.blocks.AIBlocks;
  6. import astreaInfinitum.network.MessageAltarSync;
  7. import astreaInfinitum.network.PacketHandler;
  8. import astreaInfinitum.utils.BlockPos;
  9. import cpw.mods.fml.client.FMLClientHandler;
  10. import cpw.mods.fml.common.network.NetworkRegistry;
  11. import net.minecraft.block.Block;
  12. import net.minecraft.init.Blocks;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.nbt.NBTTagList;
  15. import net.minecraft.world.World;
  16. import net.minecraftforge.common.util.Constants;
  17.  
  18. import java.util.ArrayList;
  19. import java.util.List;
  20.  
  21. /**
  22. * Created by Jared on 8/26/2015.
  23. */
  24. public class TileEntityEcoAltar extends TileEntityClientServer {
  25. public boolean activated;
  26. public boolean shouldConvert;
  27. public int convertTime;
  28. public boolean converted = false;
  29. public boolean shouldSendParticle;
  30. public List<BlockPos> blocksToConvert = new ArrayList<BlockPos>();
  31. public boolean converting = false;
  32.  
  33. public TileEntityEcoAltar() {
  34. }
  35.  
  36. @Override
  37. public void updateEntity() {
  38. super.updateEntity();
  39. }
  40.  
  41. public void updateClient() {
  42. if (converting && !blocksToConvert.isEmpty()) {
  43. convert(worldObj, xCoord, yCoord, zCoord, true);
  44. }
  45. }
  46.  
  47. public void updateServer() {
  48. if (!activated) {
  49. activated = canActivate(worldObj, xCoord, yCoord, zCoord);
  50. if (activated) {
  51. System.out.println("activated");
  52. markDirty();
  53. }
  54. }
  55. if (converting && !blocksToConvert.isEmpty()) {
  56. convert(worldObj, xCoord, yCoord, zCoord, false);
  57.  
  58. }
  59. convertTime -= 1;
  60. if (convertTime <= 0) {
  61. converted = false;
  62. convertTime = 5;
  63. }
  64. }
  65.  
  66. public boolean canActivate(World world, int x, int y, int z) {
  67. for (int X = x - 3; X <= x + 3; X++) {
  68. for (int Z = z - 3; Z <= z + 3; Z++) {
  69. if (X != x && Z != z) {
  70. if (world.getBlock(X, y, Z) == null || !(world.getBlock(X, y, Z) == Blocks.nether_brick || (world.getBlock(X, y, Z) == Blocks.quartz_block || world.getBlock(X, y, Z) instanceof IEcoAltarBlock))) {
  71. return false;
  72. }
  73. }
  74. }
  75. }
  76. return true;
  77. }
  78.  
  79. public void getBlocksToConvert(World world, int x, int y, int z) {
  80. for (int X = x - 3; X <= x + 3; X++) {
  81. for (int Z = z - 3; Z <= z + 3; Z++) {
  82. Block block = world.getBlock(X, y, Z);
  83. if (block != null) {
  84. if (block == Blocks.nether_brick || block == Blocks.quartz_block) {
  85. blocksToConvert.add(new BlockPos(X, y, Z));
  86. }
  87. }
  88. }
  89. }
  90. }
  91.  
  92. public void convert(World world, int x, int y, int z, boolean particle) {
  93. for (int j = 0; j < blocksToConvert.size(); j++) {
  94. BlockPos pos = blocksToConvert.get(j);
  95. int X = pos.x;
  96. int Z = pos.z;
  97. if (!converted) {
  98. if (worldObj.getBlock(X, yCoord, Z) == Blocks.nether_brick) {
  99. if (particle) {
  100. System.out.println("part");
  101. for (int i = 0; i < 16; i++) {
  102. world.spawnParticle("blockdust_" + Block.getIdFromBlock(worldObj.getBlock(X, yCoord, Z)) + "_0", X, yCoord, Z, 0, 0.8, 0);
  103. }
  104. }
  105. worldObj.setBlock(X, yCoord, Z, AIBlocks.ecoAltarBlock);
  106. converted = true;
  107. }
  108.  
  109. if (worldObj.getBlock(X, yCoord, Z) == Blocks.quartz_block) {
  110. for (int i = 0; i < 16; i++) {
  111. FMLClientHandler.instance().getClient().theWorld.spawnParticle("blockdust_" + Block.getIdFromBlock(worldObj.getBlock(X, yCoord, Z)) + "_0", X, yCoord, Z, 0, 0.8, 0);
  112. }
  113. worldObj.setBlock(X, yCoord, Z, AIBlocks.ecoRitualBlock);
  114. converted = true;
  115.  
  116. }
  117. if (converted) {
  118. blocksToConvert.remove(pos);
  119. markDirty();
  120. }
  121. }
  122.  
  123. }
  124. }
  125.  
  126. public boolean shouldActivate(World world, int x, int y, int z) {
  127. for (int X = x - 3; X <= x + 3; X++) {
  128. for (int Z = z - 3; Z <= z + 3; Z++) {
  129. if (world.getBlock(X, y, Z) == Blocks.nether_brick) {
  130. return true;
  131. }
  132. if (world.getBlock(X, y, Z) == Blocks.quartz_block) {
  133. return true;
  134. }
  135.  
  136. }
  137. }
  138. return false;
  139. }
  140.  
  141. @Override
  142. public void markDirty() {
  143. super.markDirty();
  144. PacketHandler.INSTANCE.sendToAllAround(new MessageAltarSync(this), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 128D));
  145. }
  146.  
  147. public boolean isAltarActivated(World world, int x, int y, int z) {
  148. for (int X = x - 3; X <= x + 3; X++) {
  149. for (int Z = z - 3; Z <= z + 3; Z++) {
  150. if (X != x && Z != z) {
  151. if (!(world.getBlock(X, y, Z) instanceof IEcoAltarBlock)) {
  152. return false;
  153. }
  154. }
  155. }
  156. }
  157. return true;
  158. }
  159.  
  160. @Override
  161. public void writeToNBT(NBTTagCompound tag) {
  162. super.writeToNBT(tag);
  163. tag.setBoolean("activated", activated);
  164. tag.setBoolean("shouldConvert", shouldConvert);
  165. tag.setInteger("convertTime", convertTime);
  166. writeBlocksToNbt(tag);
  167. }
  168.  
  169. public void writeBlocksToNbt(NBTTagCompound tags) {
  170. NBTTagList nbttaglist = new NBTTagList();
  171. for (int iter = 0; iter < blocksToConvert.size(); iter++) {
  172. if (blocksToConvert.get(iter) != null) {
  173. NBTTagCompound tagList = new NBTTagCompound();
  174. tagList.setInteger("position", iter);
  175. blocksToConvert.get(iter).writeToNbt(tagList);
  176. nbttaglist.appendTag(tagList);
  177. }
  178. }
  179.  
  180. tags.setTag("Blocks", nbttaglist);
  181. }
  182.  
  183. @Override
  184. public void readFromNBT(NBTTagCompound tag) {
  185. super.readFromNBT(tag);
  186. activated = tag.getBoolean("activated");
  187. shouldConvert = tag.getBoolean("shouldConvert");
  188. convertTime = tag.getInteger("convertTime");
  189. readBlocksFromNbt(tag);
  190. }
  191.  
  192. public void readBlocksFromNbt(NBTTagCompound tags) {
  193. NBTTagList nbttaglist = tags.getTagList("Blocks", Constants.NBT.TAG_COMPOUND);
  194. for (int iter = 0; iter < nbttaglist.tagCount(); iter++) {
  195. NBTTagCompound tagList = nbttaglist.getCompoundTagAt(iter);
  196. int position = tagList.getInteger("position");
  197. if (position >= 0 && position < blocksToConvert.size()) {
  198. blocksToConvert.set(position, BlockPos.getBlockFromNbt(tagList));
  199. }
  200. }
  201. }
  202.  
  203. public boolean isActivated() {
  204. return activated;
  205. }
  206.  
  207. public boolean isShouldConvert() {
  208. return shouldConvert;
  209. }
  210.  
  211. public int getConvertTime() {
  212. return convertTime;
  213. }
  214.  
  215. public boolean isConverted() {
  216. return converted;
  217. }
  218.  
  219. public boolean isShouldSendParticle() {
  220. return shouldSendParticle;
  221. }
  222.  
  223. public List<BlockPos> getBlocksToConvert() {
  224. return blocksToConvert;
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement