SHARE
TWEET

Untitled

a guest Feb 27th, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.bvanseghi.starcraft.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.bvanseghi.starcraft.items.ModItems;
  6. import net.bvanseghi.starcraft.lib.Reference;
  7. import net.minecraft.block.BlockDirt;
  8. import net.minecraft.block.SoundType;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.block.properties.PropertyInteger;
  11. import net.minecraft.block.state.IBlockState;
  12. import net.minecraft.init.Blocks;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.util.math.AxisAlignedBB;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.world.IBlockAccess;
  17. import net.minecraft.world.World;
  18.  
  19. public class BlockZergCreep extends ModBlocks {
  20.    
  21.     public static final PropertyInteger LAYERS = PropertyInteger.create("layers", 1, 8);
  22.     protected static final AxisAlignedBB[] SNOW_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 1.0D), 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.5D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.75D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.875D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D)};
  23.  
  24.      
  25.     public BlockZergCreep() {
  26.         super(Material.GROUND);
  27.         setUnlocalizedName(Reference.ModBlocks.BLOCK_ZERG_CREEP.getUnlocalizedName());
  28.         setRegistryName(Reference.ModBlocks.BLOCK_ZERG_CREEP.getRegistryRL());
  29.         setSoundType(SoundType.SAND);
  30.         setHardness(5.0F);
  31.         setResistance(10.0F);
  32.         setHarvestLevel("shovel", 2);
  33.         setTickRandomly(true);
  34.     }
  35.    
  36.     public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  37.     {
  38.         return SNOW_AABB[((Integer)state.getValue(LAYERS)).intValue()];
  39.     }
  40.  
  41.     @Override
  42.     public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  43.         return ModItems.creepResin;
  44.     }
  45.  
  46.     @Override
  47.     public int quantityDropped(Random rand) {
  48.         return 2 + rand.nextInt(2);
  49.     }
  50.  
  51.     @Override
  52.     protected boolean canSilkHarvest() {
  53.         return true;
  54.     }
  55.  
  56.     // TODO: Redo the Zerg Creep effect
  57.     @Override
  58.     public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
  59.         if(!worldIn.isRemote) {
  60.             if(worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2) {
  61.                 worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
  62.             } else if(worldIn.getLightFromNeighbors(pos.up()) >= 9) {
  63.                 for(int i = 0; i < 4; i++) {
  64.                     BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
  65.  
  66.                     if(blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos)) {
  67.                         return;
  68.                     }
  69.  
  70.                     IBlockState currState= worldIn.getBlockState(blockpos);
  71.                     IBlockState upState = worldIn.getBlockState(blockpos.up());
  72.  
  73.                     if (currState.getBlock() == Blocks.DIRT && currState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && upState.getLightOpacity(worldIn, pos.up()) <= 2) {
  74.                         worldIn.setBlockState(blockpos, ModBlocks.ZERG_CREEP.getDefaultState());
  75.                     }
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top