SHARE
TWEET

ItemScythe

a guest May 6th, 2018 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package tuunaa.stardew.items;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.BlockCrops;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.state.IBlockState;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.init.Blocks;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.ActionResult;
  13. import net.minecraft.util.EnumActionResult;
  14. import net.minecraft.util.EnumFacing;
  15. import net.minecraft.util.EnumHand;
  16. import net.minecraft.util.math.BlockPos;
  17. import net.minecraft.util.text.TextComponentString;
  18. import net.minecraft.world.World;
  19. import net.minecraftforge.common.IPlantable;
  20.  
  21. public class ItemScythe extends ItemBase {
  22.     public ItemScythe(String name) {
  23.         super(name);
  24.     }
  25.     public void centerDestroy(Block block, IBlockState state, World worldIn, BlockPos pos) {
  26.         if (block == Blocks.WHEAT || block == Blocks.CARROTS || block == Blocks.BEETROOTS || block == Blocks.POTATOES || block == Blocks.NETHER_WART) {
  27.             if ((int)state.getValue(BlockCrops.AGE) == ((BlockCrops)block).getMaxAge()) {
  28.                 worldIn.destroyBlock(pos, true);
  29.                 worldIn.setBlockState(pos, block.getDefaultState());
  30.             }
  31.         }
  32.     }
  33.    
  34.     public void posCompare(BlockPos pos, World worldIn, EnumFacing facing, EntityPlayer entity) {
  35.         for (EnumFacing direction : EnumFacing.HORIZONTALS) {
  36.             EnumFacing facingHoriz = entity.getHorizontalFacing();
  37.             EnumFacing facingOpp = facingHoriz.getOpposite();
  38.            
  39.             BlockPos neighborPos = pos.offset(direction);
  40.             IBlockState neighborState = worldIn.getBlockState(neighborPos);
  41.             Block neighborBlock = neighborState.getBlock();
  42.            
  43.             BlockPos facingPos = pos.offset(facingHoriz);
  44.             BlockPos oppPos = pos.offset(facingOpp);
  45.            
  46.             System.out.println("opposite direction " + facingOpp);
  47.             System.out.println("neighborPos " + neighborPos);
  48.             System.out.println("oppPos " + oppPos);
  49.            
  50.             if (neighborPos != oppPos || neighborPos != facingPos) {
  51.                 if (neighborBlock == Blocks.WHEAT || neighborBlock == Blocks.CARROTS || neighborBlock == Blocks.BEETROOTS || neighborBlock == Blocks.POTATOES || neighborBlock == Blocks.NETHER_WART) {
  52.                     if ((int)neighborState.getValue(BlockCrops.AGE) == ((BlockCrops)neighborBlock).getMaxAge()) {
  53.                         worldIn.destroyBlock(neighborPos, true);
  54.                         worldIn.setBlockState(neighborPos, neighborBlock.getDefaultState());
  55.                     }
  56.                 }
  57.             } else {
  58.                 break;
  59.             }
  60.         }
  61.     }
  62.    
  63.     @Override
  64.     public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  65.         if (!worldIn.isRemote) {
  66.             EnumFacing facingHoriz = playerIn.getHorizontalFacing();
  67.            
  68.             BlockPos clicked = pos;
  69.             IBlockState clickedState = worldIn.getBlockState(clicked);
  70.             BlockPos facingPos = pos.offset(facingHoriz);
  71.            
  72.             posCompare(facingPos, worldIn, facing, playerIn);
  73.             posCompare(pos, worldIn, facing, playerIn);
  74.             centerDestroy(clickedState.getBlock(), clickedState, worldIn, pos);
  75.            
  76.             return EnumActionResult.SUCCESS;
  77.         } else {
  78.             return EnumActionResult.FAIL;
  79.         }
  80.     }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top