Ejemplo n.º 1
0
  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumHand hand,
      @Nullable ItemStack heldItem,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (((Boolean) state.getValue(OPEN)).booleanValue()) {
      state = state.withProperty(OPEN, Boolean.valueOf(false));
      worldIn.setBlockState(pos, state, 10);
    } else {
      EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw);

      if (state.getValue(FACING) == enumfacing.getOpposite()) {
        state = state.withProperty(FACING, enumfacing);
      }

      state = state.withProperty(OPEN, Boolean.valueOf(true));
      worldIn.setBlockState(pos, state, 10);
    }

    worldIn.playEvent(
        playerIn, ((Boolean) state.getValue(OPEN)).booleanValue() ? 1008 : 1014, pos, 0);
    return true;
  }
Ejemplo n.º 2
0
  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i;

    switch ((EnumFacing) state.getValue(FACING)) {
      case EAST:
        i = 1;
        break;
      case WEST:
        i = 2;
        break;
      case SOUTH:
        i = 3;
        break;
      case NORTH:
        i = 4;
        break;
      case UP:
      default:
        i = 5;
        break;
      case DOWN:
        i = 0;
    }

    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      i |= 8;
    }

    return i;
  }
Ejemplo n.º 3
0
  /**
   * Called when a neighboring block was changed and marks that this state should perform any checks
   * during a neighbor change. Cases may include when redstone power is updated, cactus blocks
   * popping off due to a neighboring solid block, etc.
   */
  public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
    if (!worldIn.isRemote) {
      boolean flag = worldIn.isBlockPowered(pos);

      if (flag || blockIn.getDefaultState().canProvidePower()) {
        if (flag
            && !((Boolean) state.getValue(OPEN)).booleanValue()
            && !((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(
              pos,
              state
                  .withProperty(OPEN, Boolean.valueOf(true))
                  .withProperty(POWERED, Boolean.valueOf(true)),
              2);
          worldIn.playEvent((EntityPlayer) null, 1008, pos, 0);
        } else if (!flag
            && ((Boolean) state.getValue(OPEN)).booleanValue()
            && ((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(
              pos,
              state
                  .withProperty(OPEN, Boolean.valueOf(false))
                  .withProperty(POWERED, Boolean.valueOf(false)),
              2);
          worldIn.playEvent((EntityPlayer) null, 1014, pos, 0);
        } else if (flag != ((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)), 2);
        }
      }
    }
  }
Ejemplo n.º 4
0
 public boolean onBlockActivated(
     World worldIn,
     BlockPos pos,
     IBlockState state,
     EntityPlayer playerIn,
     EnumFacing side,
     float hitX,
     float hitY,
     float hitZ) {
   if (((Boolean) state.getValue(POWERED)).booleanValue()) {
     return true;
   } else {
     worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3);
     worldIn.markBlockRangeForRenderUpdate(pos, pos);
     worldIn.playSoundEffect(
         (double) pos.getX() + 0.5D,
         (double) pos.getY() + 0.5D,
         (double) pos.getZ() + 0.5D,
         "random.click",
         0.3F,
         0.6F);
     this.notifyNeighbors(worldIn, pos, (EnumFacing) state.getValue(FACING));
     worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
     return true;
   }
 }
Ejemplo n.º 5
0
  public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      this.notifyNeighbors(worldIn, pos, (EnumFacing) state.getValue(FACING));
    }

    super.breakBlock(worldIn, pos, state);
  }
Ejemplo n.º 6
0
  private void updateBlockBounds(IBlockState state) {
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
    boolean flag = ((Boolean) state.getValue(POWERED)).booleanValue();
    float f = 0.25F;
    float f1 = 0.375F;
    float f2 = (float) (flag ? 1 : 2) / 16.0F;
    float f3 = 0.125F;
    float f4 = 0.1875F;

    switch (enumfacing) {
      case EAST:
        this.setBlockBounds(0.0F, 0.375F, 0.3125F, f2, 0.625F, 0.6875F);
        break;
      case WEST:
        this.setBlockBounds(1.0F - f2, 0.375F, 0.3125F, 1.0F, 0.625F, 0.6875F);
        break;
      case SOUTH:
        this.setBlockBounds(0.3125F, 0.375F, 0.0F, 0.6875F, 0.625F, f2);
        break;
      case NORTH:
        this.setBlockBounds(0.3125F, 0.375F, 1.0F - f2, 0.6875F, 0.625F, 1.0F);
        break;
      case UP:
        this.setBlockBounds(0.3125F, 0.0F, 0.375F, 0.6875F, 0.0F + f2, 0.625F);
        break;
      case DOWN:
        this.setBlockBounds(0.3125F, 1.0F - f2, 0.375F, 0.6875F, 1.0F, 0.625F);
    }
  }
Ejemplo n.º 7
0
  @Override
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    EnumBlockMultiType type = (EnumBlockMultiType) state.getValue(MULTI_TYPE);
    int renderType = 0;

    switch (type) {
      case CRYO_CHAMBER:
        IBlockState stateAbove = worldIn.getBlockState(pos.up());
        TileEntityMulti tile = (TileEntityMulti) worldIn.getTileEntity(pos);
        if (stateAbove.getBlock() == this
            && (stateAbove.getValue(MULTI_TYPE)) == EnumBlockMultiType.CRYO_CHAMBER) {
          renderType = 0;
        } else {
          renderType = 4;
        }
        if (tile != null && tile.mainBlockPosition != null) {
          IBlockState stateMain = worldIn.getBlockState(tile.mainBlockPosition);
          if (stateMain.getBlock() == MarsBlocks.machine
              && stateMain.getValue(BlockMachineMars.TYPE)
                  == BlockMachineMars.EnumMachineType.CRYOGENIC_CHAMBER) {
            EnumFacing dir = stateMain.getValue(BlockMachineMars.FACING);
            renderType += dir.getHorizontalIndex();
          }
        }
        break;
      default:
        break;
    }

    return state.withProperty(RENDER_TYPE, renderType);
  }
 public int getMetaFromState(IBlockState state) {
   if (((Boolean) state.getValue(OPEN)).booleanValue()) {
     return (((EnumFacing) state.getValue(FACING)).getIndex() + 6);
   } else {
     return ((EnumFacing) state.getValue(FACING)).getIndex();
   }
 }
 protected IBlockState getUnpoweredState(IBlockState state) {
   return Blocks.unpowered_comparator
       .getDefaultState()
       .withProperty(DIRECTION, state.getValue(DIRECTION))
       .withProperty(POWERED, state.getValue(POWERED))
       .withProperty(MODE, state.getValue(MODE));
 }
  @Override
  public boolean onBlockActivated(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    state = world.getBlockState(pos);
    int i = ((Integer) state.getValue(COLOR)).intValue();
    if (world.isBlockPowered(pos)) {
      world.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)));
    }

    if (((Boolean) state.getValue(POWERED)).booleanValue() == true) {
      if (i < 3) {
        world.setBlockState(pos, state.withProperty(COLOR, i + 1));
      } else if (i == 3) {
        world.setBlockState(pos, state.withProperty(COLOR, 0));
      } else {
        return false;
      }
    } else {
      return false;
    }

    return true;
  }
Ejemplo n.º 11
0
 @Nullable
 public AxisAlignedBB getCollisionBoundingBox(
     IBlockState blockState, World worldIn, BlockPos pos) {
   return ((Boolean) blockState.getValue(OPEN)).booleanValue()
       ? NULL_AABB
       : (((EnumFacing) blockState.getValue(FACING)).getAxis() == EnumFacing.Axis.Z
           ? AABB_CLOSED_SELECTED_ZAXIS
           : AABB_CLOSED_SELECTED_XAXIS);
 }
Ejemplo n.º 12
0
 public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
   state = this.getActualState(state, source, pos);
   return ((Boolean) state.getValue(IN_WALL)).booleanValue()
       ? (((EnumFacing) state.getValue(FACING)).getAxis() == EnumFacing.Axis.X
           ? AABB_COLLIDE_XAXIS_INWALL
           : AABB_COLLIDE_ZAXIS_INWALL)
       : (((EnumFacing) state.getValue(FACING)).getAxis() == EnumFacing.Axis.X
           ? AABB_COLLIDE_XAXIS
           : AABB_COLLIDE_ZAXIS);
 }
Ejemplo n.º 13
0
  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;
    i = i | ((EnumFacing) state.getValue(FACING)).getIndex();

    if (((Boolean) state.getValue(EXTENDED)).booleanValue()) {
      i |= 8;
    }

    return i;
  }
