Advertisement
Guest User

code

a guest
Apr 21st, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.68 KB | None | 0 0
  1. public class BlockSilver extends BlockMetal {
  2.  
  3.     public BlockSilver(String unlocalizedName, String registryName, MapColor mapcolor, int harvestLevel) {
  4.         super(unlocalizedName, registryName, mapcolor, harvestLevel);
  5.        
  6.     }
  7.  
  8.     public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
  9.     {
  10.         Console.println("Collided with silver block"); //  <---This never prints, even when it should
  11.         if (entityIn instanceof EntityLiving)
  12.         {
  13.             if (((EntityLiving) entityIn).isEntityUndead())
  14.             {
  15.                 entityIn.attackEntityFrom(DamageSource.GENERIC, 1.0F);
  16.             }
  17.         }
  18.     }
  19. }
  20.  
  21.  
  22. //-------------------------------------------------------------------------------------------------------
  23.  
  24. public class BlockTrapFlamePad extends Block {
  25.  
  26.      public static final PropertyBool PRESSED = PropertyBool.create("pressed");
  27.    
  28.     public BlockTrapFlamePad() {
  29.         super(Material.ROCK);
  30.        
  31.         this.setUnlocalizedName(Reference.ToSBlocks.TRAP_FLAME_PAD.getUnlocalizedName());
  32.         this.setRegistryName(Reference.ToSBlocks.TRAP_FLAME_PAD.getRegistryName());
  33.         this.setTickRandomly(true);
  34.         this.setHardness(1.5F);
  35.         this.setResistance(10.0F);
  36.         this.setSoundType(SoundType.STONE);
  37.         this.setDefaultState(this.blockState.getBaseState().withProperty(PRESSED, false));
  38.        
  39.     }
  40.    
  41.     public int tickRate(World worldIn)
  42.     {
  43.         return 20;
  44.     }
  45.    
  46.     public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
  47.         Console.println("Update tick called");  // <---- THIS NEVER FIRES EITHER
  48.         if (worldIn.getBlockState(pos.up()).getBlock() == Blocks.FIRE)  {
  49.             worldIn.setBlockState(pos, state.withProperty(PRESSED, false), 2);
  50.             worldIn.setBlockState(pos.up(), Blocks.AIR.getDefaultState(), 2);
  51.             worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_STONE_PRESSPLATE_CLICK_OFF, SoundCategory.BLOCKS, 0.3F, 0.5F);
  52.         }
  53.     }
  54.    
  55.     public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
  56.     {
  57.         Console.println("Touched the flame pad"); //  <----THIS NEVER PRINTS OMG WHAT IS GOING ON!!!
  58.         if (pos.up().getY() == entityIn.getPosition().getY()) {
  59.             Console.println("Walked over flame pad!");
  60.            
  61.             if (worldIn.getBlockState(pos.up()).getBlock() == Blocks.AIR || worldIn.getBlockState(pos.up()).getBlock() == Blocks.FIRE) {
  62.                 if (state.getValue(PRESSED) == false) {
  63.                     boolean lightFire = false;
  64.                     if (entityIn instanceof EntityPlayer) {
  65.                         if (!((EntityPlayer)entityIn).isSneaking()) {
  66.                             lightFire = true;
  67.                         }
  68.                     }
  69.                     else {
  70.                         lightFire = true;
  71.                     }
  72.                    
  73.                     if (lightFire) {
  74.                         worldIn.setBlockState(pos, state.withProperty(PRESSED, true), 2);
  75.                         worldIn.setBlockState(pos.up(), Blocks.FIRE.getDefaultState(), 2);
  76.                         worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_STONE_PRESSPLATE_CLICK_ON, SoundCategory.BLOCKS, 0.3F, 0.6F);
  77.                         worldIn.scheduleUpdate(new BlockPos(pos), this, this.tickRate(worldIn));
  78.                     }
  79.  
  80.                 }
  81.             }
  82.         }
  83.  
  84.  
  85.     }
  86.    
  87.    
  88.     public IBlockState getStateFromMeta(int meta)
  89.     {
  90.         return this.getDefaultState().withProperty(PRESSED, Boolean.valueOf(meta == 1));
  91.     }
  92.  
  93.     public int getMetaFromState(IBlockState state)
  94.     {
  95.         return ((Boolean)state.getValue(PRESSED)).booleanValue() ? 1 : 0;
  96.     }
  97.  
  98.     protected BlockStateContainer createBlockState()
  99.     {
  100.         return new BlockStateContainer(this, new IProperty[] {PRESSED});
  101.     }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement