Advertisement
Guest User

BlockBlueBed.java

a guest
Dec 17th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.55 KB | None | 0 0
  1. package com.living.mod.beds;
  2.  
  3. import java.util.Iterator;
  4. import java.util.Random;
  5.  
  6. import com.living.mod.Debugger;
  7. import com.living.mod.Living;
  8.  
  9. import net.minecraft.block.Block;
  10. import net.minecraft.block.BlockDirectional;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.client.renderer.texture.IIconRegister;
  13. import net.minecraft.entity.Entity;
  14. import net.minecraft.entity.player.EntityPlayer;
  15. import net.minecraft.init.Blocks;
  16. import net.minecraft.init.Items;
  17. import net.minecraft.item.Item;
  18. import net.minecraft.util.ChatComponentTranslation;
  19. import net.minecraft.util.ChunkCoordinates;
  20. import net.minecraft.util.Direction;
  21. import net.minecraft.util.IIcon;
  22. import net.minecraft.world.IBlockAccess;
  23. import net.minecraft.world.World;
  24. import net.minecraft.world.biome.BiomeGenBase;
  25. import cpw.mods.fml.relauncher.Side;
  26. import cpw.mods.fml.relauncher.SideOnly;
  27.  
  28. public class BlockBlueBed extends BlockDirectional
  29. {
  30. public static final int[][] field_149981_a = new int[][] {{0, 1}, { -1, 0}, {0, -1}, {1, 0}};
  31. @SideOnly(Side.CLIENT)
  32. private IIcon[] field_149980_b;
  33. @SideOnly(Side.CLIENT)
  34. private IIcon[] field_149982_M;
  35. @SideOnly(Side.CLIENT)
  36. private IIcon[] field_149983_N;
  37. private static final String __OBFID = "CL_00000198";
  38.  
  39. public BlockBlueBed()
  40. {
  41. super(Material.cloth);
  42. this.func_149978_e();
  43. }
  44.  
  45. /**
  46. * Called upon block activation (right click on the block.)
  47. */
  48. public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
  49. {
  50. if (world.isRemote)
  51. {
  52. return true;
  53. }
  54. else
  55. {
  56. int i1 = world.getBlockMetadata(i, j, k);
  57.  
  58. if (!isBlockHeadOfBed(i1))
  59. {
  60. int j1 = getDirection(i1);
  61. i += field_149981_a[j1][0];
  62. k += field_149981_a[j1][1];
  63.  
  64. if (world.getBlock(i, j, k) != this)
  65. {
  66. return true;
  67. }
  68.  
  69. i1 = world.getBlockMetadata(i, j, k);
  70. }
  71.  
  72. if (world.provider.canRespawnHere() && world.getBiomeGenForCoords(i, k) != BiomeGenBase.hell)
  73. {
  74. if (func_149976_c(i1))
  75. {
  76. EntityPlayer entityplayer1 = null;
  77. Iterator iterator = world.playerEntities.iterator();
  78.  
  79. while (iterator.hasNext())
  80. {
  81. EntityPlayer entityplayer2 = (EntityPlayer)iterator.next();
  82.  
  83. if (entityplayer2.isPlayerSleeping())
  84. {
  85. ChunkCoordinates chunkcoordinates = entityplayer2.playerLocation;
  86.  
  87. if (chunkcoordinates.posX == i && chunkcoordinates.posY == j && chunkcoordinates.posZ == k)
  88. {
  89. entityplayer1 = entityplayer2;
  90. }
  91. }
  92. }
  93.  
  94. if (entityplayer1 != null)
  95. {
  96. player.addChatComponentMessage(new ChatComponentTranslation("tile.bluebed.occupied", new Object[0]));
  97. return true;
  98. }
  99.  
  100. func_149979_a(world, i, j, k, false);
  101. }
  102.  
  103. EntityPlayer.EnumStatus enumstatus = player.sleepInBedAt(i, j, k);
  104.  
  105. if (enumstatus == EntityPlayer.EnumStatus.OK)
  106. {
  107. func_149979_a(world, i, j, k, true);
  108. return true;
  109. }
  110. else
  111. {
  112. if (enumstatus == EntityPlayer.EnumStatus.NOT_POSSIBLE_NOW)
  113. {
  114. player.addChatComponentMessage(new ChatComponentTranslation("tile.bluebed.noSleep", new Object[0]));
  115. }
  116. else if (enumstatus == EntityPlayer.EnumStatus.NOT_SAFE)
  117. {
  118. player.addChatComponentMessage(new ChatComponentTranslation("tile.bluebed.notSafe", new Object[0]));
  119. }
  120.  
  121. return true;
  122. }
  123. }
  124. else
  125. {
  126. double d2 = (double)i + 0.5D;
  127. double d0 = (double)j + 0.5D;
  128. double d1 = (double)k + 0.5D;
  129. world.setBlockToAir(i, j, k);
  130. int k1 = getDirection(i1);
  131. i += field_149981_a[k1][0];
  132. k += field_149981_a[k1][1];
  133.  
  134. if (world.getBlock(i, j, k) == this)
  135. {
  136. world.setBlockToAir(i, j, k);
  137. d2 = (d2 + (double)i + 0.5D) / 2.0D;
  138. d0 = (d0 + (double)j + 0.5D) / 2.0D;
  139. d1 = (d1 + (double)k + 0.5D) / 2.0D;
  140. }
  141.  
  142. world.newExplosion((Entity)null, (double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), 5.0F, true, true);
  143. return true;
  144. }
  145. }
  146. }
  147.  
  148. /**
  149. * Gets the block's texture. Args: side, meta
  150. */
  151. @SideOnly(Side.CLIENT)
  152. public IIcon getIcon(int p_149691_1_, int p_149691_2_)
  153. {
  154. if (p_149691_1_ == 0)
  155. {
  156. return Blocks.planks.getBlockTextureFromSide(p_149691_1_);
  157. }
  158. else
  159. {
  160. int k = getDirection(p_149691_2_);
  161. int l = Direction.bedDirection[k][p_149691_1_];
  162. int i1 = isBlockHeadOfBed(p_149691_2_) ? 1 : 0;
  163. return (i1 != 1 || l != 2) && (i1 != 0 || l != 3) ? (l != 5 && l != 4 ? this.field_149983_N[i1] : this.field_149982_M[i1]) : this.field_149980_b[i1];
  164. }
  165. }
  166.  
  167. @SideOnly(Side.CLIENT)
  168. public void registerBlockIcons(IIconRegister p_149651_1_)
  169. {
  170. this.field_149983_N = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_Feet_Top"), p_149651_1_.registerIcon(this.getTextureName() + "_Head_Top")};
  171. this.field_149980_b = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_Feet_End"), p_149651_1_.registerIcon(this.getTextureName() + "_Head_End")};
  172. this.field_149982_M = new IIcon[] {p_149651_1_.registerIcon(this.getTextureName() + "_Feet_Side"), p_149651_1_.registerIcon(this.getTextureName() + "_Head_Side")};
  173. }
  174.  
  175. /**
  176. * The type of render function that is called for this block
  177. */
  178. public int getRenderType()
  179. {
  180. return 14;
  181. }
  182.  
  183. /**
  184. * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  185. */
  186. public boolean renderAsNormalBlock()
  187. {
  188. return false;
  189. }
  190.  
  191. /**
  192. * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
  193. * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  194. */
  195. public boolean isOpaqueCube()
  196. {
  197. return false;
  198. }
  199.  
  200. /**
  201. * Updates the blocks bounds based on its current state. Args: world, x, y, z
  202. */
  203. public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_)
  204. {
  205. this.func_149978_e();
  206. }
  207.  
  208. /**
  209. * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  210. * their own) Args: x, y, z, neighbor Block
  211. */
  212. public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
  213. {
  214. int l = p_149695_1_.getBlockMetadata(p_149695_2_, p_149695_3_, p_149695_4_);
  215. int i1 = getDirection(l);
  216.  
  217. if (isBlockHeadOfBed(l))
  218. {
  219. if (p_149695_1_.getBlock(p_149695_2_ - field_149981_a[i1][0], p_149695_3_, p_149695_4_ - field_149981_a[i1][1]) != this)
  220. {
  221. p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_);
  222. }
  223. }
  224. else if (p_149695_1_.getBlock(p_149695_2_ + field_149981_a[i1][0], p_149695_3_, p_149695_4_ + field_149981_a[i1][1]) != this)
  225. {
  226. p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_);
  227.  
  228. if (!p_149695_1_.isRemote)
  229. {
  230. this.dropBlockAsItem(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, l, 0);
  231. }
  232. }
  233. }
  234.  
  235. public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
  236. {
  237. /**
  238. * Returns whether or not this bed block is the head of the bed.
  239. */
  240. return isBlockHeadOfBed(p_149650_1_) ? Item.getItemById(0) : Living.itemBlueBed;
  241. }
  242.  
  243. private void func_149978_e()
  244. {
  245. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5625F, 1.0F);
  246. }
  247.  
  248. /**
  249. * Returns whether or not this bed block is the head of the bed.
  250. */
  251. public static boolean isBlockHeadOfBed(int p_149975_0_)
  252. {
  253. return (p_149975_0_ & 8) != 0;
  254. }
  255.  
  256. public static boolean func_149976_c(int p_149976_0_)
  257. {
  258. return (p_149976_0_ & 4) != 0;
  259. }
  260.  
  261. public static void func_149979_a(World p_149979_0_, int p_149979_1_, int p_149979_2_, int p_149979_3_, boolean p_149979_4_)
  262. {
  263. int l = p_149979_0_.getBlockMetadata(p_149979_1_, p_149979_2_, p_149979_3_);
  264.  
  265. if (p_149979_4_)
  266. {
  267. l |= 4;
  268. }
  269. else
  270. {
  271. l &= -5;
  272. }
  273.  
  274. p_149979_0_.setBlockMetadataWithNotify(p_149979_1_, p_149979_2_, p_149979_3_, l, 4);
  275. }
  276.  
  277. public static ChunkCoordinates func_149977_a(World p_149977_0_, int p_149977_1_, int p_149977_2_, int p_149977_3_, int p_149977_4_)
  278. {
  279. int i1 = p_149977_0_.getBlockMetadata(p_149977_1_, p_149977_2_, p_149977_3_);
  280. int j1 = BlockDirectional.getDirection(i1);
  281.  
  282. for (int k1 = 0; k1 <= 1; ++k1)
  283. {
  284. int l1 = p_149977_1_ - field_149981_a[j1][0] * k1 - 1;
  285. int i2 = p_149977_3_ - field_149981_a[j1][1] * k1 - 1;
  286. int j2 = l1 + 2;
  287. int k2 = i2 + 2;
  288.  
  289. for (int l2 = l1; l2 <= j2; ++l2)
  290. {
  291. for (int i3 = i2; i3 <= k2; ++i3)
  292. {
  293. if (World.doesBlockHaveSolidTopSurface(p_149977_0_, l2, p_149977_2_ - 1, i3) && !p_149977_0_.getBlock(l2, p_149977_2_, i3).getMaterial().isOpaque() && !p_149977_0_.getBlock(l2, p_149977_2_ + 1, i3).getMaterial().isOpaque())
  294. {
  295. if (p_149977_4_ <= 0)
  296. {
  297. return new ChunkCoordinates(l2, p_149977_2_, i3);
  298. }
  299.  
  300. --p_149977_4_;
  301. }
  302. }
  303. }
  304. }
  305.  
  306. return null;
  307. }
  308.  
  309. /**
  310. * Drops the block items with a specified chance of dropping the specified items
  311. */
  312. public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
  313. {
  314. if (!isBlockHeadOfBed(p_149690_5_))
  315. {
  316. super.dropBlockAsItemWithChance(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_6_, 0);
  317. }
  318. }
  319.  
  320. /**
  321. * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility
  322. * and stop pistons
  323. */
  324. public int getMobilityFlag()
  325. {
  326. return 1;
  327. }
  328.  
  329. /**
  330. * Gets an item for the block being called on. Args: world, x, y, z
  331. */
  332. @SideOnly(Side.CLIENT)
  333. public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
  334. {
  335. return Living.itemBlueBed;
  336. }
  337.  
  338. /**
  339. * Called when the block is attempted to be harvested
  340. */
  341. public void onBlockHarvested(World p_149681_1_, int p_149681_2_, int p_149681_3_, int p_149681_4_, int p_149681_5_, EntityPlayer p_149681_6_)
  342. {
  343. if (p_149681_6_.capabilities.isCreativeMode && isBlockHeadOfBed(p_149681_5_))
  344. {
  345. int i1 = getDirection(p_149681_5_);
  346. p_149681_2_ -= field_149981_a[i1][0];
  347. p_149681_4_ -= field_149981_a[i1][1];
  348.  
  349. if (p_149681_1_.getBlock(p_149681_2_, p_149681_3_, p_149681_4_) == this)
  350. {
  351. p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_, p_149681_4_);
  352. }
  353. }
  354. }
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement