Advertisement
Guest User

Untitled

a guest
May 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. package com.varitekcibus.amazingfoodstuffs.objects.blocks;
  2.  
  3. import com.varitekcibus.amazingfoodstuffs.init.BlockInit;
  4. import com.varitekcibus.amazingfoodstuffs.init.ItemInit;
  5.  
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.BlockCrops;
  8. import net.minecraft.block.properties.PropertyInteger;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.entity.item.EntityItem;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.init.Blocks;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.item.ItemBlock;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.EnumFacing;
  17. import net.minecraft.util.EnumHand;
  18. import net.minecraft.util.math.AxisAlignedBB;
  19. import net.minecraft.util.math.BlockPos;
  20. import net.minecraft.world.IBlockAccess;
  21. import net.minecraft.world.World;
  22.  
  23. public class BlockTomatoPlant extends BlockCrops
  24.  
  25. {
  26.  
  27. private static final AxisAlignedBB[] tomato = new AxisAlignedBB[] {new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.125D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.25D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.375D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.8125D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D)};
  28.  
  29. public BlockTomatoPlant(String name)
  30.  
  31. {
  32.  
  33. setUnlocalizedName(name);
  34. setRegistryName(name);
  35.  
  36. BlockInit.BLOCKS.add(this);
  37. ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(getRegistryName()));
  38.  
  39. }
  40.  
  41. public boolean onBlockLeftClick(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
  42.  
  43. {
  44.  
  45. if(!worldIn.isRemote)
  46.  
  47. {
  48.  
  49. if(this.isMaxAge(state))
  50.  
  51. {
  52.  
  53. worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ItemInit.TOMATO, 1)));
  54. worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ItemInit.TOMATO_SEED, 1)));
  55. worldIn.setBlockState(pos, this.withAge(0));
  56. return true;
  57.  
  58. }
  59.  
  60. }
  61.  
  62. return false;
  63.  
  64. }
  65.  
  66. protected boolean canSustainBlock(IBlockState state)
  67. {
  68. return state.getBlock() == Blocks.FARMLAND;
  69. }
  70.  
  71.  
  72. @Override
  73. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
  74.  
  75. {
  76.  
  77. if(!worldIn.isRemote)
  78.  
  79. {
  80.  
  81. if(this.isMaxAge(state))
  82.  
  83. {
  84.  
  85. worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ItemInit.ONION, 1)));
  86. worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ItemInit.ONION_SEED, 1)));
  87. worldIn.setBlockState(pos, this.withAge(0));
  88. return true;
  89.  
  90. }
  91.  
  92. }
  93.  
  94. return false;
  95.  
  96. }
  97.  
  98. @Override
  99. protected Item getSeed()
  100. {
  101.  
  102. return ItemInit.TOMATO_SEED;
  103.  
  104. }
  105.  
  106. @Override
  107. protected Item getCrop()
  108.  
  109. {
  110.  
  111. return ItemInit.TOMATO;
  112.  
  113. }
  114.  
  115. @Override
  116. public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  117. {
  118. return tomato[((Integer)state.getValue(this.getAgeProperty())).intValue()];
  119. }
  120.  
  121.  
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement