Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. package com.theishiopian.foragecraft.blocks;
  2.  
  3. import javax.annotation.Nullable;
  4.  
  5. import com.theishiopian.foragecraft.init.ModBlocks;
  6. import com.theishiopian.foragecraft.init.ModBlocks.RockType;
  7.  
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.BlockFalling;
  10. import net.minecraft.block.SoundType;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.block.state.IBlockState;
  13. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  14. import net.minecraft.creativetab.CreativeTabs;
  15. import net.minecraft.entity.item.EntityItem;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.item.Item;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.util.EnumFacing;
  20. import net.minecraft.util.EnumHand;
  21. import net.minecraft.util.math.AxisAlignedBB;
  22. import net.minecraft.util.math.BlockPos;
  23. import net.minecraft.world.IBlockAccess;
  24. import net.minecraft.world.World;
  25. import net.minecraftforge.client.model.ModelLoader;
  26. import net.minecraftforge.fml.relauncher.Side;
  27. import net.minecraftforge.fml.relauncher.SideOnly;
  28.  
  29. public class RockBlock extends BlockFalling
  30. {
  31.     RockType type;
  32.    
  33.     public RockBlock(RockType t)
  34.     {
  35.         super(Material.ROCK);
  36.        
  37.         String name = null;
  38.        
  39.         switch(t)
  40.         {
  41.             case NORMAL: name = "rock_normal";
  42.             break;
  43.             case FLAT: name = "rock_flat";
  44.             break;
  45.         }
  46.         setUnlocalizedName(name);
  47.         setRegistryName(name);
  48.         setCreativeTab(CreativeTabs.DECORATIONS);
  49.         setSoundType(SoundType.STONE);
  50.         type = t;
  51.     }
  52.    
  53.    
  54.    
  55.     @SideOnly(Side.CLIENT)
  56.     public void initModel()
  57.     {
  58.         ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
  59.     }
  60.  
  61.     @Override
  62.     public boolean isFullCube(IBlockState state)
  63.     {
  64.         return false;
  65.     }
  66.  
  67.     @Override
  68.     public boolean isOpaqueCube(IBlockState state)
  69.     {
  70.         return false;
  71.     }
  72.  
  73.     @Nullable
  74.     @Override
  75.     public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
  76.     {
  77.         return null;
  78.     }
  79.    
  80. //  @Override
  81. //  public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor)
  82. //  {
  83. //      System.out.println("crack");
  84. //      if(neighbor == pos.down())
  85. //      {
  86. //          ((World) world).setBlockToAir(pos);
  87. //      }
  88. //  }
  89.  
  90.     @Override
  91.     public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
  92.     {
  93.         if(!worldIn.isRemote)
  94.         {
  95.             ItemStack stack = null;
  96.            
  97.             switch(type)
  98.             {
  99.                 case FLAT: stack  = new ItemStack(Item.getItemFromBlock(ModBlocks.rock_flat));
  100.                     break;
  101.                 case NORMAL: stack  = new ItemStack(Item.getItemFromBlock(ModBlocks.rock_normal));
  102.                     break;
  103.             }
  104.            
  105.             worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack));
  106.         }
  107.     }
  108.  
  109.     @Override
  110.     public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
  111.             EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
  112.     {
  113.         if(!worldIn.isRemote)
  114.         {
  115.             ItemStack stack = null;
  116.            
  117.             switch(type)
  118.             {
  119.                 case FLAT: stack  = new ItemStack(Item.getItemFromBlock(ModBlocks.rock_flat));
  120.                     break;
  121.                 case NORMAL: stack  = new ItemStack(Item.getItemFromBlock(ModBlocks.rock_normal));
  122.                     break;
  123.             }
  124.            
  125.             worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack));
  126.             worldIn.setBlockToAir(pos);
  127.         }
  128.        
  129.         return false;
  130.     }
  131.    
  132.      /**
  133.      * Get the OffsetType for this Block. Determines if the model is rendered slightly offset.
  134.      */
  135.     @Override
  136.     public Block.EnumOffsetType getOffsetType()
  137.     {
  138.         return Block.EnumOffsetType.XZ;
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement