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

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

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

Block.getStateId介绍

暂无

代码示例

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

@Override
public boolean addLandingEffects(IBlockState state, net.minecraft.world.WorldServer world, BlockPos blockPosition, IBlockState iblockstate, EntityLivingBase entity, int numberOfParticles )
{
  float f = MathHelper.ceil(entity.fallDistance - 3.0F);
  double d0 = Math.min(0.2F + f / 15.0F, 10.0F);
  if (d0 > 2.5D) {
    d0 = 2.5D;
  }
  int i = (int)(150.0D * d0);
  world.spawnParticle(EnumParticleTypes.BLOCK_DUST, entity.posX, entity.posY, entity.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, Block.getStateId(ModBlocks.storage.getDefaultState().withProperty(BotaniaStateProps.STORAGE_VARIANT, StorageVariant.ELEMENTIUM)));
  return true;
}

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

@Override
protected void onImpact(@Nonnull RayTraceResult pos) {
  if(pos.getBlockPos() != null && !world.isRemote) {
    List<BlockPos> coordsList = getCoordsToPut(pos.getBlockPos());
    world.playEvent(2002, new BlockPos(this), 8);
    for(BlockPos coords : coordsList) {
      world.setBlockState(coords, Blocks.END_STONE.getDefaultState());
      if(Math.random() < 0.1)
        world.playEvent(2001, coords, Block.getStateId(Blocks.END_STONE.getDefaultState()));
    }
    setDead();
  }
}

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

@Override
public boolean doParticles(IManaBurst burst, ItemStack stack) {
  EntityThrowable entity = (EntityThrowable) burst;
  ItemStack lens = burst.getSourceLens();
  String id = ItemNBTHelper.getString(lens, TAG_BLOCK_NAME, "minecraft:air");
  Block b = Block.getBlockFromName(id);
  int meta = ItemNBTHelper.getInt(lens, TAG_META, 0);
  entity.world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, entity.posX, entity.posY, entity.posZ, entity.motionX, entity.motionY, entity.motionZ, Block.getStateId(b.getStateFromMeta(meta)));
  return true;
}

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

world.setBlockToAir(currCoords);
if(ConfigHandler.blockBreakParticles)
  world.playEvent(2001, currCoords, Block.getStateId(state));

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

@Override
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumFacing side) {
  if(player == null || world.isRemote)
    return false;
  if(!player.isSneaking()) {
    playerPositions.put(player.getUniqueID(), new DimWithPos(world.provider.getDimension(), pos));
    world.playSound(null, pos, ModSounds.ding, SoundCategory.BLOCKS, 0.5F, 1F);
  } else {
    spawnAsEntity(world, pos, new ItemStack(this));
    world.setBlockToAir(pos);
    world.playEvent(2001, pos, Block.getStateId(getDefaultState()));
  }
  return true;
}

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

@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xs, float ys, float zs) {
  IBlockState state = world.getBlockState(pos);
  if(Item.getItemFromBlock(state.getBlock()) == Items.AIR)
    return EnumActionResult.PASS;
  ItemStack blockStack = new ItemStack(state.getBlock());
  int[] ids = OreDictionary.getOreIDs(blockStack);
  for(int i : ids) {
    String name = OreDictionary.getOreName(i);
    if(name.equals("grass")) {
      world.playEvent(2001, pos, Block.getStateId(state));
      world.setBlockState(pos, ModBlocks.enchantedSoil.getDefaultState());
      player.getHeldItem(hand).shrink(1);
      return EnumActionResult.SUCCESS;
    }
  }
  return EnumActionResult.PASS;
}

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

@Override
protected void onImpact(RayTraceResult pos) {
  if (world.isRemote)
    return;
  EntityLivingBase thrower = getThrower();
  if(pos.entityHit != null && thrower != null && pos.entityHit != thrower && !pos.entityHit.isDead) {
    if(thrower instanceof EntityPlayer)
      pos.entityHit.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) thrower), Math.random() < 0.25 ? 10 : 5);
    else pos.entityHit.attackEntityFrom(DamageSource.GENERIC, Math.random() < 0.25 ? 10 : 5);
  }
  if (pos.getBlockPos() != null) {
    IBlockState state = world.getBlockState(pos.getBlockPos());
    if(ConfigHandler.blockBreakParticles && !state.getBlock().isAir(state, world, pos.getBlockPos()))
      world.playEvent(2001, pos.getBlockPos(), Block.getStateId(state));
  }
  setDead();
}

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

@Override
public void onBurstCollision(IManaBurst burst, World world, BlockPos pos) {
  if(!burst.isFake() && !world.isRemote) {
    world.playEvent(2001, pos, Block.getStateId(getDefaultState()));
    world.setBlockToAir(pos);
    EntityManaStorm storm = new EntityManaStorm(world);
    storm.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
    world.spawnEntity(storm);
  }
}

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

@Override
protected void onImpact(@Nonnull RayTraceResult var1) {
  if(!world.isRemote) {
    if(var1 != null) {
      EnumFacing dir = var1.sideHit;
      if(dir != null && dir.getAxis() != EnumFacing.Axis.Y) {
        BlockPos pos = var1.getBlockPos().offset(dir);
        while(pos.getY() > 0) {
          IBlockState state = world.getBlockState(pos);
          Block block = state.getBlock();
          if(block.isAir(state, world, pos)) {
            IBlockState stateSet = ModBlocks.solidVines.getDefaultState().withProperty(propMap.get(dir.getOpposite()), true);
            world.setBlockState(pos, stateSet, 1 | 2);
            world.playEvent(2001, pos, Block.getStateId(stateSet));
            pos = pos.down();
          } else break;
        }
      }
    }
    this.world.setEntityState(this, (byte)3);
    setDead();
  }
}

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

@Override
public void onAvatarUpdate(IAvatarTile tile, ItemStack stack) {
  TileEntity te = (TileEntity) tile;
  World world = te.getWorld();
  if(!world.isRemote && tile.getCurrentMana() >= COST && tile.getElapsedFunctionalTicks() % 4 == 0 && world.rand.nextInt(8) == 0 && tile.isEnabled()) {
    BlockPos pos = ((TileEntity) tile).getPos().offset(tile.getAvatarFacing());
    IBlockState state = world.getBlockState(pos);
    if(state.getBlock().isAir(state, world, pos)) {
      world.setBlockState(pos, Blocks.DIRT.getDefaultState());
      world.playEvent(2001, pos, Block.getStateId(Blocks.DIRT.getDefaultState()));
      tile.recieveMana(-COST);
    }
  }
}

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

@Override
public void onUpdate() {
  super.onUpdate();
  if(supertile.getWorld().isRemote || redstoneSignal > 0)
    return;
  if(mana >= COST && ticksExisted % 2 == 0) {
    BlockPos coords = getCoordsToPut();
    if(coords != null) {
      IBlockState state = getStoneToPut(coords);
      if(state != null) {
        supertile.getWorld().setBlockState(coords, state);
        if(ConfigHandler.blockBreakParticles)
          supertile.getWorld().playEvent(2001, coords, Block.getStateId(state));
        mana -= COST;
        sync();
      }
    }
  }
}

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

world.addBlockEvent(getPos(), supertile.getBlockType(), RECIPE_COMPLETE_EVENT, positionAt);
if(ConfigHandler.blockBreakParticles)
  supertile.getWorld().playEvent(2001, coords, Block.getStateId(recipe.getOutputState()));

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

IBlockState state = block.getStateFromMeta(meta);
player.world.setBlockState(coords, state, 1 | 2);
player.world.playEvent(2001, coords, Block.getStateId(state));

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

public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, BlockPos pos,
                    Predicate<IBlockState> filter,
                    boolean dispose, boolean particles) {
  if(!world.isBlockLoaded(pos))
    return;
  IBlockState state = world.getBlockState(pos);
  Block block = state.getBlock();
  if(!world.isRemote && filter.test(state)
      && !block.isAir(state, world, pos) && state.getPlayerRelativeBlockHardness(player, world, pos) > 0
      && block.canHarvestBlock(player.world, pos, player)) {
    int exp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos);
    if(exp == -1)
      return;
    if(!player.capabilities.isCreativeMode) {
      TileEntity tile = world.getTileEntity(pos);
      if(block.removedByPlayer(state, world, pos, player, true)) {
        block.onPlayerDestroy(world, pos, state);
        if(!dispose || !ItemElementiumPick.isDisposable(block)) {
          block.harvestBlock(world, player, pos, state, tile, stack);
          block.dropXpOnBlockBreak(world, pos, exp);
        }
      }
      damageItem(stack, 1, player, 80);
    } else world.setBlockToAir(pos);
    if(particles && ConfigHandler.blockBreakParticles && ConfigHandler.blockBreakParticlesTool)
      world.playEvent(2001, pos, Block.getStateId(state));
  }
}

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

supertile.getWorld().playEvent(2001, supertile.getPos(), Block.getStateId(state));
if(supertile.getWorld().getBlockState(supertile.getPos().down()).isSideSolid(supertile.getWorld(), supertile.getPos().down(), EnumFacing.UP))
  supertile.getWorld().setBlockState(supertile.getPos(), Blocks.DEADBUSH.getDefaultState());

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

@Override
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, BlockPos pos, net.minecraft.client.particle.ParticleManager effectRenderer)
{
  if (world.getBlockState(pos).getBlock() == this) {
    int i = 4;
    ParticleDigging.Factory factory = new ParticleDigging.Factory();
    for (int j = 0; j < i; ++j) {
      for (int k = 0; k < i; ++k) {
        for (int l = 0; l < i; ++l) {
          double d0 = pos.getX() + (j + 0.5D) / i;
          double d1 = pos.getY() + (k + 0.5D) / i;
          double d2 = pos.getZ() + (l + 0.5D) / i;
          effectRenderer.addEffect(factory.createParticle(-1, world, d0, d1, d2, d0 - pos.getX() - 0.5D, d1 - pos.getY() - 0.5D, d2 - pos.getZ() - 0.5D, Block.getStateId(ModBlocks.storage.getDefaultState().withProperty(BotaniaStateProps.STORAGE_VARIANT, StorageVariant.ELEMENTIUM))));
        }
      }
    }
    return true;
  } else {
    return false;
  }
}

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

@Override
public void onUpdate() {
  super.onUpdate();
  if(supertile.getWorld().isRemote || redstoneSignal > 0)
    return;
  if(ticksExisted % 30 == 0 && mana >= COST) {
    BlockPos pos = new BlockPos(
        supertile.getPos().getX() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1),
        supertile.getPos().getY() + RANGE,
        supertile.getPos().getZ() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1)
        );
    BlockPos up = pos.up();
    for(int i = 0; i < RANGE * 2; i++) {
      IBlockState stateAbove = supertile.getWorld().getBlockState(up);
      Block blockAbove = stateAbove.getBlock();
      if((supertile.getWorld().isAirBlock(up) || blockAbove.isReplaceable(supertile.getWorld(), up)) && stateAbove.getMaterial() != Material.WATER && ModBlocks.flower.canPlaceBlockAt(supertile.getWorld(), up)) {
        EnumDyeColor color = EnumDyeColor.byMetadata(supertile.getWorld().rand.nextInt(16));
        IBlockState state = ModBlocks.flower.getDefaultState().withProperty(BotaniaStateProps.COLOR, color);
        if(ConfigHandler.blockBreakParticles)
          supertile.getWorld().playEvent(2001, up, Block.getStateId(state));
        supertile.getWorld().setBlockState(up, state, 1 | 2);
        mana -= COST;
        sync();
        break;
      }
      up = pos;
      pos = pos.down();
    }
  }
}

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

@Override
public void onUpdate() {
  super.onUpdate();
  if(!supertile.getWorld().isRemote && ticksExisted % 5 == 0) {
    if(mana >= COST) {
      BlockPos coords = getCoordsToPut();
      if(coords != null) {
        supertile.getWorld().setBlockToAir(coords);
        if(ConfigHandler.blockBreakParticles)
          supertile.getWorld().playEvent(2001, coords, Block.getStateId(Blocks.SAND.getDefaultState()));
        EntityItem item = new EntityItem(supertile.getWorld(), coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, new ItemStack(Items.CLAY_BALL));
        supertile.getWorld().spawnEntity(item);
        mana -= COST;
      }
    }
  }
}

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

@Override
public void onUpdate() {
  super.onUpdate();
  if (supertile.getWorld().isRemote)
    return;
  int mana = 1800;
  if(getMaxMana() - this.mana >= mana && !supertile.getWorld().isRemote && ticksExisted % 80 == 0) {
    for(int i = 0; i < RANGE * 2 + 1; i++)
      for(int j = 0; j < RANGE * 2 + 1; j++)
        for(int k = 0; k < RANGE * 2 + 1; k++) {
          BlockPos pos = supertile.getPos().add(i - RANGE, j - RANGE, k - RANGE);
          IBlockState state = supertile.getWorld().getBlockState(pos);
          Block block = state.getBlock();
          if(block instanceof BlockCake) {
            int nextSlicesEaten = state.getValue(BlockCake.BITES) + 1;
            if(nextSlicesEaten > 6)
              supertile.getWorld().setBlockToAir(pos);
            else supertile.getWorld().setBlockState(pos, state.withProperty(BlockCake.BITES, nextSlicesEaten), 1 | 2);
            supertile.getWorld().playEvent(2001, pos, Block.getStateId(state));
            supertile.getWorld().playSound(null, supertile.getPos(), SoundEvents.ENTITY_GENERIC_EAT, SoundCategory.BLOCKS, 1F, 0.5F + (float) Math.random() * 0.5F);
            this.mana += mana;
            sync();
            return;
          }
        }
  }
}

相关文章

Block类方法