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

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

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

Block.getStateForPlacement介绍

暂无

代码示例

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

public void tryPlacingVine(Random random, World world, BlockPos below, int limit, IBlockState vine) {
 BlockPos pos = below;
 BlockPos candidate = null;
 // check straight up first
 for(int i = 0; i < limit; i++) {
  // check around for a possible block
  if(vine.getBlock().canPlaceBlockOnSide(world, pos, EnumFacing.NORTH)
    || vine.getBlock().canPlaceBlockOnSide(world, pos, EnumFacing.EAST)
    || vine.getBlock().canPlaceBlockOnSide(world, pos, EnumFacing.SOUTH)
    || vine.getBlock().canPlaceBlockOnSide(world, pos, EnumFacing.WEST)) {
   if(candidate == null || random.nextInt(10) == 0) {
    candidate = pos;
   }
  }
  pos = pos.up();
 }
 if(candidate != null) {
  // place the vine
  world.setBlockState(candidate, vine.getBlock().getStateForPlacement(world, candidate, EnumFacing.UP, 0, 0, 0, 0, null, null), 2);
  // and let it grow, let it grow, let it groooooow!
  pos = candidate;
  for(int size = random.nextInt(8); size >= 0; size++) {
   if(!(world.getBlockState(pos).getBlock() instanceof BlockSlimeVine)) {
    break;
   }
   ((BlockSlimeVine) world.getBlockState(pos).getBlock()).grow(world, random, pos, world.getBlockState(pos));
   pos = pos.down();
  }
 }
}

代码示例来源: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: Vazkii/Botania

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
  TileEntity tile = world.getTileEntity(pos);
  if(world.isRemote)
    return true;
  ItemStack currentStack = player.getHeldItem(hand);
  if(!currentStack.isEmpty()
      && Block.getBlockFromItem(currentStack.getItem()) != null
      && tile instanceof TileCamo) {
    TileCamo camo = (TileCamo) tile;
    IBlockState changeState = Block.getBlockFromItem(currentStack.getItem()).getStateForPlacement(world, pos, side, hitX, hitY, hitZ, currentStack.getItemDamage(), player);
    if(isValidBlock(changeState) && !(changeState.getBlock() instanceof BlockCamo) && changeState.getMaterial() != Material.AIR) {
      camo.camoState = changeState;
      world.notifyBlockUpdate(pos, state, state, 8);
      return true;
    }
  }
  return false;
}

代码示例来源: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: MrCrayfish/MrCrayfishFurnitureMod

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand)
{
  return super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand).withProperty(COLOUR, Math.min(meta, 15));
}

代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
  IBlockState state = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer);
  return state.withProperty(FACING, facing);
}

代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand)
{
  return super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand).withProperty(COLOUR, Math.min(meta, 15));
}

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

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  return super.getStateForPlacement(world, pos, side, hitX, hitY, hitZ, meta, placer).withProperty(FACING, side);
}

代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
  IBlockState state = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer);
  return state.withProperty(FACING, placer.getHorizontalFacing());
}

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

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  return super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer)
    .withProperty(IS_BURST, meta == 1)
    .withProperty(FACING, facing);
}

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

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ,
    EntityLivingBase placer, EnumHand hand) {
  return state.getBlock().getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, state.getBlock().getMetaFromState(state), placer,
      hand);
}

代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
  if (hasRotation)
    return getDefaultState().withProperty(PROPERTY_DIRECTION, placer.getHorizontalFacing().getOpposite());
  return super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand);
}

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

public static void renderBlockPhantom(World world, final BlockPos pos, ItemStack stack, final double relX, final double relY, final double relZ,
  BlockPos target, boolean isSolid) {
 if (stack.getItem() instanceof ItemBlock) {
  ItemBlock ib = (ItemBlock) stack.getItem();
  IBlockState stateFromStack = ib.getBlock().getStateForPlacement(world, pos, EnumFacing.DOWN, pos.getX(), pos.getY(), pos.getZ(),
    stack.getItemDamage(), null, EnumHand.MAIN_HAND);
  renderBlockPhantom(world, pos, stateFromStack, relX, relY, relZ, target, isSolid);
 }
}

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

public boolean isBlacklisted(World world, EntityPlayer player, ItemStack stack) {
  if (stack.getItem() instanceof ItemBlock) {
    Block block = ((ItemBlock)stack.getItem()).getBlock();
    if (block.hasTileEntity(block.getStateForPlacement(world, BlockPos.ORIGIN, EnumFacing.DOWN, 0F, 0F, 0F, stack.getItemDamage(), player, stack))) return true;
  }
  return registry.getValueOf(stack) == null && (stack.getItem().isDamageable() || blacklist.contains(stack));
}

代码示例来源:origin: Direwolf20-MC/BuildingGadgets

public static IBlockState getSpecificStates(IBlockState originalState, World world, EntityPlayer player, BlockPos pos, ItemStack tool) {
  IBlockState placeState = Blocks.AIR.getDefaultState();
  Block block = originalState.getBlock();
  ItemStack item = block.getPickBlock(originalState, null, world, pos, player);
  int meta = item.getMetadata();
  try {
    placeState = originalState.getBlock().getStateForPlacement(world, pos, EnumFacing.UP, 0, 0, 0, meta, player, EnumHand.MAIN_HAND);
  } catch (Exception var8) {
    placeState = originalState.getBlock().getDefaultState();
  }
  for (IProperty prop : placeState.getPropertyKeys()) {
    if (tool.getItem() instanceof GadgetCopyPaste) {
      if (SAFE_PROPERTIES_COPY_PASTE.contains(prop)) {
        placeState = placeState.withProperty(prop, originalState.getValue(prop));
      }
    } else {
      if (SAFE_PROPERTIES.contains(prop)) {
        placeState = placeState.withProperty(prop, originalState.getValue(prop));
      }
    }
  }
  return placeState;
}

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

@Override
  public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();

    if(!block.isReplaceable(worldIn, pos))
      pos = pos.offset(facing);

    ItemStack itemstack = player.getHeldItem(hand);

    if(!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(this.block, pos, false, facing, null)) {
      int i = this.getMetadata(itemstack.getMetadata());
      IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);

      if(placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1)) {
        iblockstate1 = worldIn.getBlockState(pos);
        SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, player);
//                worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
        itemstack.shrink(1);
      }

      return EnumActionResult.SUCCESS;
    }
    else return EnumActionResult.FAIL;
  }

代码示例来源:origin: OpenMods/OpenModsLib

final IBlockState newBlockState = this.block.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, itemMetadata, player, hand);

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

private EnumActionResult placeBlock(ItemStack itemstack, EntityPlayer player, BlockPos pos, EnumFacing facing, World worldIn, EnumHand hand, float hitX, float hitY, float hitZ) {
  IBlockState stateAt = worldIn.getBlockState(pos);
  if(!stateAt.getBlock().isReplaceable(worldIn, pos))
    pos = pos.offset(facing);
  
  if(itemstack.getItem() instanceof ItemBlock) {
    ItemBlock item = (ItemBlock) itemstack.getItem();
    Block block = item.getBlock();
    if(player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(block, pos, false, facing, null)) {
      int i = item.getMetadata(itemstack.getMetadata());
      IBlockState state = block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);
      
      if(item.placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, state)) {
        state = worldIn.getBlockState(pos);
        SoundType soundtype = state.getBlock().getSoundType(state, worldIn, pos, player);
        worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
        if(!player.capabilities.isCreativeMode)
          shrinkInventory(itemstack, player);
      }
      return EnumActionResult.SUCCESS;
    }
  }
  return EnumActionResult.FAIL;
}

代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod

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

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

public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  IBlockState state = worldIn.getBlockState(pos);
  Block block = state.getBlock();
  ItemStack itemstack = player.getHeldItem(hand);
  if (!itemstack.isEmpty() && facing == EnumFacing.UP && player.canPlayerEdit(pos, facing, itemstack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up())) {
    pos = pos.up();
    IBlockState blockState = crops.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);
    if (!worldIn.setBlockState(pos, blockState, 11)) {
      return EnumActionResult.FAIL;
    } else {
      blockState = worldIn.getBlockState(pos);
      if (blockState.getBlock() == crops) {
        blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
      }
      SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
      worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
      itemstack.shrink(1);
      return EnumActionResult.SUCCESS;
    }
  } else {
    return EnumActionResult.FAIL;
  }
}

相关文章

Block类方法