Guest User

Untitled

a guest
Apr 21st, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 KB | None | 0 0
  1. package com.TheRPGAdventurer.ROTD.server.blocks;
  2.  
  3. import com.TheRPGAdventurer.ROTD.DragonMounts;
  4. import com.TheRPGAdventurer.ROTD.client.gui.GuiHandler;
  5. import com.TheRPGAdventurer.ROTD.server.blocks.tileentities.TileEntityDragonShulker;
  6. import com.TheRPGAdventurer.ROTD.server.initialization.ModBlocks;
  7. import net.minecraft.block.BlockContainer;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.block.properties.IProperty;
  10. import net.minecraft.block.properties.PropertyDirection;
  11. import net.minecraft.block.properties.PropertyEnum;
  12. import net.minecraft.block.state.BlockFaceShape;
  13. import net.minecraft.block.state.BlockStateContainer;
  14. import net.minecraft.block.state.IBlockState;
  15. import net.minecraft.entity.EntityLivingBase;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.inventory.InventoryHelper;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.tileentity.TileEntity;
  20. import net.minecraft.util.EnumBlockRenderType;
  21. import net.minecraft.util.EnumFacing;
  22. import net.minecraft.util.EnumHand;
  23. import net.minecraft.util.EnumParticleTypes;
  24. import net.minecraft.util.math.AxisAlignedBB;
  25. import net.minecraft.util.math.BlockPos;
  26. import net.minecraft.world.IBlockAccess;
  27. import net.minecraft.world.World;
  28. import net.minecraftforge.fml.relauncher.Side;
  29. import net.minecraftforge.fml.relauncher.SideOnly;
  30.  
  31. import java.util.Random;
  32.  
  33. /**
  34. * Physical Block of the Dragon Core
  35. *
  36. * @author WolfShotz
  37. */
  38.  
  39. public class BlockDragonShulker extends BlockContainer {
  40.  
  41. public static final PropertyEnum<EnumFacing> FACING = PropertyDirection.create("facing");
  42.  
  43. public BlockDragonShulker(String name) {
  44. super(Material.ROCK);
  45. setUnlocalizedName(name);
  46. setRegistryName(name);
  47. setCreativeTab(DragonMounts.mainTab);
  48. setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.UP));
  49. ModBlocks.BLOCKS.add(this);
  50. }
  51.  
  52. public BlockFaceShape getBlockFaceShape(IBlockAccess p_193383_1_, IBlockState p_193383_2_, BlockPos p_193383_3_, EnumFacing p_193383_4_)
  53. {
  54. p_193383_2_ = this.getActualState(p_193383_2_, p_193383_1_, p_193383_3_);
  55. EnumFacing enumfacing = (EnumFacing)p_193383_2_.getValue(FACING);
  56. TileEntityDragonShulker.AnimationStatus tileentityshulkerbox$animationstatus = ((TileEntityDragonShulker)p_193383_1_.getTileEntity(p_193383_3_)).getAnimationStatus();
  57. return tileentityshulkerbox$animationstatus != TileEntityDragonShulker.AnimationStatus.CLOSED && (tileentityshulkerbox$animationstatus != TileEntityDragonShulker.AnimationStatus.OPENED || enumfacing != p_193383_4_.getOpposite() && enumfacing != p_193383_4_) ? BlockFaceShape.UNDEFINED : BlockFaceShape.SOLID;
  58. }
  59.  
  60. // @Override
  61. // public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  62. // if (!worldIn.isRemote) {
  63. // playerIn.openGui(DragonMounts.instance, GuiHandler.GUI_DRAGON_SHULKER, worldIn, pos.getX(), pos.getY(), pos.getZ());
  64. // }
  65. //
  66. // return true;
  67. // }
  68.  
  69. @Override
  70. public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  71. TileEntityDragonShulker tileentity = (TileEntityDragonShulker) worldIn.getTileEntity(pos);
  72. // NOT a normal shulker box. so drop items on ground if destroyed.
  73. InventoryHelper.dropInventoryItems(worldIn, pos, tileentity);
  74. super.breakBlock(worldIn, pos, state);
  75. }
  76.  
  77. @Override
  78. public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
  79. if (stack.hasDisplayName()) {
  80. TileEntity tileentity = worldIn.getTileEntity(pos);
  81.  
  82. if (tileentity instanceof TileEntityDragonShulker) {
  83. ((TileEntityDragonShulker) tileentity).setCustomName(stack.getDisplayName());
  84. }
  85. }
  86. }
  87.  
  88. @Override
  89. public TileEntity createNewTileEntity(World worldIn, int meta) {
  90. return new TileEntityDragonShulker();
  91. }
  92.  
  93. /**
  94. * Called when the block is right clicked by a player.
  95. */
  96. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  97. if (worldIn.isRemote) {
  98. return true;
  99. } else if (playerIn.isSpectator()) {
  100. return true;
  101. } else {
  102. TileEntity tileentity = worldIn.getTileEntity(pos);
  103.  
  104. if (tileentity instanceof TileEntityDragonShulker) {
  105. EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
  106. boolean flag;
  107.  
  108. if (((TileEntityDragonShulker) tileentity).getAnimationStatus() == TileEntityDragonShulker.AnimationStatus.CLOSED) {
  109. AxisAlignedBB axisalignedbb = FULL_BLOCK_AABB.expand((double) (0.5F * (float) enumfacing.getFrontOffsetX()), (double) (0.5F * (float) enumfacing.getFrontOffsetY()), (double) (0.5F * (float) enumfacing.getFrontOffsetZ())).contract((double) enumfacing.getFrontOffsetX(), (double) enumfacing.getFrontOffsetY(), (double) enumfacing.getFrontOffsetZ());
  110. flag = !worldIn.collidesWithAnyBlock(axisalignedbb.offset(pos.offset(enumfacing)));
  111. } else {
  112. flag = true;
  113. }
  114.  
  115. if (flag) {
  116. playerIn.openGui(DragonMounts.instance, GuiHandler.GUI_DRAGON_SHULKER, worldIn, pos.getX(), pos.getY(), pos.getZ());
  117. }
  118.  
  119. return true;
  120. } else {
  121. return false;
  122. }
  123. }
  124. }
  125.  
  126. /**
  127. * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
  128. * IBlockstate
  129. */
  130. public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  131. return this.getDefaultState().withProperty(FACING, facing);
  132. }
  133.  
  134. protected BlockStateContainer createBlockState() {
  135. return new BlockStateContainer(this, new IProperty[]{FACING});
  136. }
  137.  
  138. /**
  139. * Convert the BlockState into the correct metadata value
  140. */
  141. public int getMetaFromState(IBlockState state) {
  142. return ((EnumFacing) state.getValue(FACING)).getIndex();
  143. }
  144.  
  145. /**
  146. * Convert the given metadata into a BlockState for this Block
  147. */
  148. public IBlockState getStateFromMeta(int meta) {
  149. EnumFacing enumfacing = EnumFacing.getFront(meta);
  150. return this.getDefaultState().withProperty(FACING, enumfacing);
  151. }
  152.  
  153. //Create That Particle Surrounding the Box. Similar to Ender Chest
  154. @SideOnly(Side.CLIENT)
  155. public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
  156. for (int i = 0; i < 3; ++i) {
  157. int j = rand.nextInt(2) * 2 - 1;
  158. int k = rand.nextInt(2) * 2 - 1;
  159. //Coords
  160. double x = (double) pos.getX() + 0.5D + 0.25D * (double) j;
  161. double y = (double) ((float) pos.getY() + rand.nextFloat());
  162. double z = (double) pos.getZ() + 0.5D + 0.25D * (double) k;
  163. //Speed
  164. double s1 = (double) (rand.nextFloat() * (float) j);
  165. double s2 = ((double) rand.nextFloat() - 0.5D) * 0.125D;
  166. double s3 = (double) (rand.nextFloat() * (float) k);
  167. worldIn.spawnParticle(EnumParticleTypes.PORTAL, x, y, z, s1, s2, s3);
  168. }
  169. }
  170.  
  171. @Override
  172. public EnumBlockRenderType getRenderType(IBlockState state) {
  173. return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
  174. }
  175.  
  176. @Override
  177. public boolean isFullBlock(IBlockState state) {
  178. return false;
  179. }
  180.  
  181. @Override
  182. public boolean isFullCube(IBlockState state) {
  183. return false;
  184. }
  185.  
  186. @Override
  187. public boolean isOpaqueCube(IBlockState state) {
  188. return false;
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment