Advertisement
Guest User

Untitled

a guest
Jan 1st, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 KB | None | 0 0
  1. package forestry.arboriculture.blocks;
  2.  
  3. import forestry.api.arboriculture.EnumGermlingType;
  4. import forestry.api.arboriculture.ITree;
  5. import forestry.api.arboriculture.ITreeGenome;
  6. import forestry.api.arboriculture.ITreeRoot;
  7. import forestry.api.arboriculture.TreeManager;
  8. import forestry.api.core.IItemModelRegister;
  9. import forestry.api.core.IModelManager;
  10. import forestry.api.core.IStateMapperRegister;
  11. import forestry.arboriculture.genetics.TreeDefinition;
  12. import forestry.arboriculture.render.SaplingStateMapper;
  13. import forestry.arboriculture.tiles.TileSapling;
  14. import forestry.core.tiles.TileUtil;
  15. import forestry.core.utils.ItemStackUtil;
  16. import java.util.Random;
  17. import javax.annotation.Nullable;
  18. import net.minecraft.block.Block;
  19. import net.minecraft.block.IGrowable;
  20. import net.minecraft.block.SoundType;
  21. import net.minecraft.block.material.Material;
  22. import net.minecraft.block.properties.IProperty;
  23. import net.minecraft.block.state.BlockStateContainer;
  24. import net.minecraft.block.state.IBlockState;
  25. import net.minecraft.entity.player.EntityPlayer;
  26. import net.minecraft.entity.player.PlayerCapabilities;
  27. import net.minecraft.item.Item;
  28. import net.minecraft.item.ItemStack;
  29. import net.minecraft.tileentity.TileEntity;
  30. import net.minecraft.util.BlockRenderLayer;
  31. import net.minecraft.util.NonNullList;
  32. import net.minecraft.util.math.AxisAlignedBB;
  33. import net.minecraft.util.math.BlockPos;
  34. import net.minecraft.util.math.RayTraceResult;
  35. import net.minecraft.world.IBlockAccess;
  36. import net.minecraft.world.World;
  37. import net.minecraftforge.client.model.ModelLoader;
  38. import net.minecraftforge.fml.relauncher.Side;
  39. import net.minecraftforge.fml.relauncher.SideOnly;
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. public class BlockSapling
  49. extends BlockTreeContainer
  50. implements IGrowable, IStateMapperRegister, IItemModelRegister
  51. {
  52. protected static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.09999999403953552D, 0.0D, 0.09999999403953552D, 0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
  53.  
  54. public static final PropertyTree TREE = new PropertyTree("tree");
  55.  
  56. public BlockSapling() {
  57. super(Material.field_151585_k);
  58. func_149672_a(SoundType.field_185850_c);
  59. }
  60.  
  61. public AxisAlignedBB func_185496_a(IBlockState state, IBlockAccess source, BlockPos pos)
  62. {
  63. return SAPLING_AABB;
  64. }
  65.  
  66. public TileEntity func_149915_a(World var1, int meta)
  67. {
  68. return new TileSapling();
  69. }
  70.  
  71.  
  72.  
  73. @Nullable
  74. public AxisAlignedBB func_180646_a(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
  75. {
  76. return null;
  77. }
  78.  
  79.  
  80.  
  81. public boolean func_149662_c(IBlockState state)
  82. {
  83. return false;
  84. }
  85.  
  86. public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos)
  87. {
  88. return false;
  89. }
  90.  
  91. public BlockRenderLayer func_180664_k()
  92. {
  93. return BlockRenderLayer.CUTOUT;
  94. }
  95.  
  96.  
  97. public int func_176201_c(IBlockState state)
  98. {
  99. return 0;
  100. }
  101.  
  102. public IBlockState func_176221_a(IBlockState state, IBlockAccess world, BlockPos pos)
  103. {
  104. TileSapling sapling = (TileSapling)TileUtil.getTile(world, pos, TileSapling.class);
  105. if ((sapling != null) && (sapling.getTree() != null)) {
  106. state = state.func_177226_a(TREE, sapling.getTree().getGenome().getPrimary());
  107. } else {
  108. state = state.func_177226_a(TREE, TreeDefinition.Oak.getGenome().getPrimary());
  109. }
  110. return state;
  111. }
  112.  
  113. protected BlockStateContainer func_180661_e()
  114. {
  115. return new BlockStateContainer(this, new IProperty[] { TREE });
  116. }
  117.  
  118. @SideOnly(Side.CLIENT)
  119. public void registerStateMapper()
  120. {
  121. ModelLoader.setCustomStateMapper(this, new SaplingStateMapper());
  122. }
  123.  
  124.  
  125.  
  126. @SideOnly(Side.CLIENT)
  127. public void registerModel(Item item, IModelManager manager)
  128. {
  129. manager.registerItemModel(item, 0, "germlings/sapling.tree_larch");
  130. }
  131.  
  132. public static boolean canBlockStay(IBlockAccess world, BlockPos pos)
  133. {
  134. TileSapling tile = (TileSapling)TileUtil.getTile(world, pos, TileSapling.class);
  135. if (tile == null) {
  136. return false;
  137. }
  138.  
  139. ITree tree = tile.getTree();
  140. return (tree != null) && (tree.canStay(world, pos));
  141. }
  142.  
  143. public void func_189540_a(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
  144. {
  145. super.func_189540_a(state, worldIn, pos, blockIn, fromPos);
  146. if ((!field_72995_K) && (!canBlockStay(worldIn, pos))) {
  147. dropAsSapling(worldIn, pos);
  148. worldIn.func_175698_g(pos);
  149. }
  150. }
  151.  
  152.  
  153. public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
  154. {
  155. ItemStack drop = getDrop(world, pos);
  156. if (!drop.func_190926_b()) {
  157. drops.add(drop);
  158. }
  159. }
  160.  
  161. public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
  162. {
  163. TileSapling sapling = (TileSapling)TileUtil.getTile(world, pos, TileSapling.class);
  164. if ((sapling == null) || (sapling.getTree() == null)) {
  165. return ItemStack.field_190927_a;
  166. }
  167. return TreeManager.treeRoot.getMemberStack(sapling.getTree(), EnumGermlingType.SAPLING);
  168. }
  169.  
  170. public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
  171. {
  172. if ((!field_72995_K) && (canHarvestBlock(world, pos, player)) &&
  173. (!field_71075_bZ.field_75098_d)) {
  174. dropAsSapling(world, pos);
  175. }
  176.  
  177.  
  178. return world.func_175698_g(pos);
  179. }
  180.  
  181. private static void dropAsSapling(World world, BlockPos pos) {
  182. if (field_72995_K) {
  183. return;
  184. }
  185. ItemStack drop = getDrop(world, pos);
  186. if (!drop.func_190926_b()) {
  187. ItemStackUtil.dropItemStackAsEntity(drop, world, pos);
  188. }
  189. }
  190.  
  191. private static ItemStack getDrop(IBlockAccess world, BlockPos pos) {
  192. TileSapling sapling = (TileSapling)TileUtil.getTile(world, pos, TileSapling.class);
  193. if (sapling != null) {
  194. ITree tree = sapling.getTree();
  195. if (tree != null) {
  196. return TreeManager.treeRoot.getMemberStack(tree, EnumGermlingType.SAPLING);
  197. }
  198. }
  199. return ItemStack.field_190927_a;
  200. }
  201.  
  202.  
  203. public boolean func_180670_a(World world, Random rand, BlockPos pos, IBlockState state)
  204. {
  205. if (field_73012_v.nextFloat() >= 0.45F) {
  206. return false;
  207. }
  208. TileSapling saplingTile = (TileSapling)TileUtil.getTile(world, pos, TileSapling.class);
  209. return (saplingTile == null) || (saplingTile.canAcceptBoneMeal(rand));
  210. }
  211.  
  212. public boolean func_176473_a(World world, BlockPos pos, IBlockState state, boolean isClient)
  213. {
  214. return true;
  215. }
  216.  
  217. public void func_176474_b(World world, Random rand, BlockPos pos, IBlockState state)
  218. {
  219. TileSapling saplingTile = (TileSapling)TileUtil.getTile(world, pos, TileSapling.class);
  220. if (saplingTile != null) {
  221. saplingTile.tryGrow(rand, true);
  222. }
  223. }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement