コード例 #1
0
  private static boolean trySpawnEntity(ItemStack stack, WorldServer world, EntityPlayerMP player) {
    int damage = stack.getItemDamage();
    if (damage >= stack.getMaxDamage()) return false;

    NBTTagCompound tag = ItemUtils.getItemTag(stack);
    String structureName = tag.getString(TAG_STRUCTURE);

    if (Strings.isNullOrEmpty(structureName)) return false;

    Map<String, ChunkPosition> nearbyStructures =
        StructureRegistry.instance.getNearestStructures(
            world, (int) player.posX, (int) player.posY, (int) player.posZ);

    ChunkPosition structurePos = nearbyStructures.get(structureName);
    if (structurePos != null) {
      if (Config.eyeDebug)
        player.addChatComponentMessage(
            new ChatComponentTranslation(
                "openblocks.misc.structure_pos",
                structureName,
                structurePos.chunkPosX,
                structurePos.chunkPosY,
                structurePos.chunkPosZ));

      stack.setItemDamage(damage + 1);
      EntityGoldenEye eye = new EntityGoldenEye(world, stack, player, structurePos);
      world.spawnEntityInWorld(eye);
      world.playSoundAtEntity(
          player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
      return true;
    }
    return false;
  }