net.minecraft.block.Block.getHarvestLevel()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中net.minecraft.block.Block.getHarvestLevel()方法的一些代码示例,展示了Block.getHarvestLevel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getHarvestLevel()方法的具体详情如下:
包路径:net.minecraft.block.Block
类名称:Block
方法名:getHarvestLevel

Block.getHarvestLevel介绍

暂无

代码示例

代码示例来源:origin: SlimeKnights/TinkersConstruct

/**
 * Checks if an item has the right harvest level of the correct type for the block.
 */
public static boolean canHarvest(ItemStack stack, IBlockState state) {
 Block block = state.getBlock();
 // doesn't require a tool
 if(state.getMaterial().isToolNotRequired()) {
  return true;
 }
 String type = block.getHarvestTool(state);
 int level = block.getHarvestLevel(state);
 return stack.getItem().getHarvestLevel(stack, type, null, state) >= level;
}

代码示例来源:origin: SlimeKnights/TinkersConstruct

@Override
public void miningSpeed(ItemStack tool, PlayerEvent.BreakSpeed event) {
 Block block = event.getState().getBlock();
 int hlvl = tool.getItem().getHarvestLevel(tool, block.getHarvestTool(event.getState()), event.getEntityPlayer(), event.getState());
 int dif = hlvl - block.getHarvestLevel(event.getState());
 // 1 speed per harvest level above
 if(dif > 0) {
  event.setNewSpeed(event.getNewSpeed() + dif);
 }
}

代码示例来源:origin: Vazkii/Botania

@Override
public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) {
  if(!entity.world.isRemote && !burst.isFake() && pos.getBlockPos() != null) {
    int harvestLevel = ConfigHandler.harvestLevelWeight;
    BlockPos bPos = pos.getBlockPos();
    Block block = entity.world.getBlockState(bPos).getBlock();
    IBlockState state = entity.world.getBlockState(bPos);
    int neededHarvestLevel = block.getHarvestLevel(state);
    if(entity.world.isAirBlock(bPos.down()) && state.getBlockHardness(entity.world, bPos) != -1 && neededHarvestLevel <= harvestLevel && entity.world.getTileEntity(bPos) == null && block.canSilkHarvest(entity.world, bPos, state, null)) {
      state = TECHNICAL_BLOCK_REMAP.getOrDefault(state, state);
      EntityFallingBlock falling = new EntityFallingBlock(entity.world, bPos.getX() + 0.5, bPos.getY(), bPos.getZ() + 0.5, state);
      falling.fallTime = 1;
      entity.world.setBlockToAir(bPos);
      ((WorldServer) entity.world).spawnParticle(EnumParticleTypes.FALLING_DUST, bPos.getX() + 0.5, bPos.getY() + 0.5, bPos.getZ() + 0.5, 10, 0.45, 0.45, 0.45, 5, new int[] {Block.getStateId(state)});
      entity.world.spawnEntity(falling);
    }
  }
  return dead;
}

代码示例来源:origin: AlgorithmX2/Chisels-and-Bits

@Override
public int getHarvestLevel(
    final IBlockState state )
{
  return Blocks.STONE.getHarvestLevel( Blocks.STONE.getDefaultState() );
}

代码示例来源:origin: amadornes/MCMultiPart

@Override
public int getCuttingStrength() {
  return Math.max(0, state.getBlock().getHarvestLevel(state));
}

代码示例来源:origin: Vazkii/Psi

@Override
public boolean canHarvestBlock(@Nonnull IBlockState state, ItemStack stack) {
  Block block = state.getBlock();
  int level = block.getHarvestLevel(state);
  return getHarvestLevel(stack, "", null, null) >= level; 
}

代码示例来源:origin: McJtyMods/TheOneProbe

static void showHarvestLevel(IProbeInfo probeInfo, IBlockState blockState, Block block) {
  String harvestTool = block.getHarvestTool(blockState);
  if (harvestTool != null) {
    int harvestLevel = block.getHarvestLevel(blockState);
    String harvestName;
    if (harvestLevel >= harvestLevels.length) {
      harvestName = Integer.toString(harvestLevel);
    } else if (harvestLevel < 0) {
      harvestName = Integer.toString(harvestLevel);
    } else {
      harvestName = harvestLevels[harvestLevel];
    }
    probeInfo.text(LABEL + "Tool: " + INFO + harvestTool + " (level " + harvestName + ")");
  }
}

代码示例来源:origin: Vazkii/Botania

int neededHarvestLevel = block.getHarvestLevel(state);
int mana = burst.getMana();

代码示例来源:origin: CoFH/CoFHCore

@Override
public boolean canHarvestBlock(IBlockState state, ItemStack stack) {
  return harvestLevel >= state.getBlock().getHarvestLevel(state) && getDestroySpeed(stack, state) > 1.0F;
}

代码示例来源:origin: SquidDev-CC/plethora

@Nonnull
@Override
public Map<Object, Object> getMeta(@Nonnull IPartialContext<IBlockState> context) {
  IBlockState state = context.getTarget();
  Block block = state.getBlock();
  Map<Object, Object> data = new HashMap<>();
  fillBasicMeta(data, state);
  Material material = state.getMaterial();
  data.put("material", PlethoraAPI.instance().metaRegistry().getMeta(context.makePartialChild(material)));
  int level = block.getHarvestLevel(state);
  if (level >= 0) data.put("harvestLevel", level);
  data.put("harvestTool", block.getHarvestTool(state));
  return data;
}

代码示例来源:origin: TerraFirmaCraft/TerraFirmaCraft

public BlockStairsTFC(Rock rock, Rock.Type type)
{
  super(BlockRockVariant.get(rock, type).getDefaultState());
  if (!ROCK_TABLE.containsKey(rock))
    ROCK_TABLE.put(rock, new EnumMap<>(Rock.Type.class));
  ROCK_TABLE.get(rock).put(type, this);
  Block c = BlockRockVariant.get(rock, type);
  setHarvestLevel(c.getHarvestTool(c.getDefaultState()), c.getHarvestLevel(c.getDefaultState()));
  OreDictionaryHelper.register(this, "stair");
  OreDictionaryHelper.registerRockType(this, type, rock, "stair");
}

代码示例来源:origin: ldtteam/minecolonies

/**
 * Get the correct havestlevel for a certain block.
 * We need this because minecraft has a lot of blocks which have strange or no required harvestlevel.
 *
 * @param target the target block.
 * @return the required harvestLevel.
 */
public static int getCorrectHavestLevelForBlock(final Block target)
{
  final int required = target.getHarvestLevel(target.getDefaultState());
  if ((required == -1 && target.getDefaultState().getMaterial() == Material.WOOD)
     || target == Blocks.HARDENED_CLAY || target == Blocks.STAINED_HARDENED_CLAY)
  {
    return 0;
  }
  return required;
}

代码示例来源:origin: Ellpeck/ActuallyAdditions

private boolean checkIndestructable(World world, BlockPos pos){
    //If this isn't checked, the game crashes because it tries to destroy a chest that doesn't have any loot yet :v
    TileEntity tile = world.getTileEntity(pos);
    if(tile instanceof ILootContainer){
      return true;
    }

    IBlockState state = world.getBlockState(pos);
    if(state != null){
      Block block = state.getBlock();
      //check if it's tree or grass that is generated here
      if(block == Blocks.LOG || block == Blocks.LEAVES || block == Blocks.TALLGRASS){
        return true;
      }
      if(block != null && (block.isAir(state, world, pos) || block.getHarvestLevel(state) >= 0F)){
        return false;
      }
    }
    return true;
  }
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

private boolean canHarvest(BlockPos harvestPos) {
  //TODO add block-breaking exclusion list to config
  IBlockState state = world.getBlockState(harvestPos);
  Block block = state.getBlock();
  if (world.isAirBlock(harvestPos) || state.getMaterial().isLiquid()) {
    return false;
  }
  int harvestLevel = block.getHarvestLevel(state);
  if (harvestLevel >= 2) {
    int toolLevel = 1;
    if (getUpgrades().contains(WorksiteUpgrade.TOOL_QUALITY_3)) {
      toolLevel = Integer.MAX_VALUE;
    } else if (getUpgrades().contains(WorksiteUpgrade.TOOL_QUALITY_2)) {
      toolLevel = 3;
    } else if (getUpgrades().contains(WorksiteUpgrade.TOOL_QUALITY_1)) {
      toolLevel = 2;
    }
    if (toolLevel < harvestLevel) {
      return false;
    }//else is harvestable, check the rest of the checks
  }
  return state.getBlockHardness(world, harvestPos) >= 0;
}

