Advertisement
Guest User

BlockScreen class

a guest
Dec 11th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. package dk.adventures.AdvScreen.Blocks;
  2.  
  3.  
  4. import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
  5. import dk.adventures.AdvScreen.Constants.RenderIDs;
  6. import dk.adventures.AdvScreen.TileEntity.TileEntityScreen;
  7. import dk.adventures.AdvScreen.Utils.Logger;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.client.renderer.RenderBlocks;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.tileentity.TileEntity;
  16. import net.minecraft.util.MathHelper;
  17. import net.minecraft.world.IBlockAccess;
  18. import net.minecraft.world.World;
  19.  
  20.  
  21. public class BlockScreen extends BlockBaseContainer
  22. {
  23. public BlockScreen()
  24. {
  25. super("BlockScreen", Material.rock);
  26. }
  27.  
  28. @Override
  29. public TileEntity createNewTileEntity(World world, int meta)
  30. {
  31. return new TileEntityScreen();
  32. }
  33.  
  34. @Override
  35. public int colorMultiplier(IBlockAccess par1, int x, int y, int z)
  36. {
  37. return 0x00ff00; // Integer.parseInt("ffffff", 16);
  38. }
  39.  
  40. @Override
  41. public boolean isOpaqueCube()
  42. {
  43. return false;
  44. }
  45.  
  46. @Override
  47. public boolean renderAsNormalBlock()
  48. {
  49. return false;
  50. }
  51.  
  52. @Override
  53. public int getRenderType()
  54. {
  55. return RenderIDs.Screen;
  56. }
  57.  
  58.  
  59. @Override
  60. public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
  61. {
  62. super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack); //not needed Pahimar eh? ;)
  63.  
  64. world.setBlockMetadataWithNotify(x, y, z, 1, 2);
  65.  
  66. if (world.getTileEntity(x,y,z) instanceof TileEntityScreen)
  67. {
  68. int iOrientation = determineOrientation(world, x, y, z, entityLiving);
  69.  
  70.  
  71.  
  72. ((TileEntityScreen)world.getTileEntity(x,y,z)).Orientation = iOrientation;
  73.  
  74. if (!world.isRemote)
  75. Minecraft.getMinecraft().thePlayer.sendChatMessage(String.format("Orientation: %d", iOrientation));
  76. }
  77. }
  78.  
  79.  
  80. public static int determineOrientation(World world, int x, int y, int z, EntityLivingBase entityLiving)
  81. {
  82. int iOrientation = 0; //0=north, 1=east, 2=south, 3=west, 4,5,6,7=Up/NESW, 8,9,10,11=Down/NESW
  83. int iUpDown = 0;
  84.  
  85. if (MathHelper.abs((float) entityLiving.posX - (float) x) < 2.0F && MathHelper.abs((float)entityLiving.posZ - (float)z) < 2.0F)
  86. {
  87. double d0 = entityLiving.posY + 1.82D - (double)entityLiving.yOffset;
  88.  
  89. if (d0 - (double)y > 2.0D)
  90. {
  91. iUpDown = 4;
  92. }
  93.  
  94. if ((double)y - d0 > 0.0D)
  95. {
  96. iUpDown = 8;
  97. }
  98. }
  99.  
  100. int l = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  101. iOrientation = l + iUpDown;
  102.  
  103. return iOrientation;
  104. }
  105.  
  106. @Override
  107. public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
  108. {
  109. //setBlockBounds(0.0f, 0.0f, 0.9f, 1.0f, 1.0f, 1.0f);
  110. int meta = world.getBlockMetadata(x, y, z);
  111.  
  112. // if (meta == 0) //hack test to render block correctly in inventory
  113. // return;
  114.  
  115. setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
  116.  
  117. TileEntity ent = world.getTileEntity(x,y,z);
  118.  
  119. if (ent instanceof TileEntityScreen)
  120. {
  121. int iOri = ((TileEntityScreen)ent).Orientation;
  122. float fDepth = ((TileEntityScreen)ent).Depth;
  123.  
  124. switch (iOri)
  125. {
  126. case 0:
  127. setBlockBounds(0.0f, 0.0f, 1.0f-fDepth, 1.0f, 1.0f, 1.0f);
  128. break;
  129.  
  130. default:
  131. break;
  132. }
  133. }
  134. }
  135.  
  136. @Override
  137. public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float faceX, float faceY, float faceZ)
  138. {
  139. if (!world.isRemote && player.getHeldItem() == null && !player.isSneaking())
  140. {
  141. Logger.Info(String.format("onBlockActivated (%d,%d,%d)", x, y, z));
  142. //world.setBlockMetadataWithNotify(x, y, z, 1, 3);
  143. //this.setLightLevel(15);
  144.  
  145. TileEntity te = world.getTileEntity(x,y,z);
  146.  
  147. if (te instanceof TileEntityScreen)
  148. {
  149. TileEntityScreen screen = (TileEntityScreen)te;
  150. float fDepth = screen.Depth;
  151.  
  152. fDepth = fDepth-0.1f < 0.1f ? 1.0f : fDepth-0.1f;
  153.  
  154. screen.Depth = fDepth;
  155. setBlockBoundsBasedOnState(world, x, y, z);
  156. world.markBlockForUpdate(x, y, z);
  157. }
  158.  
  159. return true;
  160. }
  161. else
  162. return false;
  163. }
  164.  
  165.  
  166. }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement