net.minecraft.item.ItemStack.getMetadata()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(143)

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

ItemStack.getMetadata介绍

暂无

代码示例

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

private boolean isDust() {
  ItemStack stack = itemHandler.getStackInSlot(0);
  return !stack.isEmpty() && stack.getItem() == ModItems.manaResource && stack.getMetadata() == 23;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

private boolean fuzzyItemStackComparison( ItemStack a, ItemStack b, FuzzyMode mode )
{
  if( a.getItem() == b.getItem() )
  {
    if( a.getItem().isDamageable() )
    {
      if( mode == FuzzyMode.IGNORE_ALL )
      {
        return true;
      }
      else if( mode == FuzzyMode.PERCENT_99 )
      {
        return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
      }
      else
      {
        final float percentDamageOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
        final float percentDamageOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
        return ( percentDamageOfA > mode.breakPoint ) == ( percentDamageOfB > mode.breakPoint );
      }
    }
    return a.getMetadata() == b.getMetadata();
  }
  return false;
}

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

private boolean placeBlock(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float xOffset, float yOffset, float zOffset) {
  IBlockState iblockstate = world.getBlockState(pos);
  Block block = iblockstate.getBlock();
  if(!block.isReplaceable(world, pos)) {
    pos = pos.offset(side);
  }
  if(itemstack.isEmpty()) {
    return false;
  } else if(!player.canPlayerEdit(pos, side, itemstack)) {
    return false;
  } else if(world.mayPlace(Blocks.MOB_SPAWNER, pos, false, side, null)) {
    int meta = this.getMetadata(itemstack.getMetadata());
    IBlockState iblockstate1 = Blocks.MOB_SPAWNER.getStateForPlacement(world, pos, side, xOffset, yOffset, zOffset, meta, player);
    if (placeBlockAt(itemstack, player, world, pos, side, xOffset, yOffset, zOffset, iblockstate1)) {
      world.playSound(null, pos, Blocks.MOB_SPAWNER.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (Blocks.MOB_SPAWNER.getSoundType().getVolume() + 1.0F) / 2.0F, Blocks.MOB_SPAWNER.getSoundType().getPitch() * 0.8F);
      player.renderBrokenItemStack(itemstack);
      itemstack.shrink(1);
      for(int i = 0; i < 100; i++)
        Botania.proxy.sparkleFX(pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 0.45F + 0.2F * (float) Math.random(), 6);
    }
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
  public IBakedModel handleItemState( IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity )
  {
    if( !( stack.getItem() instanceof ItemFacade ) )
    {
      return originalModel;
    }
    ItemFacade itemFacade = (ItemFacade) stack.getItem();
    ItemStack textureItem = itemFacade.getTextureItem( stack );
    int hash = Objects.hash( textureItem.getItem().getRegistryName(), textureItem.getMetadata(), textureItem.getTagCompound() );
    FacadeBakedItemModel model = FacadeDispatcherBakedModel.this.cache.get( hash );
    if( model == null )
    {
      model = new FacadeBakedItemModel(FacadeDispatcherBakedModel.this.getBaseModel(), textureItem, FacadeDispatcherBakedModel.this.facadeBuilder);
      FacadeDispatcherBakedModel.this.cache.put(hash, model);
    }
    return model;
  }
};

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

items.registerItemColorHandler((s, t) -> Minecraft.getMinecraft().getBlockColors().colorMultiplier(((ItemBlock)s.getItem()).getBlock().getStateFromMeta(s.getMetadata()), null, null, t),
    ModBlocks.petalBlock, ModBlocks.pool, ModBlocks.spreader);

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

@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  // Copy of ItemBlock.onItemUse
  IBlockState iblockstate = world.getBlockState(pos);
  Block block = iblockstate.getBlock();
  if (!block.isReplaceable(world, pos))
  {
    pos = pos.offset(facing);
  }
  ItemStack stack = player.getHeldItem(hand);
  if (!stack.isEmpty() && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(ModBlocks.buriedPetals, pos, false, facing, null))
  {
    int i = this.getMetadata(stack.getMetadata());
    IBlockState iblockstate1 = ModBlocks.buriedPetals.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player);
    if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1))
    {
      SoundType soundtype = ModBlocks.buriedPetals.getSoundType();
      world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
      stack.shrink(1);
    }
    return EnumActionResult.SUCCESS;
  }
  else
  {
    return EnumActionResult.FAIL;
  }
}

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

.renderSkull(-0.5F, 0.0F, -0.5F, EnumFacing.UP, 180.0F, itemstack.getMetadata(), null, -1, limbSwing);
ShaderHelper.releaseShader();

代码示例来源:origin: TheGreyGhost/MinecraftByExample

@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
{
 int metadata = stack.getMetadata();
 int contentsBits = metadata & 0x03;
 int fullnessBits = (metadata >> 2) & 0x07;
 if (fullnessBits != 0) --fullnessBits;  // decrease fullness (assumes same order of metadata as fullness!)
 int newMetadata = contentsBits | (fullnessBits << 2);
 stack.setItemDamage(newMetadata);
 return stack;
}

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

@Override
 public @Nonnull String getUnlocalizedName(@Nonnull ItemStack stack) {
  return super.getUnlocalizedName(stack) + "_" + stack.getMetadata();
 }
});

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

@Override
public @Nonnull String getUnlocalizedName(@Nonnull ItemStack stack) {
 if (block instanceof INamedSubBlocks) {
  return ((INamedSubBlocks) block).getUnlocalizedName(stack.getMetadata());
 } else {
  return super.getUnlocalizedName(stack);
 }
}

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

@SuppressWarnings("deprecation")
@Override
@SideOnly(Side.CLIENT)
public List<Pair<IBlockState, ItemStack>> mapItemRender(@Nonnull Block block, @Nonnull ItemStack stack, @Nonnull ItemQuadCollector itemQuadCollector) {
 return Collections
   .singletonList(Pair.of(block.getStateFromMeta(stack.getMetadata()).withProperty(EnumRenderMode.RENDER, SINGLE_MODEL_INVENTORY), (ItemStack) null));
}

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

@SuppressWarnings("deprecation")
@Override
@SideOnly(Side.CLIENT)
public List<Pair<IBlockState, ItemStack>> mapItemRender(@Nonnull Block block, @Nonnull ItemStack stack, @Nonnull ItemQuadCollector itemQuadCollector) {
 return Collections
   .singletonList(Pair.of(block.getStateFromMeta(stack.getMetadata()).withProperty(EnumRenderMode.RENDER, SINGLE_MODEL_INVENTORY), (ItemStack) null));
}

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

@Override
@SideOnly(Side.CLIENT)
public List<Pair<IBlockState, ItemStack>> mapItemRender(Block block, ItemStack stack, ItemQuadCollector itemQuadCollector) {
 return Collections.singletonList(Pair.of(block.getStateFromMeta(stack.getMetadata()).withProperty(EnumRenderMode6.RENDER, EnumRenderMode6.FRONT_ON_NORTH),
   stack));
}

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

@Override
@SideOnly(Side.CLIENT)
public List<Pair<IBlockState, ItemStack>> mapItemRender(@Nonnull Block block, @Nonnull ItemStack stack, @Nonnull ItemQuadCollector itemQuadCollector) {
 List<Pair<IBlockState, ItemStack>> states = new ArrayList<Pair<IBlockState, ItemStack>>();
 states.add(Pair.of(block.getStateFromMeta(stack.getMetadata()).withProperty(EnumRenderMode.RENDER, EnumRenderMode.FRONT), stack));
 if (!stack.hasTagCompound()) {
  // glass needs to be rendered on top of fluid
  states.add(Pair.of(block.getStateFromMeta(stack.getMetadata()).withProperty(EnumRenderMode.RENDER, EnumRenderMode.FRONT_ON), stack));
 }
 itemQuadCollector.addQuads(null, renderHead(null));
 return states;
}

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

TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;
if (itemstack.getMetadata() == 3) // Botania - do not retrieve skins

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

@Override
public void setEnergyStored(@Nonnull ItemStack container, int energy) {
 if (CapBankType.getTypeFromMeta(container.getMetadata()).isCreative()) {
  energy = CapBankType.getTypeFromMeta(container.getMetadata()).getMaxEnergyStored() / 2;
 }
 IInternalPoweredItem.super.setEnergyStored(container, energy);
}

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

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@SideOnly(Side.CLIENT)
public void addDetailedEntries(@Nonnull ItemStack itemstack, @Nullable EntityPlayer entityplayer, @Nonnull List list, boolean flag) {
 SpecialTooltipHandler.addDetailedTooltipFromResources(list, itemstack);
 if (EnumFacadeType.getTypeFromMeta(itemstack.getMetadata()) != EnumFacadeType.BASIC) {
  list.add("");
  SpecialTooltipHandler.addDetailedTooltipFromResources(list, getUnlocalizedName(itemstack));
 }
}

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

@Override
public IBlockState getPaintSource(@Nonnull Block block, @Nonnull ItemStack stack) {
 IBlockState paintSource = PaintUtil.getSourceBlock(stack);
 return paintSource != null ? paintSource : defaultPaints.get(EnumPressurePlateType.getTypeFromMeta(stack.getMetadata()).ordinal());
}

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

@Override
public void onBlockPlacedBy(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull EntityLivingBase placer,
  @Nonnull ItemStack stack) {
 setTypeFromMeta(worldIn, pos, stack.getMetadata());
 setPaintSource(state, worldIn, pos, PaintUtil.getSourceBlock(stack));
 setRotation(worldIn, pos, EnumFacing.fromAngle(placer.rotationYaw));
 setMobType(worldIn, pos, CapturedMob.create(stack));
 if (!worldIn.isRemote) {
  worldIn.notifyBlockUpdate(pos, state, state, 3);
 }
}

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

protected boolean plant(@Nonnull IFarmer farm, @Nonnull World world, @Nonnull BlockPos bc, @Nonnull ItemStack sapling) {
 if (canPlant(world, bc, sapling) && farm.checkAction(FarmingAction.PLANT, FarmingTool.HOE)) {
  world.setBlockToAir(bc);
  final Item item = sapling.getItem();
  final IBlockState state = Block.getBlockFromItem(item).getStateFromMeta(item.getMetadata(sapling.getMetadata()));
  world.setBlockState(bc, state, 1 | 2);
  farm.registerAction(FarmingAction.PLANT, FarmingTool.HOE, state, bc);
  return true;
 } else {
  return false;
 }
}

相关文章

微信公众号

最新文章

更多

ItemStack类方法