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

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

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

Block.isToolEffective介绍

暂无

代码示例

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

/**
 * Returns true if the tool is effective for harvesting the given block.
 */
public static boolean isToolEffective(ItemStack stack, IBlockState state) {
 // check material
 for(String type : stack.getItem().getToolClasses(stack)) {
  if(state.getBlock().isToolEffective(type, state)) {
   return true;
  }
 }
 return false;
}

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

@Override
public boolean isToolEffective(
    final String type,
    final IBlockState state )
{
  return Blocks.STONE.isToolEffective( type, Blocks.STONE.getDefaultState() );
}

代码示例来源:origin: vadis365/TheErebus

public boolean isToolEffective(IBlockState state) {
    return state.getBlock().isToolEffective("pickaxe", state) || state.getBlock().isToolEffective("axe", state) || state.getBlock().isToolEffective("shovel", state);
  }
}

代码示例来源:origin: SleepyTrousers/EnderIO

public static boolean isToolEffective(@Nonnull IBlockState state, @Nonnull ItemStack stack) {
 for (String type : stack.getItem().getToolClasses(stack)) {
  if (state.getBlock().isToolEffective(NullHelper.notnull(type, "getToolClasses() derped"), state)) {
   return true;
  }
 }
 return false;
}

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

public boolean canLevel(ItemStack stack, IBlockState state) {
  for (String type : getToolClasses(stack)) {
    if (state.getBlock().isToolEffective(type, state))
      return true;
  }
  return effectiveBlocks.contains(state.getBlock());
}

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

@Override
public boolean canLevel(ItemStack stack, IBlockState state) {
  for (String type : getToolClasses(stack)) {
    if (state.getBlock().isToolEffective(type, state))
      return true;
  }
  return state.getBlock() instanceof IPlantable;
}

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

@Override
public float getStrVsBlock(ItemStack stack, IBlockState state) {
  for (String type : getToolClasses(stack)) {
    if (state.getBlock().isToolEffective(type, state))
      return getEffiency(stack);
  }
  return this.effectiveBlocks.contains(state.getBlock()) ? getEffiency(stack) : 1.0F;
}

代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation

@Override
public boolean onBlockBreakWithTool(BlockEvent.BreakEvent event, @Nonnull ItemStack toolStack, @Nonnull ItemStack thisUpgradeStack) {
  IBlockState state = event.getState();
  Block block = state.getBlock();
  if (block.isToolEffective(((SteamTool) toolStack.getItem()).toolClass(), state)) {
    fellBlocks(event.getWorld(), event.getPos(), event.getPlayer(), toolStack);
  }
  return true;
}

代码示例来源:origin: SleepyTrousers/EnderIO

public static boolean isToolEffective(IBlockState state, ItemStack stack) {
 if (stack.isEmpty()) { // don't spawn them with an empty hand, helps newly spawned players
  return !ZooConfig.direSlimeEnabledHand.get();
 }
 if (!ZooConfig.direSlimeEnabled.get()) {
  return true;
 }
 for (String type : stack.getItem().getToolClasses(stack)) {
  if (type != null) {
   if (state.getBlock().isToolEffective(type, state) || "shovel".equals(type)) {
    // the "shovel" check is needed for modded blocks that extend dirt/grass but refuse to acknowledge any tool as effective, e.g. TiC
    return true;
   }
  }
 }
 return false;
}

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

@Override
public float getDestroySpeed(ItemStack stack, IBlockState state)
{
  Material material = state.getMaterial();
  switch (type)
  {
    case AXE:
      if (material == Material.WOOD || material == Material.PLANTS || material == Material.VINE)
        return efficiency;
      break;
    case PICK:
      if (material == Material.IRON || material == Material.ANVIL || material == Material.ROCK)
        return efficiency;
      break;
    case SHOVEL:
      if (material == Material.SNOW || material == Material.CRAFTED_SNOW) return efficiency;
    case SCYTHE:
      if (material == Material.PLANTS || material == Material.VINE || material == Material.LEAVES)
        return efficiency;
  }
  for (String type : getToolClasses(stack))
  {
    if (state.getBlock().isToolEffective(type, state)) return efficiency;
  }
  return super.getDestroySpeed(stack, state);
}

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

@Override
public float getDestroySpeed(ItemStack itemstack, IBlockState state) {
  for (String type : getToolClasses(itemstack)) {
    if (state.getBlock().isToolEffective(type, state)) {
      return efficiencyOnProperMaterial;
    }
  }
  if (this == ModuleCore.getItems().bronzePickaxe) {
    Material material = state.getMaterial();
    return material != Material.IRON && material != Material.ANVIL && material != Material.ROCK ? super.getDestroySpeed(itemstack, state) : this.efficiencyOnProperMaterial;
  }
  return super.getDestroySpeed(itemstack, state);
}

代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation

@Override
public boolean onBlockBreakWithTool(BlockEvent.BreakEvent event, @Nonnull ItemStack toolStack, @Nonnull ItemStack thisUpgradeStack) {
  EntityPlayer player = event.getPlayer();
  BlockPos pos = event.getPos();
  World world = event.getWorld();
  IBlockState state = event.getState();
  Block block = state.getBlock();
  Item toolItem = toolStack.getItem();
  RayTraceResult ray = ((SteamTool) toolItem).rayTrace(world, player, false);
  if (ray != null && block.isToolEffective(((SteamTool) toolItem).toolClass(), state)) {
    mineExtraBlocks(getExtraBlockCoordinates(ray.sideHit), pos, world, (ItemTool) toolItem, toolStack, player);
  }
  return true;
}

代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation

@Override
public boolean onBlockBreakWithTool(BlockEvent.BreakEvent event, @Nonnull ItemStack toolStack, @Nonnull ItemStack thisUpgradeStack) {
  EntityPlayer player = event.getPlayer();
  World world = event.getWorld();
  IBlockState state = event.getState();
  Block block = state.getBlock();
  SteamTool tool = (SteamTool) toolStack.getItem();
  RayTraceResult ray = tool.rayTrace(world, player, false);
  if (ray != null && block.isToolEffective(((SteamTool) toolStack.getItem()).toolClass(), state)) {
    WorldHelper.mineExtraBlocks(WorldHelper.getExtraBlockCoordinates(ray.sideHit), event.getPos(), world, (ItemTool) tool, toolStack, player);
  }
  return true;
}

代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation

@Override
  public void onPlayerHarvestDropsWithTool(BlockEvent.HarvestDropsEvent event, @Nonnull ItemStack toolStack, @Nonnull ItemStack thisUpgradeStack) {
    IBlockState state = event.getState();
    Block block = state.getBlock();
    SteamTool tool = (SteamTool) toolStack.getItem();
    if (event.getDrops().isEmpty() || !block.isToolEffective(tool.toolClass(), state)) {
      return;
    }
    int itemsSmelted = 0;
    for (int i = 0; i < event.getDrops().size(); i++) {
      ItemStack drop = event.getDrops().get(i);
      if (drop == null || drop.getItem() == null) {
        continue;
      }

      ItemStack output = SteamingRegistry.getSteamingResult(drop);
      if (output == null || output.getItem() == null) {
        continue;
      }
      event.getDrops().remove(i);
      event.getDrops().add(i, output.copy());
      itemsSmelted += 1;
    }
    if (itemsSmelted > 0) {
      tool.addSteam(toolStack, -(itemsSmelted * tool.steamPerDurability()), event.getHarvester());
    }
  }
}

代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation

IBlockState state1 = world.getBlockState(pos);
Block block1 = state1.getBlock();
if (!block1.isToolEffective(((SteamTool) toolStack.getItem()).toolClass(), state1) ||
 !block1.canHarvestBlock(world, pos, player)) {
  continue;

代码示例来源:origin: PrinceOfAmber/Cyclic

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onBreakEvent(BreakEvent event) {
 World world = event.getWorld();
 EntityPlayer player = event.getPlayer();
 if (player.swingingHand == null) {
  return;
 }
 BlockPos pos = event.getPos();
 Block block = event.getState().getBlock();
 //is this item stack enchanted with ME?
 ItemStack stackHarvestingWith = player.getHeldItem(player.swingingHand);
 int level = this.getCurrentLevelTool(stackHarvestingWith);
 if (level <= 0) {
  return;
 }
 // if I am using an axe on stone or dirt, doesn't trigger
 boolean isAnySingleOk = false;//if i am a tool valid on 2 things, and both of 2 blocks are present, we are just ok
 for (String type : stackHarvestingWith.getItem().getToolClasses(stackHarvestingWith)) {
  if (block.isToolEffective(type, world.getBlockState(pos))) {
   isAnySingleOk = true;
  }
 }
 //starts at 1 for current one
 if (isAnySingleOk) {
  this.harvestSurrounding(world, player, pos, block, 1, level);
 }
}

相关文章

Block类方法