代码示例来源:origin: TerraFirmaCraft/TerraFirmaCraft

public BlockStairsTFC(Tree wood)
  {
    super(BlockPlanksTFC.get(wood).getDefaultState());
    if (WOOD_MAP.put(wood, this) != null) throw new IllegalStateException("There can only be one.");
    Block c = BlockPlanksTFC.get(wood);
    setHarvestLevel(c.getHarvestTool(c.getDefaultState()), c.getHarvestLevel(c.getDefaultState()));
    OreDictionaryHelper.register(this, "stair");
    OreDictionaryHelper.register(this, "stair", "wood");
    OreDictionaryHelper.register(this, "stair", "wood", wood);
    Blocks.FIRE.setFireInfo(this, 5, 20);
  }
}

代码示例来源:origin: TerraFirmaCraft/TerraFirmaCraft

private BlockSlabTFC(Rock rock, Rock.Type type)
{
  this(BlockRockVariant.get(rock, type));
  Block c = BlockRockVariant.get(rock, type);
  //noinspection ConstantConditions
  setHarvestLevel(c.getHarvestTool(c.getDefaultState()), c.getHarvestLevel(c.getDefaultState()));
}

代码示例来源:origin: TerraFirmaCraft/TerraFirmaCraft

private BlockSlabTFC(Tree wood)
{
  this(BlockPlanksTFC.get(wood));
  Block c = BlockPlanksTFC.get(wood);
  //noinspection ConstantConditions
  setHarvestLevel(c.getHarvestTool(c.getDefaultState()), c.getHarvestLevel(c.getDefaultState()));
  Blocks.FIRE.setFireInfo(this, 5, 20);
}

代码示例来源:origin: Vazkii/Psi

public static boolean canHarvestBlock(Block block, EntityPlayer player, World world, BlockPos pos, ItemStack tool) {
    IBlockState state = world.getBlockState(pos).getActualState(world, pos);
    if (state.getMaterial().isToolNotRequired())
      return true;

    String toolType = block.getHarvestTool(state);
    if (tool.isEmpty() || toolType == null)
      return player.canHarvestBlock(state);

    int toolLevel = tool.getItem().getHarvestLevel(tool, toolType, player, state);
    if (toolLevel < 0)
      return player.canHarvestBlock(state);

    return toolLevel >= block.getHarvestLevel(state);
}
}

代码示例来源:origin: PenguinSquad/Harvest-Festival

public boolean onSmashed(EntityPlayer player, ItemStack stack, ToolTier tier, int harvestLevel, World world, BlockPos pos, IBlockState state) {
  if (canUse(stack)) {
    if (state.getBlock() instanceof ISmashable) {
      int requiredLevel = state.getBlock().getHarvestLevel(state);
      if (harvestLevel >= requiredLevel) {
        ISmashable smashable = ((ISmashable) state.getBlock());
        if (smashable.getToolType() == getToolType()) {
          if (smashable.smashBlock(player, world, pos, state, tier)) {
            ToolHelper.performTask(player, stack, this);
            if (!world.isRemote) {
              onBlockDestroyed(stack, world, state, pos, player);
            }
            return true;
          }
        }
      }
    }
  }
  return false;
}

代码示例来源:origin: JurassiCraftTeam/JurassiCraft2

public AncientSlabBlock(TreeType type, IBlockState referenceState) {
  super(referenceState.getBlock().getMaterial(referenceState));
  this.type = type;
  IBlockState state = this.blockState.getBaseState();
  if (!this.isDouble()) {
    state = state.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
  }
  Block block = state.getBlock();
  this.setHardness(block.getBlockHardness(state, null, null));
  this.setResistance((block.getExplosionResistance(null) * 5.0F) / 3.0F);
  this.setSoundType(SoundType.WOOD);
  this.setHarvestLevel(block.getHarvestTool(state), block.getHarvestLevel(state));
  this.setUnlocalizedName(type.name().toLowerCase(Locale.ENGLISH) + "_slab");
  this.setDefaultState(state);
}

相关文章

Block类方法