Ejemplo n.º 14
0
 /**
  * Returns whether the two block states are equal to each other
  *
  * @param state1 The First Block State
  * @param state2 The Second Block State
  * @return Whether they are equal
  */
 public static boolean blockStatesEqual(IBlockState state1, IBlockState state2) {
   for (IProperty p : (ImmutableSet<IProperty>) state1.getProperties().keySet()) {
     if (!state2.getProperties().containsKey(p)) {
       return false;
     }
     if (state1.getValue(p) != state2.getValue(p)) {
       return false;
     }
   }
   return state1.getBlock() == state2.getBlock();
 }
 protected IBlockState getUnpoweredState(IBlockState poweredState) {
   Boolean obool = (Boolean) poweredState.getValue(POWERED);
   BlockRedstoneComparator.Mode blockredstonecomparator$mode =
       (BlockRedstoneComparator.Mode) poweredState.getValue(MODE);
   EnumFacing enumfacing = (EnumFacing) poweredState.getValue(FACING);
   return Blocks.UNPOWERED_COMPARATOR
       .getDefaultState()
       .withProperty(FACING, enumfacing)
       .withProperty(POWERED, obool)
       .withProperty(MODE, blockredstonecomparator$mode);
 }
  @Override
  public int damageDropped(IBlockState state) {
    byte b0 = 0;
    int i;

    i = b0 | ((Integer) state.getValue(COLOR)).intValue();

    if (state.getValue(DARK) == EnumType.WHITE) i |= 8;
    i |= (((Boolean) state.getValue(POWERED)).booleanValue() == true) ? 4 : 0;

    return i;
  }
Ejemplo n.º 17
0
 @Override
 public EnumFacing getFrontDirection(IBlockState state) {
   switch (getMetaUsage()) {
     case HORIZROTATION:
       return state.getValue(FACING_HORIZ);
     case ROTATION:
       return state.getValue(FACING);
     case NONE:
       return EnumFacing.NORTH;
   }
   return EnumFacing.NORTH;
 }
Ejemplo n.º 18
0
 @Override
 public int getMetaFromState(IBlockState state) {
   switch (getMetaUsage()) {
     case HORIZROTATION:
       return state.getValue(FACING_HORIZ).getIndex() - 2;
     case ROTATION:
       return state.getValue(FACING).getIndex();
     case NONE:
       return 0;
   }
   return 0;
 }
Ejemplo n.º 19
0
  private void checkForMove(World worldIn, BlockPos pos, IBlockState state) {
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
    boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing);

    if (flag && !((Boolean) state.getValue(EXTENDED)).booleanValue()) {
      if ((new BlockPistonStructureHelper(worldIn, pos, enumfacing, true)).canMove()) {
        worldIn.addBlockEvent(pos, this, 0, enumfacing.getIndex());
      }
    } else if (!flag && ((Boolean) state.getValue(EXTENDED)).booleanValue()) {
      worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(false)), 2);
      worldIn.addBlockEvent(pos, this, 1, enumfacing.getIndex());
    }
  }
Ejemplo n.º 20
0
  public int getMetaFromState(IBlockState state) {
    byte var2 = 0;
    int var3 = var2 | ((BlockPlanks.EnumType) state.getValue(VARIANT_PROP)).func_176839_a();
    if (!((Boolean) state.getValue(field_176237_a)).booleanValue()) {
      var3 |= 4;
    }

    if (((Boolean) state.getValue(field_176236_b)).booleanValue()) {
      var3 |= 8;
    }

    return var3;
  }
Ejemplo n.º 21
0
  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;
    i = i | ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();

    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      i |= 8;
    }

    if (((Boolean) state.getValue(OPEN)).booleanValue()) {
      i |= 4;
    }

    return i;
  }
Ejemplo n.º 22
0
  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;
    i = i | ((EABlockSlabDraconium.EnumType) state.getValue(VARIANT)).getMetadata();

    if (this.isDouble()) {
      if (((Boolean) state.getValue(SEAMLESS)).booleanValue()) {
        i |= 8;
      }
    } else if (state.getValue(HALF) == EABlockSlabDraconium.EnumBlockHalf.TOP) {
      i |= 8;
    }

    return i;
  }
  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;
    i = i | ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();

    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      i |= 8;
    }

    if (state.getValue(MODE) == BlockRedstoneComparator.Mode.SUBTRACT) {
      i |= 4;
    }

    return i;
  }
 @Override
 public int damageDropped(IBlockState state) {
   EightTiers stateTier = (EightTiers) state.getValue(TIER);
   int tier = stateTier.getID();
   if (tier != 0 && tier < MAXTIER) return tier - 1;
   else return 0;
 }
