Guest User

Untitled

a guest
Sep 1st, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. package com.mightydanp.eot.common.block;
  2.  
  3. import java.util.List;
  4. import java.util.Locale;
  5. import java.util.Random;
  6.  
  7. import javax.annotation.Nullable;
  8.  
  9. import com.mightydanp.eot.api.common.block.IMetaBlock;
  10. import com.mightydanp.eot.common.EoT;
  11.  
  12. import net.minecraft.block.SoundType;
  13. import net.minecraft.block.material.Material;
  14. import net.minecraft.block.properties.PropertyEnum;
  15. import net.minecraft.block.state.IBlockState;
  16. import net.minecraft.entity.Entity;
  17. import net.minecraft.entity.player.EntityPlayer;
  18. import net.minecraft.init.Blocks;
  19. import net.minecraft.init.Items;
  20. import net.minecraft.item.Item;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.stats.StatList;
  23. import net.minecraft.tileentity.TileEntity;
  24. import net.minecraft.util.BlockRenderLayer;
  25. import net.minecraft.util.IStringSerializable;
  26. import net.minecraft.util.math.AxisAlignedBB;
  27. import net.minecraft.util.math.BlockPos;
  28. import net.minecraft.world.IBlockAccess;
  29. import net.minecraft.world.World;
  30. import net.minecraftforge.fml.relauncher.Side;
  31. import net.minecraftforge.fml.relauncher.SideOnly;
  32.  
  33. public class BlockTwigs extends IMetaBlock implements net.minecraftforge.common.IPlantable {
  34.  
  35. private static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 0.0625, 1.0);
  36.  
  37. public static final PropertyEnum TYPE = PropertyEnum.create("twigs", TwigsType.class);
  38.  
  39. public BlockTwigs(String unlocalizedName) {
  40. super(Material.GRASS, TYPE, TwigsType.class, unlocalizedName);
  41. this.setCreativeTab(EoT.tabEoT);
  42. this.setUnlocalizedName(unlocalizedName);
  43. this.setHardness(0.5F);
  44. this.setSoundType(SoundType.PLANT);
  45. this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, TwigsType.TWIGS));
  46. }
  47.  
  48. public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
  49. if (state.getBlock() == this) {
  50. IBlockState soil = worldIn.getBlockState(pos.down());
  51. return soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
  52. }
  53. return this.canSustainBush(worldIn.getBlockState(pos.down()));
  54. }
  55.  
  56. protected boolean canSustainBush(IBlockState state) {
  57. return state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.DIRT || state.getBlock() == Blocks.SAND || state.getBlock() == Blocks.STONE;
  58. }
  59.  
  60. @Override
  61. public boolean isFullCube(IBlockState state) {
  62. return false;
  63. }
  64.  
  65. @Override
  66. public boolean isOpaqueCube(IBlockState state) {
  67. return false;
  68. }
  69.  
  70. @SideOnly(Side.CLIENT)
  71. @Override
  72. public BlockRenderLayer getBlockLayer() {
  73. return BlockRenderLayer.TRANSLUCENT;
  74. }
  75.  
  76. @Override
  77. public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) {
  78. super.addCollisionBoxToList(pos, entityBox, collidingBoxes, BOUNDING_BOX);
  79. }
  80.  
  81. @Override
  82. public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
  83. return BOUNDING_BOX;
  84. }
  85.  
  86. @Override
  87. public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  88. return null;
  89. }
  90.  
  91. @Override
  92. public int quantityDropped(Random rand) {
  93. return 0;
  94. }
  95.  
  96. @Override
  97. public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, @Nullable ItemStack stack) {
  98. if (!worldIn.isRemote && stack != null && stack.getItem() == Items.SHEARS) {
  99. player.addStat(StatList.getBlockStats(this));
  100. spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(ModBlocks.twigs)));
  101. } else {
  102. Random rand = null;
  103. player.addStat(StatList.getBlockStats(this));
  104. spawnAsEntity(worldIn, pos, new ItemStack(Items.STICK, 1 + this.RANDOM.nextInt(3), 0));
  105. }
  106. }
  107.  
  108. @Override
  109. public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
  110. if (this == ModBlocks.twigs) return net.minecraftforge.common.EnumPlantType.Desert;
  111. return net.minecraftforge.common.EnumPlantType.Plains;
  112. }
  113.  
  114. @Override
  115. public IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos) {
  116. IBlockState state = world.getBlockState(pos);
  117. if (state.getBlock() != this) return getDefaultState();
  118. return state;
  119. }
  120.  
  121. public enum TwigsType implements IStringSerializable,IMetaBlock.IEnumMeta {
  122. TWIGS;
  123.  
  124. public final int meta;
  125.  
  126. TwigsType() {
  127. meta = ordinal();
  128. }
  129.  
  130. @Override
  131. public String getName() {
  132. return this.toString().toLowerCase(Locale.US);
  133. }
  134.  
  135. @Override
  136. public int getMeta() {
  137. return meta;
  138. }
  139.  
  140. }
  141.  
  142. }
Add Comment
Please, Sign In to add comment