Advertisement
Guest User

Untitled

a guest
Jun 18th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.95 KB | None | 0 0
  1.  
  2. package skyinf;
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Random;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.util.Direction;
  11. import net.minecraft.util.LongHashMap;
  12. import net.minecraft.util.MathHelper;
  13. import net.minecraft.world.ChunkCoordIntPair;
  14. import net.minecraft.world.PortalPosition;
  15. import net.minecraft.world.Teleporter;
  16. import net.minecraft.world.World;
  17. import net.minecraft.world.WorldServer;
  18.  
  19. public class TeleporterMoon extends Teleporter {
  20. public Random rand = new Random();
  21. World world;
  22. static Ship1 shipGen;
  23. private final WorldServer worldServerInstance;
  24.  
  25. /** A private Random() function in Teleporter */
  26. private final Random random;
  27.  
  28. /** Stores successful portal placement locations for rapid lookup. */
  29. private final LongHashMap destinationCoordinateCache = new LongHashMap();
  30.  
  31. /**
  32. * A list of valid keys for the destinationCoordainteCache. These are based
  33. * on the X & Z of the players initial location.
  34. */
  35. private final List destinationCoordinateKeys = new ArrayList();
  36.  
  37. public TeleporterMoon(WorldServer par1WorldServer) {
  38. super(par1WorldServer);
  39. this.worldServerInstance = par1WorldServer;
  40. this.random = new Random(par1WorldServer.getSeed());
  41. }
  42.  
  43. /**
  44. * Place an entity in a nearby portal, creating one if necessary.
  45. */
  46. @Override
  47. public void placeInPortal(Entity par1Entity, double par2, double par4, double par6, float par8) {
  48. world = par1Entity.worldObj;
  49. if (this.worldServerInstance.provider.dimensionId != 1) {
  50. if (!this.placeInExistingPortal(par1Entity, par2, par4, par6, par8)) {
  51. this.makePortal(par1Entity);
  52. this.placeInExistingPortal(par1Entity, par2, par4, par6, par8);
  53. }
  54. } else {
  55. int i = MathHelper.floor_double(par1Entity.posX);
  56. int j = MathHelper.floor_double(par1Entity.posY) - 1;
  57. int k = MathHelper.floor_double(par1Entity.posZ);
  58. byte b0 = 1;
  59. byte b1 = 0;
  60.  
  61. for (int l = -2; l <= 2; ++l) {
  62. for (int i1 = -2; i1 <= 2; ++i1) {
  63. for (int j1 = -1; j1 < 3; ++j1) {
  64. int k1 = i + i1 * b0 + l * b1;
  65. int l1 = j + j1;
  66. int i2 = k + i1 * b1 - l * b0;
  67. boolean flag = j1 < 0;
  68. this.worldServerInstance.setBlock(k1, l1, i2, flag ? Block.obsidian.blockID : 0);
  69. }
  70. }
  71. }
  72.  
  73. par1Entity.setLocationAndAngles((double) i, (double) j, (double) k, par1Entity.rotationYaw, 0.0F);
  74. par1Entity.motionX = par1Entity.motionY = par1Entity.motionZ = 0.0D;
  75. }
  76. }
  77.  
  78. /**
  79. * Place an entity in a nearby portal which already exists.
  80. */
  81. @Override
  82. public boolean placeInExistingPortal(Entity par1Entity, double par2, double par4, double par6, float par8) {
  83. short short1 = 128;
  84. double d3 = -1.0D;
  85. int i = 0;
  86. int j = 0;
  87. int k = 0;
  88. int l = MathHelper.floor_double(par1Entity.posX);
  89. int i1 = MathHelper.floor_double(par1Entity.posZ);
  90. long j1 = ChunkCoordIntPair.chunkXZ2Int(l, i1);
  91. boolean flag = true;
  92. double d4;
  93. int k1;
  94.  
  95. if (this.destinationCoordinateCache.containsItem(j1)) {
  96. PortalPosition portalposition = (PortalPosition) this.destinationCoordinateCache.getValueByKey(j1);
  97. d3 = 0.0D;
  98. i = portalposition.posX;
  99. j = portalposition.posY;
  100. k = portalposition.posZ;
  101. portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime();
  102. flag = false;
  103. } else {
  104. for (k1 = l - short1; k1 <= l + short1; ++k1) {
  105. double d5 = (double) k1 + 0.5D - par1Entity.posX;
  106.  
  107. for (int l1 = i1 - short1; l1 <= i1 + short1; ++l1) {
  108. double d6 = (double) l1 + 0.5D - par1Entity.posZ;
  109.  
  110. for (int i2 = this.worldServerInstance.getActualHeight() - 1; i2 >= 0; --i2) {
  111. if (this.worldServerInstance.getBlockId(k1, i2, l1) == Block.portal.blockID) {
  112. while (this.worldServerInstance.getBlockId(k1, i2 - 1, l1) == Block.portal.blockID) {
  113. --i2;
  114. }
  115.  
  116. d4 = (double) i2 + 0.5D - par1Entity.posY;
  117. double d7 = d5 * d5 + d4 * d4 + d6 * d6;
  118.  
  119. if (d3 < 0.0D || d7 < d3) {
  120. d3 = d7;
  121. i = k1;
  122. j = i2;
  123. k = l1;
  124. }
  125. }
  126. }
  127. }
  128. }
  129. }
  130.  
  131. if (d3 >= 0.0D) {
  132. if (flag) {
  133. this.destinationCoordinateCache.add(j1, new PortalPosition(this, i, j, k, this.worldServerInstance.getTotalWorldTime()));
  134. this.destinationCoordinateKeys.add(Long.valueOf(j1));
  135. }
  136.  
  137. double d8 = (double) i + 0.5D;
  138. double d9 = (double) j + 0.5D;
  139. d4 = (double) k + 0.5D;
  140. int j2 = -1;
  141.  
  142.  
  143. int k2 = par1Entity.getTeleportDirection();
  144.  
  145. if (j2 > -1) {
  146. int l2 = Direction.rotateLeft[j2];
  147. int i3 = Direction.offsetX[j2];
  148. int j3 = Direction.offsetZ[j2];
  149. int k3 = Direction.offsetX[l2];
  150. int l3 = Direction.offsetZ[l2];
  151. boolean flag1 = !this.worldServerInstance.isAirBlock(i + i3 + k3, j, k + j3 + l3) || !this.worldServerInstance.isAirBlock(i + i3 + k3, j + 1, k + j3 + l3);
  152. boolean flag2 = !this.worldServerInstance.isAirBlock(i + i3, j, k + j3) || !this.worldServerInstance.isAirBlock(i + i3, j + 1, k + j3);
  153.  
  154. if (flag1 && flag2) {
  155. j2 = Direction.rotateOpposite[j2];
  156. l2 = Direction.rotateOpposite[l2];
  157. i3 = Direction.offsetX[j2];
  158. j3 = Direction.offsetZ[j2];
  159. k3 = Direction.offsetX[l2];
  160. l3 = Direction.offsetZ[l2];
  161. k1 = i - k3;
  162. d8 -= (double) k3;
  163. int i4 = k - l3;
  164. d4 -= (double) l3;
  165. flag1 = !this.worldServerInstance.isAirBlock(k1 + i3 + k3, j, i4 + j3 + l3) || !this.worldServerInstance.isAirBlock(k1 + i3 + k3, j + 1, i4 + j3 + l3);
  166. flag2 = !this.worldServerInstance.isAirBlock(k1 + i3, j, i4 + j3) || !this.worldServerInstance.isAirBlock(k1 + i3, j + 1, i4 + j3);
  167. }
  168.  
  169. float f1 = 0.5F;
  170. float f2 = 0.5F;
  171.  
  172. if (!flag1 && flag2) {
  173. f1 = 1.0F;
  174. } else if (flag1 && !flag2) {
  175. f1 = 0.0F;
  176. } else if (flag1 && flag2) {
  177. f2 = 0.0F;
  178. }
  179.  
  180. d8 += (double) ((float) k3 * f1 + f2 * (float) i3);
  181. d4 += (double) ((float) l3 * f1 + f2 * (float) j3);
  182. float f3 = 0.0F;
  183. float f4 = 0.0F;
  184. float f5 = 0.0F;
  185. float f6 = 0.0F;
  186.  
  187. if (j2 == k2) {
  188. f3 = 1.0F;
  189. f4 = 1.0F;
  190. } else if (j2 == Direction.rotateOpposite[k2]) {
  191. f3 = -1.0F;
  192. f4 = -1.0F;
  193. } else if (j2 == Direction.rotateRight[k2]) {
  194. f5 = 1.0F;
  195. f6 = -1.0F;
  196. } else {
  197. f5 = -1.0F;
  198. f6 = 1.0F;
  199. }
  200.  
  201. double d10 = par1Entity.motionX;
  202. double d11 = par1Entity.motionZ;
  203. par1Entity.motionX = d10 * (double) f3 + d11 * (double) f6;
  204. par1Entity.motionZ = d10 * (double) f5 + d11 * (double) f4;
  205. par1Entity.rotationYaw = par8 - (float) (k2 * 90) + (float) (j2 * 90);
  206. } else {
  207. par1Entity.motionX = par1Entity.motionY = par1Entity.motionZ = 0.0D;
  208. }
  209.  
  210. par1Entity.setLocationAndAngles(d8, d9, d4, par1Entity.rotationYaw, par1Entity.rotationPitch);
  211. return true;
  212. } else {
  213. return false;
  214. }
  215. }
  216.  
  217. @Override
  218. public boolean makePortal(Entity par1Entity) {
  219. World world1 = par1Entity.worldObj;
  220. int i = MathHelper.floor_double(par1Entity.posX) - 3;
  221. int j = MathHelper.floor_double(par1Entity.posY) - 1;
  222. int k = MathHelper.floor_double(par1Entity.posZ) - 7;
  223. System.out.println("" + i +" "+ j +" "+ k);
  224. shipGen.generate(world1, rand, i, j, k);
  225. System.out.println("Generated!");
  226. return true;
  227. }
  228.  
  229. /**
  230. * called periodically to remove out-of-date portal locations from the cache
  231. * list. Argument par1 is a WorldServer.getTotalWorldTime() value.
  232. */
  233. public void removeStalePortalLocations(long par1) {
  234. if (par1 % 100L == 0L) {
  235. Iterator iterator = this.destinationCoordinateKeys.iterator();
  236. long j = par1 - 600L;
  237.  
  238. while (iterator.hasNext()) {
  239. Long olong = (Long) iterator.next();
  240. PortalPosition portalposition = (PortalPosition) this.destinationCoordinateCache.getValueByKey(olong.longValue());
  241.  
  242. if (portalposition == null || portalposition.lastUpdateTime < j) {
  243. iterator.remove();
  244. this.destinationCoordinateCache.remove(olong.longValue());
  245. }
  246. }
  247. }
  248. }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement