Guest User

Untitled

a guest
Nov 9th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.01 KB | None | 0 0
  1. package tutorial.generic;
  2.  
  3. import cpw.mods.fml.common.network.NetworkRegistry;
  4. import cpw.mods.fml.relauncher.Side;
  5. import cpw.mods.fml.relauncher.SideOnly;
  6.  
  7. import java.util.Random;
  8.  
  9. import net.minecraft.block.Block;
  10. import net.minecraft.block.BlockContainer;
  11. import net.minecraft.block.BlockFurnace;
  12. import net.minecraft.block.material.Material;
  13. import net.minecraft.client.renderer.texture.IIconRegister;
  14. import net.minecraft.entity.EntityLivingBase;
  15. import net.minecraft.entity.item.EntityItem;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.init.Blocks;
  18. import net.minecraft.inventory.Container;
  19. import net.minecraft.inventory.IInventory;
  20. import net.minecraft.item.Item;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.nbt.NBTTagCompound;
  23. import net.minecraft.tileentity.TileEntity;
  24. import net.minecraft.tileentity.TileEntityFurnace;
  25. import tutorial.generic.TileEntityEnderFurnace;
  26. import net.minecraft.util.IIcon;
  27. import net.minecraft.util.MathHelper;
  28. import net.minecraft.world.World;
  29.  
  30. public class EnderFurnace extends BlockContainer {
  31. private final Random field_149933_a = new Random();
  32. private final boolean field_149932_b;
  33. private static boolean field_149934_M;
  34. @SideOnly(Side.CLIENT)
  35. private IIcon field_149935_N;
  36.  
  37. @SideOnly(Side.CLIENT)
  38. private IIcon field_149936_O;
  39. private static final String __OBFID = "CL_00000249";
  40.  
  41. protected EnderFurnace(boolean p_i45407_1_)
  42.  
  43. {
  44. super(Material.rock);
  45. this.field_149932_b = p_i45407_1_;
  46. }
  47.  
  48. public Item getItemDropped(int p_149650_1_, Random p_149650_2_,
  49. int p_149650_3_) {
  50. return Item.getItemFromBlock(Generic.enderFurnaceUnlit);
  51. }
  52.  
  53. /**
  54. * Called whenever the block is added into the world. Args: world, x, y, z
  55. */
  56. public void onBlockAdded(World p_149726_1_, int p_149726_2_,
  57. int p_149726_3_, int p_149726_4_) {
  58. super.onBlockAdded(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_);
  59. this.func_149930_e(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_);
  60. }
  61.  
  62. private void func_149930_e(World p_149930_1_, int p_149930_2_,
  63. int p_149930_3_, int p_149930_4_) {
  64. if (!p_149930_1_.isRemote) {
  65. Block block = p_149930_1_.getBlock(p_149930_2_, p_149930_3_,
  66. p_149930_4_ - 1);
  67. Block block1 = p_149930_1_.getBlock(p_149930_2_, p_149930_3_,
  68. p_149930_4_ + 1);
  69. Block block2 = p_149930_1_.getBlock(p_149930_2_ - 1, p_149930_3_,
  70. p_149930_4_);
  71. Block block3 = p_149930_1_.getBlock(p_149930_2_ + 1, p_149930_3_,
  72. p_149930_4_);
  73. byte b0 = 3;
  74.  
  75. if (block.func_149730_j() && !block1.func_149730_j()) {
  76. b0 = 3;
  77. }
  78.  
  79. if (block1.func_149730_j() && !block.func_149730_j()) {
  80. b0 = 2;
  81. }
  82.  
  83. if (block2.func_149730_j() && !block3.func_149730_j()) {
  84. b0 = 5;
  85. }
  86.  
  87. if (block3.func_149730_j() && !block2.func_149730_j()) {
  88. b0 = 4;
  89. }
  90.  
  91. p_149930_1_.setBlockMetadataWithNotify(p_149930_2_, p_149930_3_,
  92. p_149930_4_, b0, 2);
  93. }
  94. }
  95.  
  96. /**
  97. * Gets the block's texture. Args: side, meta
  98. */
  99. @SideOnly(Side.CLIENT)
  100. public IIcon getIcon(int p_149691_1_, int p_149691_2_) {
  101. return p_149691_1_ == 1 ? this.field_149935_N
  102. : (p_149691_1_ == 0 ? this.field_149935_N
  103. : (p_149691_1_ != p_149691_2_ ? this.blockIcon
  104. : this.field_149936_O));
  105. }
  106.  
  107. @SideOnly(Side.CLIENT)
  108. public void registerBlockIcons(IIconRegister p_149651_1_) {
  109. this.blockIcon = p_149651_1_.registerIcon("endermod:furnace_side");
  110. this.field_149936_O = p_149651_1_
  111. .registerIcon(this.field_149932_b ? "endermod:furnace_front_on"
  112. : "endermod:furnace_front_off");
  113. this.field_149935_N = p_149651_1_.registerIcon("endermod:furnace_top");
  114. }
  115.  
  116. /**
  117. * Called upon block activation (right click on the block.)
  118. */
  119. public boolean onBlockActivated(World world, int x, int y, int z,
  120. EntityPlayer player, int p_149727_6_, float p_149727_7_,
  121. float p_149727_8_, float p_149727_9_) {
  122.  
  123. if (world.isRemote) {
  124. return true;
  125. } else {
  126.  
  127. TileEntityEnderFurnace TileEntityEnderFurnace = (TileEntityEnderFurnace) world
  128. .getTileEntity(x, y, z);
  129.  
  130. if (TileEntityEnderFurnace != null) {
  131. // player.func_146101_a(TileEntityEnderFurnace);
  132. player.openGui(Generic.instance, 0, world, x, y, z);
  133. }
  134.  
  135. return true;
  136. }
  137.  
  138. }
  139.  
  140. /**
  141. * Update which block the furnace is using depending on whether or not it is
  142. * burning
  143. */
  144. public static void updateFurnaceBlockState(boolean p_149931_0_,
  145. World p_149931_1_, int p_149931_2_, int p_149931_3_, int p_149931_4_) {
  146. int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_,
  147. p_149931_4_);
  148. TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_,
  149. p_149931_3_, p_149931_4_);
  150. field_149934_M = true;
  151.  
  152. if (p_149931_0_) {
  153. p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_,
  154. Generic.enderFurnaceLit);
  155. } else {
  156. p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_,
  157. Generic.enderFurnaceUnlit);
  158. }
  159.  
  160. field_149934_M = false;
  161. p_149931_1_.setBlockMetadataWithNotify(p_149931_2_, p_149931_3_,
  162. p_149931_4_, l, 2);
  163.  
  164. if (tileentity != null) {
  165. tileentity.validate();
  166. p_149931_1_.setTileEntity(p_149931_2_, p_149931_3_, p_149931_4_,
  167. tileentity);
  168. }
  169. }
  170.  
  171. /**
  172. * Returns a new instance of a block's tile entity class. Called on placing
  173. * the block.
  174. */
  175. public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
  176. return new TileEntityEnderFurnace();
  177. }
  178.  
  179. /**
  180. * Called when the block is placed in the world.
  181. */
  182. public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_,
  183. int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_,
  184. ItemStack p_149689_6_) {
  185. int l = MathHelper
  186. .floor_double((double) (p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  187.  
  188. if (l == 0) {
  189. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_,
  190. p_149689_4_, 2, 2);
  191. }
  192.  
  193. if (l == 1) {
  194. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_,
  195. p_149689_4_, 5, 2);
  196. }
  197.  
  198. if (l == 2) {
  199. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_,
  200. p_149689_4_, 3, 2);
  201. }
  202.  
  203. if (l == 3) {
  204. p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_,
  205. p_149689_4_, 4, 2);
  206. }
  207.  
  208. if (p_149689_6_.hasDisplayName()) {
  209. ((TileEntityEnderFurnace) p_149689_1_.getTileEntity(p_149689_2_,
  210. p_149689_3_, p_149689_4_)).func_145951_a(p_149689_6_
  211. .getDisplayName());
  212. }
  213. }
  214.  
  215. public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_,
  216. int p_149749_4_, Block p_149749_5_, int p_149749_6_) {
  217. if (!field_149934_M) {
  218. TileEntityEnderFurnace TileEntityEnderFurnace = (TileEntityEnderFurnace) p_149749_1_
  219. .getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
  220.  
  221. if (TileEntityEnderFurnace != null) {
  222. for (int i1 = 0; i1 < TileEntityEnderFurnace.getSizeInventory(); ++i1) {
  223. ItemStack itemstack = TileEntityEnderFurnace
  224. .getStackInSlot(i1);
  225.  
  226. if (itemstack != null) {
  227. float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
  228. float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
  229. float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
  230.  
  231. while (itemstack.stackSize > 0) {
  232. int j1 = this.field_149933_a.nextInt(21) + 10;
  233.  
  234. if (j1 > itemstack.stackSize) {
  235. j1 = itemstack.stackSize;
  236. }
  237.  
  238. itemstack.stackSize -= j1;
  239. EntityItem entityitem = new EntityItem(p_149749_1_,
  240. (double) ((float) p_149749_2_ + f),
  241. (double) ((float) p_149749_3_ + f1),
  242. (double) ((float) p_149749_4_ + f2),
  243. new ItemStack(itemstack.getItem(), j1,
  244. itemstack.getItemDamage()));
  245.  
  246. if (itemstack.hasTagCompound()) {
  247. entityitem.getEntityItem().setTagCompound(
  248. (NBTTagCompound) itemstack
  249. .getTagCompound().copy());
  250. }
  251.  
  252. float f3 = 0.05F;
  253. entityitem.motionX = (double) ((float) this.field_149933_a
  254. .nextGaussian() * f3);
  255. entityitem.motionY = (double) ((float) this.field_149933_a
  256. .nextGaussian() * f3 + 0.2F);
  257. entityitem.motionZ = (double) ((float) this.field_149933_a
  258. .nextGaussian() * f3);
  259. p_149749_1_.spawnEntityInWorld(entityitem);
  260. }
  261. }
  262. }
  263.  
  264. p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_,
  265. p_149749_4_, p_149749_5_);
  266. }
  267. }
  268.  
  269. super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_,
  270. p_149749_5_, p_149749_6_);
  271. }
  272.  
  273. /**
  274. * A randomly called display update to be able to add particles or other
  275. * items for display
  276. */
  277. @SideOnly(Side.CLIENT)
  278. public void randomDisplayTick(World p_149734_1_, int p_149734_2_,
  279. int p_149734_3_, int p_149734_4_, Random p_149734_5_) {
  280. if (this.field_149932_b) {
  281. int l = p_149734_1_.getBlockMetadata(p_149734_2_, p_149734_3_,
  282. p_149734_4_);
  283. float f = (float) p_149734_2_ + 0.5F;
  284. float f1 = (float) p_149734_3_ + 0.0F + p_149734_5_.nextFloat()
  285. * 6.0F / 16.0F;
  286. float f2 = (float) p_149734_4_ + 0.5F;
  287. float f3 = 0.52F;
  288. float f4 = p_149734_5_.nextFloat() * 0.6F - 0.3F;
  289.  
  290. if (l == 4) {
  291. p_149734_1_.spawnParticle("smoke", (double) (f - f3),
  292. (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
  293. p_149734_1_.spawnParticle("flame", (double) (f - f3),
  294. (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
  295. } else if (l == 5) {
  296. p_149734_1_.spawnParticle("smoke", (double) (f + f3),
  297. (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
  298. p_149734_1_.spawnParticle("flame", (double) (f + f3),
  299. (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
  300. } else if (l == 2) {
  301. p_149734_1_.spawnParticle("smoke", (double) (f + f4),
  302. (double) f1, (double) (f2 - f3), 0.0D, 0.0D, 0.0D);
  303. p_149734_1_.spawnParticle("flame", (double) (f + f4),
  304. (double) f1, (double) (f2 - f3), 0.0D, 0.0D, 0.0D);
  305. } else if (l == 3) {
  306. p_149734_1_.spawnParticle("smoke", (double) (f + f4),
  307. (double) f1, (double) (f2 + f3), 0.0D, 0.0D, 0.0D);
  308. p_149734_1_.spawnParticle("flame", (double) (f + f4),
  309. (double) f1, (double) (f2 + f3), 0.0D, 0.0D, 0.0D);
  310. }
  311. }
  312. }
  313.  
  314. /**
  315. * If this returns true, then comparators facing away from this block will
  316. * use the value from getComparatorInputOverride instead of the actual
  317. * redstone signal strength.
  318. */
  319. public boolean hasComparatorInputOverride() {
  320. return true;
  321. }
  322.  
  323. /**
  324. * If hasComparatorInputOverride returns true, the return value from this is
  325. * used instead of the redstone signal strength when this block inputs to a
  326. * comparator.
  327. */
  328. public int getComparatorInputOverride(World p_149736_1_, int p_149736_2_,
  329. int p_149736_3_, int p_149736_4_, int p_149736_5_) {
  330. return Container.calcRedstoneFromInventory((IInventory) p_149736_1_
  331. .getTileEntity(p_149736_2_, p_149736_3_, p_149736_4_));
  332. }
  333.  
  334. /**
  335. * Gets an item for the block being called on. Args: world, x, y, z
  336. */
  337. @SideOnly(Side.CLIENT)
  338. public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_,
  339. int p_149694_4_) {
  340. return Item.getItemFromBlock(Generic.enderFurnaceUnlit);
  341. }
  342. }
Advertisement
Add Comment
Please, Sign In to add comment