Ejemplo n.º 25
0
 private boolean isSameLeaf(IBlockAccess world, BlockPos pos, IBlockState state) {
   if ((world.getBlockState(pos).getBlock() == state.getBlock()
       && world.getBlockState(pos).getValue(META_PROPERTY) == state.getValue(META_PROPERTY))) {
     return true;
   }
   return false;
 }
 @Override
 public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
   int age = (Integer) state.getValue(AGE);
   if (age < 7 && rand.nextDouble() < this.default_ripeningProbability) {
     worldIn.setBlockState(pos, state.withProperty(AGE, age + 1), 2);
   }
 }
Ejemplo n.º 27
0
 protected void func_176234_a(
     World worldIn, BlockPos p_176234_2_, IBlockState p_176234_3_, int p_176234_4_) {
   if (p_176234_3_.getValue(VARIANT_PROP) == BlockPlanks.EnumType.OAK
       && worldIn.rand.nextInt(p_176234_4_) == 0) {
     spawnAsEntity(worldIn, p_176234_2_, new ItemStack(Items.apple, 1, 0));
   }
 }
Ejemplo n.º 28
0
  @SideOnly(Side.CLIENT)
  public void randomDisplayTick(World pos, BlockPos state, IBlockState worldIn, Random rand) {
    EnumFacing enumfacing = (EnumFacing) worldIn.getValue(FACING);
    double d0 = (double) state.getX() + 0.5D;
    double d1 = (double) state.getY() + 0.7D;
    double d2 = (double) state.getZ() + 0.5D;
    double d3 = 0.22D;
    double d4 = 0.27D;

    if (enumfacing.getAxis().isHorizontal()) {
      EnumFacing enumfacing1 = enumfacing.getOpposite();
      pos.spawnParticle(
          EnumParticleTypes.SPELL_MOB_AMBIENT,
          d0 + d4 * (double) enumfacing1.getFrontOffsetX(),
          d1 + d3,
          d2 + d4 * (double) enumfacing1.getFrontOffsetZ(),
          0.0D,
          5.0D,
          0.0D,
          new int[0]);
      pos.spawnParticle(
          EnumParticleTypes.REDSTONE,
          d0 + d4 * (double) enumfacing1.getFrontOffsetX(),
          d1 + d3,
          d2 + d4 * (double) enumfacing1.getFrontOffsetZ(),
          -9.0D,
          9.0D,
          -9.0D,
          new int[0]);
    } else {
      pos.spawnParticle(
          EnumParticleTypes.SPELL_MOB_AMBIENT, d0, d1, d2, 0.0D, 5.0D, 0.0D, new int[0]);
      pos.spawnParticle(EnumParticleTypes.REDSTONE, d0, d1, d2, -9.0D, 9.0D, -9.0D, new int[0]);
    }
  }
  protected int calculateInputStrength(World worldIn, BlockPos pos, IBlockState state) {
    int i = super.calculateInputStrength(worldIn, pos, state);
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
    BlockPos blockpos = pos.offset(enumfacing);
    IBlockState iblockstate = worldIn.getBlockState(blockpos);

    if (iblockstate.hasComparatorInputOverride()) {
      i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
    } else if (i < 15 && iblockstate.isNormalCube()) {
      blockpos = blockpos.offset(enumfacing);
      iblockstate = worldIn.getBlockState(blockpos);

      if (iblockstate.hasComparatorInputOverride()) {
        i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
      } else if (iblockstate.getMaterial() == Material.AIR) {
        EntityItemFrame entityitemframe = this.findItemFrame(worldIn, enumfacing, blockpos);

        if (entityitemframe != null) {
          i = entityitemframe.getAnalogOutput();
        }
      }
    }

    return i;
  }
  private void func_176462_k(World world, BlockPos pos, IBlockState state) {
    int newStrength = this.func_176460_j(world, pos, state);
    int oldStrength =
        F.or(
            world.bindTileEntity(
                pos,
                TileEntityComparator.class,
                t -> {
                  int old = t.getOutputSignal();
                  t.setOutputSignal(newStrength);
                  return old;
                }),
            0);

    if (oldStrength != newStrength
        || state.getValue(MODE) == BlockRedstoneComparator.Mode.COMPARE) {
      boolean var9 = this.isPowered(world, pos, state);
      boolean var8 = this.isPowered(state);

      if (var8 && !var9) {
        world.setBlockState(pos, state.withProperty(POWERED, false), 2);
      } else if (!var8 && var9) {
        world.setBlockState(pos, state.withProperty(POWERED, true), 2);
      }

      this.updateRedstoneState(world, pos, state);
    }
  }